Frontend\Modules\Blog\Engine\Model::getAllCategories PHP Метод

getAllCategories() публичный статический Метод

Get all categories used
public static getAllCategories ( ) : array
Результат array
    public static function getAllCategories()
    {
        $return = (array) FrontendModel::getContainer()->get('database')->getRecords('SELECT c.id, c.title AS label, m.url, COUNT(c.id) AS total, m.data AS meta_data
             FROM blog_categories AS c
             INNER JOIN blog_posts AS i ON c.id = i.category_id AND c.language = i.language
             INNER JOIN meta AS m ON c.meta_id = m.id
             WHERE c.language = ? AND i.status = ? AND i.hidden = ? AND i.publish_on <= ?
             GROUP BY c.id', array(LANGUAGE, 'active', 'N', FrontendModel::getUTCDate('Y-m-d H:i')), 'id');
        // loop items and unserialize
        foreach ($return as &$row) {
            if (isset($row['meta_data'])) {
                $row['meta_data'] = @unserialize($row['meta_data']);
            }
        }
        return $return;
    }

Usage Example

Пример #1
0
 /**
  * Load the data, don't forget to validate the incoming data
  */
 private function getData()
 {
     // get categories
     $categories = FrontendBlogModel::getAllCategories();
     $possibleCategories = array();
     foreach ($categories as $category) {
         $possibleCategories[$category['url']] = $category['id'];
     }
     // requested category
     $requestedCategory = \SpoonFilter::getValue($this->URL->getParameter(1, 'string'), array_keys($possibleCategories), 'false');
     // requested page
     $requestedPage = $this->URL->getParameter('page', 'int', 1);
     // validate category
     if ($requestedCategory == 'false') {
         $this->redirect(FrontendNavigation::getURL(404));
     }
     // set category
     $this->category = $categories[$possibleCategories[$requestedCategory]];
     // set URL and limit
     $this->pagination['url'] = FrontendNavigation::getURLForBlock('Blog', 'Category') . '/' . $requestedCategory;
     $this->pagination['limit'] = $this->get('fork.settings')->get('Blog', 'overview_num_items', 10);
     // populate count fields in pagination
     $this->pagination['num_items'] = FrontendBlogModel::getAllForCategoryCount($requestedCategory);
     $this->pagination['num_pages'] = (int) ceil($this->pagination['num_items'] / $this->pagination['limit']);
     // redirect if the request page doesn't exists
     if ($requestedPage > $this->pagination['num_pages'] || $requestedPage < 1) {
         $this->redirect(FrontendNavigation::getURL(404));
     }
     // populate calculated fields in pagination
     $this->pagination['requested_page'] = $requestedPage;
     $this->pagination['offset'] = $this->pagination['requested_page'] * $this->pagination['limit'] - $this->pagination['limit'];
     // get articles
     $this->items = FrontendBlogModel::getAllForCategory($requestedCategory, $this->pagination['limit'], $this->pagination['offset']);
 }
All Usage Examples Of Frontend\Modules\Blog\Engine\Model::getAllCategories