public function unstickAction($id)
{
if (!$this->checkTokenGet('post-' . $id)) {
return $this->response->redirect();
}
if (!($usersId = $this->session->get('identity'))) {
$this->flashSession->error('You must be logged first');
$this->response->redirect();
return $this->response->redirect();
}
$parameters = ["id = ?0 AND sticked = ?1 AND 'Y' = ?2", 'bind' => [$id, Posts::IS_STICKED, $this->session->get('identity-moderator')]];
if (!($post = Posts::findFirst($parameters))) {
$this->flashSession->error('The discussion does not exist');
$this->response->redirect();
return $this->response->redirect();
}
if (Posts::IS_DELETED == $post->deleted) {
$this->flashSession->error("The post is deleted");
return $this->response->redirect();
}
$post->sticked = Posts::IS_UNSTICKED;
if ($post->save()) {
$this->flashSession->success('Discussion was successfully unsticked');
return $this->response->redirect();
}
$this->flashSession->error(join('<br>', $post->getMessages()));
return $this->response->redirect();
}