Пример #1
0
 /**
  * Action for setting a status
  * @Acl(action="moderate")
  */
 public function setStatusAction()
 {
     $this->getHelper('contextSwitch')->addActionContext('set-status', 'json')->initContext();
     if (!SecurityToken::isValid()) {
         $this->view->status = 401;
         $this->view->message = getGS('Invalid security token!');
         return;
     }
     $status = $this->getRequest()->getParam('status');
     $comments = $this->getRequest()->getParam('comment');
     if (!is_array($comments)) {
         $comments = array($comments);
     }
     if ($status == "deleted") {
         $comments = array_unique(array_merge($comments, $this->getAllReplies($comments)));
     }
     try {
         foreach ($comments as $id) {
             $comment = $this->commentRepository->find($id);
             if ($status == "deleted") {
                 $msg = getGS('Comment delete by $1 from the article $2 ($3)', Zend_Registry::get('user')->getName(), $comment->getThread()->getName(), $comment->getLanguage()->getCode());
                 $this->_helper->flashMessenger($msg);
             } else {
                 $msg = getGS('Comment $4 by $1 in the article $2 ($3)', Zend_Registry::get('user')->getName(), $comment->getThread()->getName(), $comment->getLanguage()->getCode(), $status);
                 $this->_helper->flashMessenger($msg);
             }
         }
         $this->commentRepository->setStatus($comments, $status);
         $this->commentRepository->flush();
     } catch (Exception $e) {
         $this->view->status = $e->getCode();
         $this->view->message = $e->getMessage();
         return;
     }
     $this->view->status = 200;
     $this->view->message = "succcesful";
 }