コード例 #1
0
ファイル: model.php プロジェクト: netconstructor/forkcms
    /**
     * Get related items based on tags
     *
     * @return	array
     * @param	int $id					The id of the item to get related items for.
     * @param	int[optional] $limit	The maximum number of items to retrieve.
     */
    public static function getRelated($id, $limit = 5)
    {
        // redefine
        $id = (int) $id;
        $limit = (int) $limit;
        // get the related IDs
        $relatedIDs = (array) FrontendTagsModel::getRelatedItemsByTags($id, 'blog', 'blog');
        // no items
        if (empty($relatedIDs)) {
            return array();
        }
        // get link
        $link = FrontendNavigation::getURLForBlock('blog', 'detail');
        // get items
        $items = (array) FrontendModel::getDB()->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
        return $items;
    }
コード例 #2
0
ファイル: model.php プロジェクト: naujasdizainas/forkcms
    /**
     * Get related items based on tags
     *
     * @param int $id
     * @param int[optional] $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::getDB()->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(FRONTEND_LANGUAGE, 'N', (int) $limit), 'id');
        foreach ($items as &$row) {
            $row['full_url'] = $link . '/' . $row['url'];
        }
        return $items;
    }