/** * @operationName("Edit Post") * @operationDescription("Edit Post") */ public function editAction() { $this->view->changeRender('admin/post/create'); $post = Models\Post::findFirst($this->dispatcher->getParam('id')); if (!$post) { throw new Exception\ResourceNotFoundException('ERR_BLOG_POST_NOT_FOUND'); } $form = new Forms\PostForm(); $form->setModel($post); $form->addForm('text', 'Eva\\EvaBlog\\Forms\\TextForm'); $this->view->setVar('form', $form); $this->view->setVar('item', $post); if (!$this->request->isPost()) { return false; } $data = $this->request->getPost(); if (!$form->isFullValid($data)) { return $this->showInvalidMessages($form); } try { $form->save('updatePost'); } catch (\Exception $e) { return $this->showException($e, $form->getModel()->getMessages()); } $this->flashSession->success('SUCCESS_POST_UPDATED'); return $this->redirectHandler('/admin/post/edit/' . $post->id); }
public function tutorialAction() { $id = $this->dispatcher->getParam('id'); $id = $id ? $id : 'huangjingainian'; $post = Post::findFirst(array('conditions' => "slug = :slug:", 'bind' => array('slug' => $id))); if (!$post) { throw new Exception\ResourceNotFoundException('Request post not found'); } $this->view->setVar('post', $post); }
public function getTitle() { $postId = str_replace('post_', '', $this->uniqueKey); // p($postId); $post = Post::findFirst($postId); // p($post); if ($post) { return $post->title; } return $this->title; }
public function newsAction() { $id = $this->dispatcher->getParam('id'); if (is_numeric($id)) { $post = Post::findFirst($id); } else { $post = Post::findFirstBySlug($id); } if (!$post || $post->status != 'published') { throw new Exception\ResourceNotFoundException('Request post not found'); } $this->view->setVar('post', $post); }
/** * @operationName("Check post slug unique") * @operationDescription("Check post slug unique") */ public function slugAction() { $slug = $this->request->get('slug'); $exclude = $this->request->get('exclude'); if ($slug) { $conditions = array("columns" => array('id'), "conditions" => 'slug = :slug:', "bind" => array('slug' => $slug)); if ($exclude) { $conditions['conditions'] .= ' AND id != :id:'; $conditions['bind']['id'] = $exclude; } $post = Models\Post::findFirst($conditions); } else { $post = array(); } if ($post) { $this->response->setStatusCode('409', 'Post Already Exists'); } return $this->response->setJsonContent(array('exist' => $post ? true : false, 'id' => $post ? $post->id : 0)); }
/** * * @SWG\Api( * path="/admin/posts/{postId}", * description="Post related api", * produces="['application/json']", * @SWG\Operations( * @SWG\Operation( * method="DELETE", * summary="Delete post by ID", * notes="Returns deleted post", * @SWG\Parameters( * @SWG\Parameter( * name="postId", * description="ID of post", * paramType="path", * required=true, * type="integer" * ) * ) * ) * ) * ) * @operationName("删除文章") * @operationDescription("删除文章") */ public function deleteAction() { $id = $this->dispatcher->getParam('id'); $post = Models\Post::findFirst($id); if (!$post) { throw new Exception\ResourceNotFoundException('Request post not exist'); } $postinfo = $post->dump(Models\Post::$defaultDump); try { $post->removePost($id); return $this->response->setJsonContent($postinfo); } catch (\Exception $e) { return $this->showExceptionAsJson($e, $post->getMessages()); } }
/** * * @SWG\Api( * path="/posts/{postId}", * description="Posts Manage api", * produces="['application/json']", * @SWG\Operations( * @SWG\Operation( * method="GET", * summary="Find post by ID", * notes="Returns a post based on ID", * @SWG\Parameters( * @SWG\Parameter( * name="postId", * description="ID of post", * paramType="path", * required=true, * type="integer" * ) * ) * ) * ) * ) */ public function getAction() { $id = $this->dispatcher->getParam('id'); $postModel = new Models\Post(); $post = $postModel->findFirst($id); if (!$post || $post->status != 'published') { throw new Exception\ResourceNotFoundException('Request post not exist'); } $post = $post->dump(Models\Post::$defaultDump); return $this->response->setJsonContent($post); }