Frontend\Modules\Tags\Engine\Model::getRelatedItemsByTags PHP Method

getRelatedItemsByTags() public static method

Get all related items
public static getRelatedItemsByTags ( integer $id, integer $module, integer $otherModule, integer $limit = 5 ) : array
$id integer The id of the item in the source-module.
$module integer The source module.
$otherModule integer The module wherein the related items should appear.
$limit integer The maximum of related items to grab.
return array
    public static function getRelatedItemsByTags($id, $module, $otherModule, $limit = 5)
    {
        return (array) FrontendModel::getContainer()->get('database')->getColumn('SELECT t2.other_id
             FROM modules_tags AS t
             INNER JOIN modules_tags AS t2 ON t.tag_id = t2.tag_id
             WHERE t.other_id = ? AND t.module = ? AND t2.module = ? AND
                (t2.module != t.module OR t2.other_id != t.other_id)
             GROUP BY t2.other_id
             ORDER BY COUNT(t2.tag_id) DESC
             LIMIT ?', array((int) $id, (string) $module, (string) $otherModule, (int) $limit));
    }

Usage Example

Example #1
0
 /**
  * Get related items based on tags
  *
  * @param int $id
  * @param int $limit
  *
  * @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;
 }
All Usage Examples Of Frontend\Modules\Tags\Engine\Model::getRelatedItemsByTags