Esempio n. 1
0
 public function batchAction()
 {
     if (!$this->request->isPut()) {
         return $this->showErrorMessageAsJson(405, 'ERR_REQUEST_METHOD_NOT_ALLOW');
     }
     $idArray = $this->request->getPut('id');
     if (!is_array($idArray) || count($idArray) < 1) {
         return $this->showErrorMessageAsJson(401, 'ERR_REQUEST_PARAMS_INCORRECT');
     }
     $status = $this->request->getPut('status');
     $comments = array();
     $commentManager = new Models\CommentManager();
     try {
         foreach ($idArray as $id) {
             $comment = $commentManager->findCommentById($id);
             if ($comment) {
                 $commentManager->updateCommentStatus($comment, $status);
                 $comments[] = $comment;
             }
         }
     } catch (\Exception $e) {
         return $this->showExceptionAsJson($e, $comment->getMessages());
     }
     return $this->response->setJsonContent($comments);
 }
Esempio n. 2
0
 public function indexAction()
 {
     $limit = $this->request->getQuery('limit', 'int', 25);
     $limit = $limit > 100 ? 100 : $limit;
     $limit = $limit < 10 ? 10 : $limit;
     $orderMapping = array('id' => 'id ASC', '-id' => 'id DESC', 'created_at' => 'createdAt ASC', '-created_at' => 'createdAt DESC');
     $order = $this->request->getQuery('order', 'string', '-created_at');
     $query = array('q' => $this->request->getQuery('q', 'string'), 'status' => $this->request->getQuery('status', 'string'), 'uid' => $this->request->getQuery('uid', 'int'), 'cid' => $this->request->getQuery('cid', 'int'), 'username' => $this->request->getQuery('username', 'string'), 'order' => $order, 'limit' => $limit, 'page' => $this->request->getQuery('page', 'int', 1));
     $form = new Forms\FilterForm();
     $form->setValues($this->request->getQuery());
     $this->view->setVar('form', $form);
     $commentManager = new Models\CommentManager();
     $comments = $commentManager->findComments($query);
     $paginator = new \Eva\EvaEngine\Paginator(array("builder" => $comments, "limit" => $limit, "page" => $query['page']));
     $paginator->setQuery($query);
     $pager = $paginator->getPaginate();
     $this->view->setVar('pager', $pager);
     return $paginator;
 }
Esempio n. 3
0
 public function userVotesAction()
 {
     $data = array('up' => array(), 'down' => array());
     if ($user = $this->getUserInfo()) {
         $userId = $user['id'];
     } else {
         return $data;
     }
     $commentIds = $this->request->getQuery('commentIds');
     $commentManage = new CommentManager();
     $votes = $commentManage->findVotesByuserId($userId, $commentIds);
     foreach ($votes as $v) {
         if ($v->action == Votes::TYPE_UP) {
             $data['up'][] = $v->commentId;
         }
         if ($v->action == Votes::TYPE_DOWN) {
             $data['down'][] = $v->commentId;
         }
     }
     echo json_encode($data);
     $this->view->disable();
 }
Esempio n. 4
0
 /**
  * @operationName("Remove user and comments")
  * @operationDescription("Remove user and comments")
  */
 public function deleteUserCommentAction()
 {
     if (!$this->request->isDelete()) {
         return $this->showErrorMessageAsJson(405, 'ERR_REQUEST_METHOD_NOT_ALLOW');
     }
     $userId = $this->dispatcher->getParam('id');
     //删除评论
     $commentModel = new CommentManager();
     try {
         $comments = $commentModel->findCommentsByUserId($userId);
         foreach ($comments as $comment) {
             $commentModel->updateCommentStatus($comment, Comments::STATE_SPAM);
         }
         $commentModel->syncCommentNum();
     } catch (\Exception $e) {
         return $this->showExceptionAsJson($e, $comment->getMessages());
     }
     //删除用户
     $user = Models\UserManager::findFirst($userId);
     if (!$user) {
         return $this->showErrorMessageAsJson(404, 'ERR_USER_NOT_FOUND');
     }
     try {
         $user->status = 'deleted';
         $user->save();
     } catch (\Exception $e) {
         return $this->showExceptionAsJson($e, $user->getMessages());
     }
     $userInfo = $this->getUserInfo();
     $operationData = array('operatorId' => $userInfo['id'], 'subjectUser' => $user);
     $this->getDI()->getEventsManager()->fire('audit:createOperation', $operationData);
     return $this->response->setJsonContent($user);
 }
Esempio n. 5
0
 public function getLastComment()
 {
     $commentManager = new CommentManager();
     $lastComment = $commentManager->findLastCommentByUserId($this->id);
     return $lastComment;
 }
Esempio n. 6
0
 /**
  * Checks if a comment belongs to a thread. Returns the comment if it does.
  *
  * @param ThreadInterface $thread Thread object
  * @param mixed $commentId Id of the comment.
  *
  * @return CommentInterface|null The comment.
  */
 private function getValidCommentParent($thread, $commentId)
 {
     if (!empty($commentId)) {
         $commentManager = new CommentManager();
         $comment = $commentManager->findCommentById($commentId);
         if (!$comment) {
             //todo throw exception
             exit(sprintf('Parent comment with identifier "%s" does not exist', $commentId));
             //                throw new NotFoundHttpException(sprintf('Parent comment with identifier "%s" does not exist', $commentId));
         }
         //            if ($comment->getThread() !== $thread) {
         //                exit('Parent comment is not a comment of the given thread.');
         ////                throw new NotFoundHttpException('Parent comment is not a comment of the given thread.');
         //            }
         return $comment;
     }
 }
Esempio n. 7
0
 /**
  *
  * @SWG\Api(
  *   path="/comments/{commentId}",
  *   description="Comment related api",
  *   produces="['application/json']",
  *   @SWG\Operations(
  *     @SWG\Operation(
  *       method="GET",
  *       summary="Find comment by ID",
  *       notes="Returns a comment based on ID",
  *       @SWG\Parameters(
  *         @SWG\Parameter(
  *           name="commentId",
  *           description="ID of comment",
  *           paramType="path",
  *           required=true,
  *           type="integer"
  *         )
  *       )
  *     )
  *   )
  * )
  */
 public function getAction()
 {
     $id = $this->dispatcher->getParam('id');
     $commentManger = new Models\CommentManager();
     $comment = $commentManger->findCommentById($id);
     if (!$comment) {
         throw new Exception\ResourceNotFoundException('Request commment not exist');
     }
     $comment = $comment->dump(Entities\Comments::$defaultDump);
     return $this->response->setJsonContent($comment);
 }
Esempio n. 8
0
 /**
  * @operationName("用户评论列表")
  * @operationDescription("用户评论列表")
  */
 public function commentsAction()
 {
     $me = Login::getCurrentUser();
     $user = User::findFirstById($me['id']);
     $this->view->setVar('item', $user);
     $comment = new Comment();
     $comments = $comment->findCommentsByUser($user);
     $paginator = new Paginator(array("builder" => $comments, "limit" => 10, "page" => 1));
     //        $paginator->setQuery($query);
     $pager = $paginator->getPaginate();
     $this->view->setVar('pager', $pager);
 }