/** * Deletes a reply * * @param int $id */ public function deleteAction($id) { $usersId = $this->session->get('identity'); if (!$usersId) { return $this->response->setStatusCode('401', 'Unauthorized'); } $parametersReply = array('id = ?0 AND (users_id = ?1 OR "Y" = ?2)', 'bind' => array($id, $usersId, $this->session->get('identity-moderator'))); $postReply = PostsReplies::findFirst($parametersReply); if ($postReply) { if ($usersId == $postReply->users_id) { $user = $postReply->user; if ($user) { $user->decreaseKarma(Karma::DELETE_REPLY_ON_SOMEONE_ELSE_POST); $user->save(); } } else { $user = Users::findFirstById($usersId); if ($user) { if ($user->moderator == 'Y') { $user->increaseKarma(Karma::MODERATE_DELETE_REPLY); $user->save(); } } } if ($postReply->delete()) { if ($usersId != $postReply->post->users_id) { $user = $postReply->post->user; if ($user) { $user->decreaseKarma(Karma::SOMEONE_DELETED_HIS_OR_HER_REPLY_ON_MY_POST); $user->save(); } $postReply->post->number_replies--; $postReply->post->save(); } $this->flashSession->success('Reply was deleted successfully'); } $href = 'discussion/' . $postReply->post->id . '/' . $postReply->post->slug; return $this->response->redirect($href); } return $this->response->redirect(); }
/** * Deletes a reply * * @param int $id * * @return Response */ public function deleteAction($id) { $usersId = $this->session->get('identity'); if (!$usersId) { return $this->response->setStatusCode('401', 'Unauthorized'); } $parametersReply = ['id = ?0 AND (users_id = ?1 OR "Y" = ?2)', 'bind' => [$id, $usersId, $this->session->get('identity-moderator')]]; $postReply = PostsReplies::findFirst($parametersReply); if (!$postReply) { $this->flashSession->error('Post reply does not exist'); return $this->response->redirect(); } if (!$this->checkTokenGetJson('post-' . $postReply->post->id)) { $this->flashSession->error('This post is outdated. Please try to vote for the reply again.'); return $this->response->redirect(); } if ($postReply) { if ($usersId == $postReply->users_id) { $user = $postReply->user; if ($user) { $user->decreaseKarma(Karma::DELETE_REPLY_ON_SOMEONE_ELSE_POST); $user->save(); } } else { $user = Users::findFirstById($usersId); if ($user) { if ($user->moderator == 'Y') { $user->increaseKarma(Karma::MODERATE_DELETE_REPLY); $user->save(); } } } if ($postReply->delete()) { if ($usersId != $postReply->post->users_id) { $user = $postReply->post->user; if ($user) { $user->decreaseKarma(Karma::SOMEONE_DELETED_HIS_OR_HER_REPLY_ON_MY_POST); $user->save(); } $postReply->post->number_replies--; $postReply->post->save(); } $this->flashSession->success('Reply was deleted successfully'); } $href = 'discussion/' . $postReply->post->id . '/' . $postReply->post->slug; return $this->response->redirect($href); } return $this->response->redirect(); }