public function unsubscribeAction($id)
{
if (!$this->checkTokenGet('post-' . $id)) {
return $this->response->redirect();
}
$usersId = $this->session->get('identity');
if (!$usersId) {
$this->flashSession->error('You must be logged first');
return $this->response->redirect();
}
$post = Posts::findFirstById($id);
if (!$post) {
$this->flashSession->error('The discussion does not exist');
return $this->response->redirect();
}
$subscription = PostsSubscribers::findFirst(['posts_id = ?0 AND users_id = ?1', 'bind' => [$post->id, $usersId]]);
if ($subscription) {
$this->flashSession->notice('You were successfully unsubscribed from this post');
$subscription->delete();
}
return $this->response->redirect('discussion/' . $post->id . '/' . $post->slug);
}