Exemplo n.º 1
0
 public function dispatch($request, $response)
 {
     // start session
     session_start();
     $article_id = $request->getPathParam('articleid');
     if ($request->isPost() === true) {
         //  handle post
         $title = $_POST['title'];
         $body = $_POST['body'];
         $summary = $_POST['summary'];
         ArticleService::saveArticleInSession($article_id, $title, $body, $summary);
         $response->redirect('/admin.php/edit/preview/' . $article_id);
     } else {
         if ($request->isGet() === true) {
             if (ArticleService::isArticleInSession($article_id)) {
                 $model = ArticleService::getArticleFromSession($article_id);
             } else {
                 $model = ArticleService::getArticle($article_id);
             }
             $view_adapter = new EditArticleViewAdapter($model);
             $this->view = new EditArticleView($view_adapter);
             $this->view->render();
         }
     }
 }
 public function dispatch($request, $response)
 {
     session_start();
     $article_id = $request->getPathParam('articleid');
     if ($request->isPost() === true) {
         if (ArticleService::isArticleInSession($article_id)) {
             $model = ArticleService::getArticleFromSession($article_id);
             ArticleService::updateArticle($model);
             $response->redirect('/admin.php');
         }
     } else {
         if (ArticleService::isArticleInSession($article_id)) {
             $model = ArticleService::getArticleFromSession($article_id);
             $view_adapter = new EditPreviewArticleViewAdapter($model);
             $this->view = new EditPreviewArticleView($view_adapter);
             $this->view->render();
         } else {
             $response->redirect('/admin.php');
         }
     }
 }
 public function dispatch($request, $response)
 {
     session_start();
     if ($request->isPost() === true) {
         $title = $request->postParameter('title');
         $body = $request->postParameter('body');
         $summary = $request->postParameter('summary');
         ArticleService::saveArticleInSession('_new', $title, $body, $summary);
         $response->redirect('/admin.php/create/preview/_new');
     } else {
         if ($request->isGet() === true) {
             //  treat as GET
             $article_id = $request->getParameter('id');
             if (isset($article_id) && ArticleService::isArticleInSession($article_id)) {
                 $model = ArticleService::getArticleFromSession($article_id);
                 $view = new CreateArticleView(new CreateArticleViewAdapter($model));
             } else {
                 $view = new CreateArticleView(new CreateArticleViewAdapter(ArticleService::nullArticle()));
             }
             $view->render();
         }
     }
 }