Frontend\Modules\Faq\Engine\Model::getAllForCategory PHP Method

getAllForCategory() public static method

Get all items in a category
public static getAllForCategory ( integer $categoryId, integer $limit = null, mixed $excludeIds = null ) : array
$categoryId integer
$limit integer
$excludeIds mixed
return array
    public static function getAllForCategory($categoryId, $limit = null, $excludeIds = null)
    {
        $categoryId = (int) $categoryId;
        $limit = (int) $limit;
        $excludeIds = empty($excludeIds) ? array(0) : (array) $excludeIds;
        // get items
        if ($limit != null) {
            $items = (array) FrontendModel::getContainer()->get('database')->getRecords('SELECT i.*, m.url
                 FROM faq_questions AS i
                 INNER JOIN meta AS m ON i.meta_id = m.id
                 WHERE i.category_id = ? AND i.language = ? AND i.hidden = ?
                 AND i.id NOT IN (' . implode(',', $excludeIds) . ')
             ORDER BY i.sequence
             LIMIT ?', array((int) $categoryId, LANGUAGE, 'N', (int) $limit));
        } else {
            $items = (array) FrontendModel::getContainer()->get('database')->getRecords('SELECT i.*, m.url
                 FROM faq_questions AS i
                 INNER JOIN meta AS m ON i.meta_id = m.id
                 WHERE i.category_id = ? AND i.language = ? AND i.hidden = ?
                 AND i.id NOT IN (' . implode(',', $excludeIds) . ')
             ORDER BY i.sequence', array((int) $categoryId, LANGUAGE, 'N'));
        }
        // init var
        $link = FrontendNavigation::getURLForBlock('Faq', 'Detail');
        // build the item urls
        foreach ($items as &$item) {
            $item['full_url'] = $link . '/' . $item['url'];
        }
        return $items;
    }

Usage Example

Example #1
0
 /**
  * Load the data, don't forget to validate the incoming data
  */
 private function getData()
 {
     $categories = FrontendFaqModel::getCategories();
     $limit = $this->get('fork.settings')->get('Faq', 'overview_num_items_per_category', 10);
     foreach ($categories as $item) {
         $item['questions'] = FrontendFaqModel::getAllForCategory($item['id'], $limit);
         // no questions? next!
         if (empty($item['questions'])) {
             continue;
         }
         // add the category item including the questions
         $this->items[] = $item;
     }
 }
All Usage Examples Of Frontend\Modules\Faq\Engine\Model::getAllForCategory