Exemplo n.º 1
0
 /**
  * This shows the create post form and also store the related post
  */
 public function editAction($id)
 {
     $usersId = $this->session->get('identity');
     if (!$usersId) {
         $this->flashSession->error('You must be logged first');
         return $this->response->redirect();
     }
     /**
      * Find the post using get
      */
     $parameters = array("id = ?0 AND (users_id = ?1 OR 'Y' = ?2)", "bind" => array($id, $usersId, $this->session->get('identity-moderator')));
     $post = Posts::findFirst($parameters);
     if (!$post) {
         $this->flashSession->error('The discussion does not exist');
         return $this->response->redirect();
     }
     if ($this->request->isPost()) {
         if (!$this->checkTokenPost()) {
             return $this->response->redirect();
         }
         $title = $this->request->getPost('title', 'trim');
         $content = $this->request->getPost('content');
         $post->categories_id = $this->request->getPost('categoryId');
         $post->title = $title;
         $post->slug = Slug::generate($title);
         $post->content = $content;
         $post->edited_at = time();
         $usersId = $this->session->get('identity');
         if ($post->users_id != $usersId) {
             /** @var Users $user */
             $user = Users::findFirstById($usersId);
             if ($user) {
                 $user->increaseKarma(Karma::MODERATE_POST);
                 $user->save();
             }
         }
         if ($post->save()) {
             return $this->response->redirect('discussion/' . $post->id . '/' . $post->slug);
         }
         foreach ($post->getMessages() as $message) {
             $this->flash->error($message);
         }
     } else {
         $this->tag->displayTo('id', $post->id);
         $this->tag->displayTo('title', $post->title);
         $this->tag->displayTo('content', $post->content);
         $this->tag->displayTo('categoryId', $post->categories_id);
     }
     $this->tag->setTitle('Edit Tip: ' . $this->escaper->escapeHtml($post->title));
     $parametersCategory = array('order' => 'name');
     $this->view->categories = Categories::find($parametersCategory);
     $this->view->post = $post;
 }
Exemplo n.º 2
0
 /**
  * @dataProvider validUrlProvider
  * @param string $input
  * @param string $expected
  */
 public function testShouldConvertNonAsciiStringToValidUrl($input, $expected)
 {
     $this->assertEquals($expected, $this->slug->generate($input));
 }