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

getRelated() public static method

Get related items based on tags
public static getRelated ( integer $id, integer $limit = 5 ) : array
$id integer
$limit integer
return array
    public static function getRelated($id, $limit = 5)
    {
        $relatedIDs = (array) FrontendTagsModel::getRelatedItemsByTags((int) $id, 'Faq', 'Faq');
        // there are no items, so return an empty array
        if (empty($relatedIDs)) {
            return array();
        }
        $link = FrontendNavigation::getURLForBlock('Faq', 'Detail');
        $items = (array) FrontendModel::getContainer()->get('database')->getRecords('SELECT i.id, i.question, m.url
             FROM faq_questions AS i
             INNER JOIN meta AS m ON i.meta_id = m.id
             WHERE i.language = ? AND i.hidden = ? AND i.id IN(' . implode(',', $relatedIDs) . ')
             ORDER BY i.question
             LIMIT ?', array(LANGUAGE, 'N', (int) $limit), 'id');
        foreach ($items as &$row) {
            $row['full_url'] = $link . '/' . $row['url'];
        }
        return $items;
    }

Usage Example

Beispiel #1
0
 /**
  * Parse the data into the template
  */
 private function parse()
 {
     // add to breadcrumb
     if ($this->settings['allow_multiple_categories']) {
         $this->breadcrumb->addElement($this->record['category_title'], $this->record['category_full_url']);
     }
     $this->breadcrumb->addElement($this->record['question']);
     // set meta
     if ($this->settings['allow_multiple_categories']) {
         $this->header->setPageTitle($this->record['category_title']);
     }
     $this->header->setPageTitle($this->record['question']);
     // assign article
     $this->tpl->assign('item', $this->record);
     // assign items in the same category and related items
     $this->tpl->assign('inSameCategory', FrontendFaqModel::getAllForCategory($this->record['category_id'], $this->settings['related_num_items'], $this->record['id']));
     $this->tpl->assign('related', FrontendFaqModel::getRelated($this->record['id'], $this->settings['related_num_items']));
     // assign settings
     $this->tpl->assign('settings', $this->settings);
     // parse the form
     if (empty($this->status)) {
         $this->frm->parse($this->tpl);
     }
     // parse the form status
     if (!empty($this->status)) {
         $this->tpl->assign($this->status, true);
     }
 }