public function updatepostAction(Param\NamedInt $id = null) { if ($post = Blogs\Post::getById($id)) { $post->setTitle($_POST['postTitle']); $post->setText($_POST['postText']); $post->setUser($_POST['user']); $post->save(); } $this->view->redirect('/adm/blogs/'); }
public function deleteAjaxActionAuth(Param\AjaxString $id = null) { $id = $id ? $id->val() : null; if (!($post = Blogs\Post::getById($id))) { $this->ajax->display(Difra\Locales::getInstance()->getXPath('blogs/notifies/post_not_found')); die; } $Auth = \Difra\Auth::getInstance(); if ($post->getUser() != $Auth->getEmail() && !$Auth->isModerator()) { $group = $post->getBlog()->getGroup(); if (!$group or $group->getOwner() != \Difra\Auth::getInstance()->getEmail()) { $this->ajax->display(Difra\Locales::getInstance()->getXPath('blogs/notifies/edit_post_denied')); die; } } $post::delete($id); $this->ajax->setResponse('success', true); }
/** * Добавляет пост * @param int $userId * @param string $title * @param string $text * @param bool $hidden * @return Post */ public function addPost($userId, $title, $text, $hidden = false) { return Post::add($this->id, $userId, ['title' => $title, 'text' => $text, 'visible' => $hidden ? '0' : '1']); }