示例#1
0
 public function init()
 {
     parent::init();
     // change the label of `submit` button
     $this->getElement('submit')->setLabel('Save comment');
     $this->addElements(array($this->_status()));
 }
示例#2
0
 /**
  * Load the comments by the unique alias.
  *
  * Options:
  *      - template
  *      - key
  *
  * @param string $aliasKey
  * @param array $options
  * @return string
  * @throws Zend_Controller_Action_Exception
  */
 public function getComments($aliasKey, $options = array())
 {
     $user = Zend_Auth::getInstance()->getIdentity();
     $request = Zend_Controller_Front::getInstance()->getRequest();
     $aliasManager = new Comments_Model_CommentAlias_Manager();
     $manager = new Comments_Model_Comment_Manager();
     $alias = $aliasManager->getByAlias($aliasKey);
     $page = $request->getParam('page');
     $userId = $user ? $user->id : 0;
     $this->_checkOptions($options);
     // throws Exception when aliasKey is missed or wrong
     if (!$aliasKey || !$alias) {
         throw new Zend_Controller_Action_Exception('Page not found');
     }
     // throw Exception when key required and missed
     if (!$this->_key && $alias->isKeyRequired()) {
         throw new Zend_Controller_Action_Exception('Missed key parameter');
     }
     $paginator = Zend_Paginator::factory($manager->getSelect($alias, $userId, $this->_key));
     // set paginator options
     if ($alias->isPaginatorEnabled()) {
         $paginator->setItemCountPerPage($alias->countPerPage);
         $paginator->setCurrentPageNumber($page);
     } else {
         // Is there a way to disable pagination?
         $paginator->setItemCountPerPage(9999);
     }
     // init form
     $form = new Comments_Model_Comment_Form_Create();
     $form->setAlias($aliasKey);
     $form->setKey($this->_key);
     $form->setReturnUrl($this->view->url());
     if (!$alias->isTitleDisplayed()) {
         $form->removeTitleElement();
     }
     return $this->view->partial('list.phtml', 'comments', array('paginator' => $paginator, 'form' => $form, 'user' => $user, 'template' => $this->_template));
 }
 public function indexAction()
 {
     $aliasManager = new Comments_Model_CommentAlias_Manager();
     $commentsTable = new Comments_Model_Comment_Table();
     $alias = $aliasManager->getByAlias($this->getRequest()->getParam('alias'));
     $key = $this->getRequest()->getParam('key');
     if (!$alias) {
         throw new Zend_Controller_Action_Exception('Page not found');
     }
     // user should have an identity
     if (Zend_Auth::getInstance()->hasIdentity()) {
         $form = new Comments_Model_Comment_Form_Create();
         // check alias item options
         // check that required status for key
         if ($alias->isKeyRequired()) {
             $form->setKey($key);
         }
         // check need and visibility of title
         if (!$alias->isTitleDisplayed()) {
             $form->removeTitleElement();
         }
         // validate form by the POST request pararm
         if ($this->getRequest()->isPost() && $form->isValid($this->getRequest()->getParams())) {
             // creating new comments row
             $row = $commentsTable->createRow($form->getValues());
             $row->aliasId = $alias->id;
             $row->status = Comments_Model_Comment::STATUS_ACTIVE;
             // change status to "review" when pre-moderation required
             if ($alias->isPreModerationRequired()) {
                 $row->status = Comments_Model_Comment::STATUS_REVIEW;
             }
             $row->save();
             // display the flash message according to the comment status
             switch ($row->status) {
                 case Comments_Model_Comment::STATUS_REVIEW:
                     $this->_helper->flashMessenger->addMessage('Comment added successfully and awaiting pre-moderation.');
                     break;
                 default:
                     $this->_helper->flashMessenger->addMessage('Comment added successfully');
                     break;
             }
             // redirect to the URL that was setted to the form element
             $this->_redirect($form->getValue('returnUrl'));
         }
         // set the view variables
         $this->view->user = $this->view->user();
         $this->view->form = $form;
     }
 }