public function viewAction() { // action body $id = $this->_request->getParam('id'); $post = $this->postModel->find($id); if ($post) { $userUtil = new Myblog_Model_Utils_User(); $commentModel = new Myblog_Model_Comment(); $this->view->post = $post->toObject(); $this->view->post->author = $userUtil->getNameById($post->getCreatedBy()); $this->view->post->commentsCount = $commentModel->getMapper()->countByQuery('post = ' . $id . ' AND parent = 0'); } else { $this->view->post = null; } }
protected function getChildren($post, $parent) { try { $response = array(); $commentModel = new Myblog_Model_Comment(); $comments = $commentModel->getMapper()->findByField(array('post', 'parent'), array('post' => $post, 'parent' => $parent)); if ($comments) { $userUtils = new Myblog_Model_Utils_User(); foreach ($comments as $comment) { $comment = $comment->toArray(); $comment['author'] = $userUtils->getNameById($comment['created_by']); $comment['children'] = $this->getChildren($post, $comment['id']); $response[] = $comment; } } return $response; } catch (Exception $ex) { echo $post, ' # ', $parent; exit; } }