public function listAction() { $viewer = Engine_Api::_()->user()->getViewer(); //$this->view->subject = $subject = Engine_Api::_()->core()->getSubject(); $this->view->subject = $subject = $this->_subject; // Perms $this->view->canComment = $canComment = $subject->authorization()->isAllowed($viewer, 'comment'); $this->view->canDelete = $subject->authorization()->isAllowed($viewer, 'edit'); // Likes $this->view->viewAllLikes = $this->_getParam('viewAllLikes', false); $this->view->likes = $likes = $subject->likes()->getLikePaginator(); // If has a page, display oldest to newest if (null !== ($page = $this->_getParam('page'))) { $commentSelect = $subject->comments()->getCommentSelect(); $commentSelect->order('comment_id ASC'); $comments = Zend_Paginator::factory($commentSelect); $comments->setCurrentPageNumber($page); $comments->setItemCountPerPage(10); $this->view->comments = $comments; $this->view->page = $page; } else { $commentSelect = $subject->comments()->getCommentSelect(); $commentSelect->order('comment_id DESC'); $comments = Zend_Paginator::factory($commentSelect); $comments->setCurrentPageNumber(1); $comments->setItemCountPerPage(4); $this->view->comments = $comments; $this->view->page = $page; } if ($viewer->getIdentity() && $canComment) { $this->view->form = $form = new Core_Form_Comment_Create(); $form->populate(array('identity' => $subject->getIdentity(), 'type' => $subject->getType())); } }
public function indexAction() { // Get subject $subject = null; if (Engine_Api::_()->core()->hasSubject()) { $subject = Engine_Api::_()->core()->getSubject(); } else { if ($subject = $this->_getParam('subject')) { list($type, $id) = explode('_', $subject); $subject = Engine_Api::_()->getItem($type, $id); } else { if (($type = $this->_getParam('type')) && ($id = $this->_getParam('id'))) { $subject = Engine_Api::_()->getItem($type, $id); } } } if (!$subject instanceof Core_Model_Item_Abstract || !$subject->getIdentity() || !method_exists($subject, 'comments') && !method_exists($subject, 'likes')) { return $this->setNoRender(); } // Perms $viewer = Engine_Api::_()->user()->getViewer(); $this->view->canComment = $canComment = $subject->authorization()->isAllowed($viewer, 'comment'); $this->view->canDelete = $canDelete = $subject->authorization()->isAllowed($viewer, 'edit'); // Likes $this->view->viewAllLikes = $this->_getParam('viewAllLikes', false); $this->view->likes = $likes = $subject->likes()->getLikePaginator(); // Comments // If has a page, display oldest to newest if (null !== ($page = $this->_getParam('page'))) { $commentSelect = $subject->comments()->getCommentSelect(); $commentSelect->order('comment_id ASC'); $comments = Zend_Paginator::factory($commentSelect); $comments->setCurrentPageNumber($page); $comments->setItemCountPerPage(10); $this->view->comments = $comments; $this->view->page = $page; } else { // If not has a page, show the $commentSelect = $subject->comments()->getCommentSelect(); $commentSelect->order('comment_id DESC'); $comments = Zend_Paginator::factory($commentSelect); $comments->setCurrentPageNumber(1); $comments->setItemCountPerPage(4); $this->view->comments = $comments; $this->view->page = $page; } if ($viewer->getIdentity() && $canComment) { $this->view->form = $form = new Core_Form_Comment_Create(); //$form->setAction($this->view->url(array('action' => ''))) $form->populate(array('identity' => $subject->getIdentity(), 'type' => $subject->getType())); } // Hide if can't post and no comments if (!$canComment && !$canDelete && count($comments) <= 0 && count($likes) <= 0) { $this->setNoRender(); } }