public function detailAction()
 {
     $id = $this->dispatcher->getParam('id');
     $livenewsModel = new Models\NewsManager();
     $news = $livenewsModel->findFirst($id);
     if (!$news || $news->status != 'published') {
         throw new Exception\ResourceNotFoundException('Request news not found');
     }
     $this->view->setVar('news', $news);
 }
Exemple #2
0
 public function sideareaAction()
 {
     $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
     $query = array('q' => $this->request->getQuery('q', 'string'));
     $this->view->setVar('query', $query);
     $news = new Models\NewsManager();
     $newsSet = $news->findNews($query);
     $paginator = new \Eva\EvaEngine\Paginator(array("builder" => $newsSet, "limit" => 5, "page" => 1));
     $paginator->setQuery($query);
     $pager = $paginator->getPaginate();
     $this->view->setVar('pager', $pager);
 }
 public function livenewsAction()
 {
     $id = $this->dispatcher->getParam('id');
     if (is_numeric($id)) {
         $post = Models\NewsManager::findFirst($id);
     } else {
         $post = Models\NewsManager::findFirstBySlug($id);
     }
     if (!$post || $post->status != 'published') {
         throw new Exception\ResourceNotFoundException('Request post not found');
     }
     $this->view->setVar('post', $post);
 }
 /**
  * @operationName("Change livenews status")
  * @operationDescription("Change livenews status")
  */
 public function statusAction()
 {
     if (!$this->request->isPut()) {
         return $this->showErrorMessageAsJson(405, 'ERR_REQUEST_METHOD_NOT_ALLOW');
     }
     $id = $this->dispatcher->getParam('id');
     $post = Models\NewsManager::findFirst($id);
     try {
         $post->status = $this->request->getPut('status');
         $post->updatedAt = time();
         $post->save();
     } catch (\Exception $e) {
         return $this->showExceptionAsJson($e, $post->getMessages());
     }
     return $this->response->setJsonContent($post);
 }
Exemple #5
0
 /**
  * @operationName("Edit Livenews (For Data)")
  * @operationDescription("Edit Livenews (For Data)")
  */
 public function editAction()
 {
     $this->view->changeRender('admin/data/create');
     $news = Models\NewsManager::findFirst($this->dispatcher->getParam('id'));
     if (!$news) {
         throw new Exception\ResourceNotFoundException('ERR_LIVENEWS_NEWS_NOT_FOUND');
     }
     $form = new Forms\NewsForm();
     $form->setModel($news);
     $form->addForm('text', 'Eva\\EvaLivenews\\Forms\\TextForm');
     $this->view->setVar('form', $form);
     $this->view->setVar('item', $news);
     if (!$this->request->isPost()) {
         return false;
     }
     $data = $this->request->getPost();
     if ($this->request->isAjax()) {
         if (!$form->isFullValid($data)) {
             return $this->showInvalidMessagesAsJson($form);
         }
         try {
             $form->save('updateNews');
         } catch (\Exception $e) {
             return $this->showExceptionAsJson($e, $form->getModel()->getMessages());
         }
         return $this->showResponseAsJson($form->getModel()->dump(Models\NewsManager::$defaultDump));
     } else {
         if (!$form->isFullValid($data)) {
             return $this->showInvalidMessages($form);
         }
         try {
             $form->save('updateNews');
         } catch (\Exception $e) {
             return $this->showException($e, $form->getModel()->getMessages());
         }
         $this->flashSession->success('SUCCESS_NEWS_UPDATED');
         return $this->redirectHandler('/admin/livenews/news/edit/' . $news->id);
     }
 }
 /**
  *
  * @SWG\Api(
  *   path="/admin/livenews/{livenewsId}",
  *   description="Livenews related api",
  *   produces="['application/json']",
  *   @SWG\Operations(
  *     @SWG\Operation(
  *       method="DELETE",
  *       summary="Delete livenews by ID",
  *       notes="Returns deleted livenews",
  *       @SWG\Parameters(
  *         @SWG\Parameter(
  *           name="livenewsId",
  *           description="ID of livenews",
  *           paramType="path",
  *           required=true,
  *           type="integer"
  *         )
  *       )
  *     )
  *   )
  * )
  * @operationName("删除实时新闻")
  * @operationDescription("删除实时新闻")
  */
 public function deleteAction()
 {
     $id = $this->dispatcher->getParam('id');
     $livenews = Models\NewsManager::findFirst($id);
     if (!$livenews) {
         throw new Exception\ResourceNotFoundException('Request livenews not exist');
     }
     $livenewsinfo = $livenews->dump(Models\NewsManager::$defaultDump);
     try {
         $livenews->removeNews($id);
         return $this->response->setJsonContent($livenewsinfo);
     } catch (\Exception $e) {
         return $this->showExceptionAsJson($e, $livenews->getMessages());
     }
 }
 /**
  *
  * @SWG\Api(
  *   path="/livenews/{livenewsId}",
  *   description="Livenews related api",
  *   produces="['application/json']",
  *   @SWG\Operations(
  *     @SWG\Operation(
  *       method="GET",
  *       summary="Find livenews by ID",
  *       notes="Returns a livenews based on ID",
  *       @SWG\Parameters(
  *         @SWG\Parameter(
  *           name="livenewsId",
  *           description="ID of livenews",
  *           paramType="path",
  *           required=true,
  *           type="integer"
  *         )
  *       )
  *     )
  *   )
  * )
  */
 public function getAction()
 {
     $id = $this->dispatcher->getParam('id');
     $livenewsModel = new Models\NewsManager();
     $livenews = $livenewsModel->findFirst($id);
     if (!$livenews || $livenews->status != 'published') {
         throw new Exception\ResourceNotFoundException('Request livenews not exist');
     }
     $livenews = $livenews->dump(Models\NewsManager::$defaultDump);
     return $this->response->setJsonContent($livenews);
 }