function getBlockForum() { $forumMapper = new Forum_Model_Mapper_Forum(); $select = $forumMapper->getDbTable()->select(); $select->where('parent_id != ?', 'null')->order('timestamp DESC')->limit(1, 0); $forumReply = $forumMapper->fetchAll($select); if (!empty($forumReply)) { $forumReply = array_shift($forumReply); $forumQuestion = $forumMapper->find($forumReply->getParentId(), new Forum_Model_Forum()); if (!is_null($forumQuestion)) { $this->view->assign(array('forum_question' => $forumQuestion, 'forum_reply' => $forumReply)); } } }
/** * @return $this */ public function setNoReplyForums() { $select = $this->_modelMapper->getDbTable()->select(); $select->where('parent_id is null')->where('deleted != ?', 1)->order('timestamp DESC'); $forumItems = $this->_modelMapper->fetchAll($select); if (!empty($forumItems)) { $forums = array(); $noReply = array(); /** @var Forum_Model_Forum $forumItem */ foreach ($forumItems as $forumItem) { $topic = array(); $select->reset()->where('parent_id = ?', $forumItem->getId())->where('deleted != ?', 1)->order('timestamp ASC'); $reply = $this->_modelMapper->fetchAll($select); if (0 !== count($reply)) { $topic['question'] = $forumItem; $topic['reply'] = $reply; } else { $noReply[] = $forumItem; } if (!empty($topic)) { $forums[] = $topic; } } $this->setNoReply($noReply); $this->setForums($forums); } return $this; }
public function forumItems() { $select = $this->_modelMapper->getDbTable()->select(); $select->where('parent_id is null')->where('deleted != ?', 1)->order('timestamp DESC'); $cache = Zend_Registry::get('cache'); $cacheName = 'forumItems'; if ($this->_request->getParam('section')) { $category = $this->_modelMapper->getCategoryArray(); $select->where('category = ?', $category[$this->_request->getParam('section')]); $cacheName = 'forumItems_' . $this->_request->getParam('section'); } if (!($forumItems = $cache->load($cacheName))) { $forumItems = $this->_modelMapper->fetchAll($select); $cache->save($forumItems, $cacheName, array('forum', 'forumQuestions')); } if (!empty($forumItems)) { $forums = array(); $noReply = array(); /** @var Forum_Model_Forum $forumItem */ foreach ($forumItems as $forumItem) { $topic = array(); $select->reset()->where('parent_id = ?', $forumItem->getId())->where('deleted != ?', 1)->order('timestamp ASC'); $cacheName = 'forumItems_reply_' . $forumItem->getId(); if (!($reply = $cache->load($cacheName))) { $reply = $this->_modelMapper->fetchAll($select); $cache->save($reply, $cacheName, array('forum', 'forumReply')); } if (0 !== count($reply)) { $topic['question'] = $forumItem; $topic['reply'] = $reply; } else { $noReply[] = $forumItem; } if (!empty($topic)) { $forums[] = $topic; } } $this->setNoReply($noReply); $this->setForums($forums); } return $this; }