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
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;
 }
Example #2
0
 /**
  * Get related items based on tags
  *
  * @param int $id    The id of the item to get related items for.
  * @param int $limit The maximum number of items to retrieve.
  * @return array
  */
 public static function getRelated($id, $limit = 5)
 {
     $id = (int) $id;
     $limit = (int) $limit;
     // get the related IDs
     $relatedIDs = (array) FrontendTagsModel::getRelatedItemsByTags($id, 'Blog', 'Blog', $limit);
     // no items
     if (empty($relatedIDs)) {
         return array();
     }
     // get link
     $link = FrontendNavigation::getURLForBlock('Blog', 'Detail');
     // get items
     $items = (array) FrontendModel::getContainer()->get('database')->getRecords('SELECT i.id, i.title, m.url
          FROM blog_posts AS i
          INNER JOIN meta AS m ON i.meta_id = m.id
          WHERE i.status = ? AND i.language = ? AND i.hidden = ? AND i.publish_on <= ? AND i.id IN(' . implode(',', $relatedIDs) . ')
          ORDER BY i.publish_on DESC, i.id DESC
          LIMIT ?', array('active', FRONTEND_LANGUAGE, 'N', FrontendModel::getUTCDate('Y-m-d H:i') . ':00', $limit), 'id');
     // loop items
     foreach ($items as &$row) {
         $row['full_url'] = $link . '/' . $row['url'];
     }
     return $items;
 }