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; }