Пример #1
0
 /**
  * Method for voting a task
  *
  * @return mixed
  */
 public function voteAction()
 {
     $this->view->disable();
     if (!$this->request->isPost()) {
         return $this->response->redirect($this->router->getControllerName());
     }
     $way = 'positive';
     if ($this->request->getPost('way') == 'negative') {
         $way = 'negative';
     }
     $objectId = $this->request->getPost('objectId');
     $object = $this->request->getPost('object');
     $vote = Vote::vote($objectId, $object, $way);
     $user = Users::findFirstById($this->auth->getAuth()['id']);
     $this->setJsonResponse();
     if (!$user) {
         $this->jsonMessages['messages'][] = ['type' => 'error', 'content' => 'You need to login first'];
         return $this->jsonMessages;
     }
     if ($object == Vote::OBJECT_POSTS) {
         if (!($post = Posts::findFirstById($objectId))) {
             $this->jsonMessages['messages'][] = ['type' => 'error', 'content' => 'Post does not exist'];
             return $this->jsonMessages;
         }
         $this->setPointPost($way, $user, $post);
         //Adding notification when you have receive vote on the post, and not for now for post replies
         if ($user->getId() != $post->getUsersId()) {
             $this->setActivityNotifications($user, $post);
         }
     }
     if ($object == Vote::OBJECT_POSTS_REPLY) {
         if (!($postReply = PostsReply::findFirstById($objectId))) {
             $this->jsonMessages['messages'][] = ['type' => 'error', 'content' => 'Post reply does not exist'];
             return $this->jsonMessages;
         }
         //Set karam Voting someone else's post (positive or negative) on posts reply
         $this->setPointReply($way, $user, $postReply);
     }
     if (!$vote) {
         $this->jsonMessages['messages'][] = ['type' => 'error', 'content' => 'Vote have a problem :)'];
         return $this->jsonMessages;
     }
     if ($user->getVote() <= 0) {
         $this->jsonMessages['messages'][] = ['type' => 'error', 'content' => t('You don\'t have enough votes available :)')];
         return $this->jsonMessages;
     }
     //checking the user have already voted this post yet
     if (is_array($vote)) {
         $this->jsonMessages['messages'][] = $vote;
         return $this->jsonMessages;
     }
     if ($this->request->isAjax()) {
         $vote = (new Vote())->getVotes($objectId, $object);
         return ['data' => $vote['positive'] - $vote['negative']];
     }
     echo 0;
     return 0;
 }
Пример #2
0
 public function editAnswerAction($id)
 {
     $auth = $this->auth->getAuth();
     $postReply = PostsReply::findFirstById($id);
     if (!$auth) {
         $this->flashSession->error(t('You must be logged in first to post answer'));
         return $this->currentRedirect();
     }
     if (!$this->auth->isTrustModeration() && $auth['id'] != $postReply->getUsersId()) {
         $this->flashSession->error(t('You don\'t have permission'));
         return $this->currentRedirect();
     }
     if (!$postReply) {
         $this->flashSession->error(t('The posts replies not exist!'));
         return $this->currentRedirect();
     }
     if ($this->request->isPost()) {
         //save history  postreplies table, it just for admin or moderator
         if ($this->auth->isTrustModeration() && $auth['id'] != $postReply->getUsersId()) {
             $postReplyHistory = new PostsReplyHistory();
             $postReplyHistory->setContent($this->request->getPost('content'));
             $postReplyHistory->setPostsReplyId($id);
             $postReplyHistory->setUsersId($auth['id']);
             if (!$postReplyHistory->save()) {
                 $this->saveLoger($postReplyHistory->getMessages());
             }
         }
         //Update replies post
         $postReply->setContent($this->request->getPost('content'));
         if (!$postReply->save()) {
             $this->saveLoger($postReply->getMessages());
         }
         $this->flashSession->success(t('Data was successfully saved'));
         return $this->response->redirect('/posts/' . $postReply->getPostsId() . '/editpost');
     }
     $this->view->hotPosts = Posts::getHotPosts();
     $this->view->form = new ReplyForm($postReply);
     $this->tag->setTitle(t('Edit answer'));
     return $this->view->pickCustom('replies/editAnswer');
 }