Пример #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);
 }
Пример #2
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);
 }