%PDF- %PDF-
Direktori : /var/www/pn/utils/classes/ |
Current File : /var/www/pn/utils/classes/Viewer.php |
<?php class Viewer { private $POSTS_PER_PAGE = 10; public $wpdb; public function __construct() { global $wpdb; $this->wpdb = $wpdb; } public function getUnApprovedProjects($page = 0) { $offsetQuery = ''; if($page > 0){ $offset = $page * $this->POSTS_PER_PAGE; $offsetQuery = ' OFFSET ' . $offset; } $sql = "SELECT * FROM " . PROJECT_TABLE_NAME . " WHERE (`approved` <> '1') AND (`deleted` IS NULL OR `deleted` <> 1) LIMIT " . $this->POSTS_PER_PAGE . $offsetQuery; $projects = $this->wpdb->get_results( $sql ); return $projects; } public function getMaxUnApprovedPages() { $sql = "SELECT COUNT(*) FROM ".PROJECT_TABLE_NAME." WHERE (`approved` <> '1') AND (`deleted` IS NULL OR `deleted` <> 1);"; $countOfRecords = $this->wpdb->get_results( $sql, ARRAY_N ); $countOfPage = ceil ($countOfRecords[0][0] / $this->POSTS_PER_PAGE); return $countOfPage; } public function getApprovedProjects($page = 0) { $offsetQuery = ''; if($page > 0){ $offset = $page * $this->POSTS_PER_PAGE; $offsetQuery = ' OFFSET ' . $offset; } $sql = "SELECT * FROM " . PROJECT_TABLE_NAME . " WHERE (`approved` = '1') AND (`deleted` IS NULL OR `deleted` <> 1) LIMIT " . $this->POSTS_PER_PAGE . $offsetQuery; $projects = $this->wpdb->get_results( $sql ); return $projects; } public function getMaxApprovedPages() { $sql = "SELECT COUNT(*) FROM ".PROJECT_TABLE_NAME." WHERE (`approved` = '1') AND (`deleted` IS NULL OR `deleted` <> 1);"; $countOfRecords = $this->wpdb->get_results( $sql, ARRAY_N ); $countOfPage = ceil ($countOfRecords[0][0] / $this->POSTS_PER_PAGE); return $countOfPage; } public function getProjectById($id) { $sql = "SELECT * FROM ".PROJECT_TABLE_NAME." WHERE id=" . $id; $projectData = $this->wpdb->get_row($sql, OBJECT); return $projectData; } public function getKeys() { try{ $keys = file_get_contents(PARSER_PATH.'/keywords.txt'); $keys = trim($keys); return $keys; }catch (\Exception $e) { echo 'Can`t get keywords: ', $e->getMessage(), "\n"; echo 'From file: ', PARSER_PATH.'/keywords.txt', "\n"; } } }