public function getRelatedContents($id, $limit = -1) { $tags = $this->getTagIdsByContentId($id); $linkedContents = array(); $contents = array(); if (!empty($tags)) { $cntHasTagModel = new Default_Model_ContentHasTag(); $select = $cntHasTagModel->select()->from('cnt_has_tag', array('id_cnt'))->where('id_tag IN (?)', $tags)->where('id_cnt != ?', $id); if ($limit != -1) { $select->limit($limit); } $contents = $cntHasTagModel->fetchAll($select)->toArray(); } $cnthascntModel = new Default_Model_ContentHasContent(); $contents = array_merge($contents, $cnthascntModel->getContentLinkIds($id)); $linkedContents = $this->find($contents); $viewsModel = new Default_Model_ContentViews(); $rows = array(); foreach ($linkedContents as $row) { $tempRow = array(); $tempRow['title_cnt'] = $row->title_cnt; $tempRow['id_cnt'] = $row->id_cnt; $tempRow['language_cnt'] = $row->language_cnt; $tempRow['viewCount'] = $viewsModel->getViewsByContentId($row->id_cnt); $tempRow['contentType'] = $row->findDependentRowset('Default_Model_ContentTypes', 'ContentType')->current()->key_cty; array_push($rows, $tempRow); if ($limit != -1 && count($rows) >= $limit) { break; } } return $rows; }
public function getRelatedContents($id) { $tags = $this->getTagIdsByContentId($id); $linkedContents = array(); $cntHasTagModel = new Default_Model_ContentHasTag(); $select = $cntHasTagModel->select()->from('cnt_has_tag', array('id_cnt'))->where('id_tag IN (?)', $tags)->where('id_cnt != ?', $id); $contents = $cntHasTagModel->fetchAll($select)->toArray(); $linkedContents = $this->find($contents); $viewsModel = new Default_Model_ContentViews(); $rows = array(); foreach ($linkedContents as $row) { $tempRow = array(); $tempRow['title_cnt'] = $row->title_cnt; $tempRow['id_cnt'] = $row->id_cnt; $tempRow['viewCount'] = $viewsModel->getViewsByContentId($row->id_cnt); $tempRow['contentType'] = $row->findDependentRowset('Default_Model_ContentTypes', 'ContentType')->current()->key_cty; array_push($rows, $tempRow); } return $rows; }