Esempio n. 1
0
 /**
  * @return \Phalcon\Http\ResponseInterface
  */
 public function saveAction()
 {
     $this->view->disable();
     //  Is not $_POST
     if (!$this->request->isPost()) {
         return $this->indexRedirect();
     }
     $id = $this->request->getPost('id');
     if (!empty($id)) {
         $object = Posts::findFirstById($id);
         $object->setSlug(Slug::generate($this->request->getPost('title')));
     } else {
         $object = new Posts();
         //@todo
     }
     $form = new PostsForm($object);
     $form->bind($_POST, $object);
     //  Form isn't valid
     if (!$form->isValid($this->request->getPost())) {
         $this->saveLoger($form->getMessages());
         // Redirect to edit form if we have an ID in page, otherwise redirect to add a new item page
         return $this->response->redirect($this->getPathController() . (!is_null($id) ? '/edit/' . $id : '/new'));
     } else {
         if (!$object->save()) {
             $this->saveLoger($object->getMessages());
             return $this->dispatcher->forward(['controller' => $this->getPathController(), 'action' => 'new']);
         } else {
             $this->flashSession->success(t('Data was successfully saved'));
             return $this->currentRedirect();
         }
     }
 }
Esempio n. 2
0
 /**
  * @return \Phalcon\Http\ResponseInterface
  */
 public function saveAction()
 {
     //  Is not $_POST
     if (!$this->request->isPost()) {
         $this->view->disable();
         return $this->response->redirect($this->router->getControllerName());
     }
     $id = $this->request->getPost('id');
     $auth = $this->auth->getAuth();
     if (!$auth) {
         $this->flashSession->error('You must be logged first');
         return $this->currentRedirect();
     }
     //Checking tags
     $tags = $this->request->getPost('tags', 'string', null);
     if (is_string($this->phanbook->isTags($tags))) {
         $this->flashSession->notice(t($this->isTags($tags)));
         return $this->dispatcher->forward(['controller' => $this->router->getControllerName(), 'action' => !is_null($id) ? 'edit' : 'new', 'params' => !is_null($id) ? array($id) : array()]);
     }
     if (!empty($id)) {
         $object = Posts::findFirstById($id);
         $object->setSlug(Slug::generate($this->request->getPost('title')));
         //@Todo continue When moderator or admin edit post
         //Just to save history when user is TrustModarator and the user not owner the post
         if ($this->auth->isTrustModeration() && $auth['id'] != $object->getUsersId()) {
             $object->setEditedAt(time());
             $postHistory = new PostsHistory();
             $postHistory->setPostsId($id);
             $postHistory->setUsersId($auth['id']);
             $postHistory->setContent($this->request->getPost('content'));
             if (!$postHistory->save()) {
                 $this->saveLoger($postHistory->getMessages());
             }
         }
     } else {
         $object = new Posts();
         $object->setType(Posts::POST_QUESTIONS);
         $object->setSlug(Slug::generate($this->request->getPost('title')));
         $object->setUsersId($auth['id']);
         $user = Users::findFirstById($auth['id']);
         $user->increaseKarma(Karma::ADD_NEW_POST);
         if (!$user->save()) {
             $this->saveLoger($user->getMessages());
         }
     }
     $form = new QuestionsForm($object);
     $form->bind($_POST, $object);
     //  Form isn't valid
     if (!$form->isValid($this->request->getPost())) {
         $this->saveLoger($form->getMessages());
         // Redirect to edit form if we have an ID in page, otherwise redirect to add a new item page
         return $this->response->redirect($this->router->getControllerName() . (!is_null($id) ? '/edit/' . $id : '/new'));
     } else {
         if (!$object->save()) {
             $this->saveLoger($object->getMessages());
             return $this->dispatcher->forward(['controller' => $this->router->getControllerName(), 'action' => 'new']);
         } else {
             if (!$this->phanbook->saveTagsInPosts($tags, $object)) {
                 return $this->response->redirect($this->router->getControllerName() . (!is_null($id) ? '/edit/' . $id : '/new'));
             }
             $this->flashSession->success(t('Data was successfully saved'));
             return $this->response->redirect($this->router->getControllerName());
         }
     }
     $this->view->disable();
 }
Esempio n. 3
0
 /**
  * @return \Phalcon\Http\ResponseInterface
  */
 public function saveAction()
 {
     $this->view->disable();
     //  Is not $_POST
     if (!$this->request->isPost()) {
         return $this->indexRedirect();
     }
     $id = $this->request->getPost('id');
     $auth = $this->auth->getAuth();
     $tags = $this->request->getPost('tags', 'string', null);
     if (!empty($id)) {
         $object = Posts::findFirstById($id);
     } else {
         $object = new Posts();
         //@todo
     }
     $object->setSlug(Slug::generate($this->request->getPost('title')));
     $object->setUsersId($auth['id']);
     $form = new PostsForm($object);
     $form->bind($_POST, $object);
     //  Form isn't valid
     if (!$form->isValid($this->request->getPost())) {
         $this->saveLoger($form->getMessages());
         // Redirect to edit form if we have an ID in page, otherwise redirect to add a new item page
         return $this->response->redirect($this->getPathController() . (!is_null($id) ? '/edit/' . $id : '/new'));
     } else {
         $object->setStatus(Posts::PUBLISH_STATUS);
         //Save post to draft
         if ($this->request->getPost('saveDraft')) {
             $object->setStatus(Posts::DRAFT_STATUS);
         }
         if (!$object->save()) {
             $this->saveLoger($object->getMessages());
             return $this->dispatcher->forward(['controller' => $this->getPathController(), 'action' => 'new']);
         } else {
             $this->phanbook->tag()->saveTagsInPosts($tags, $object);
             $this->flashSession->success(t('Data was successfully saved'));
             return $this->indexRedirect();
         }
     }
 }
Esempio n. 4
0
 /**
  * @return \Phalcon\Http\ResponseInterface
  */
 public function saveHackernewAction()
 {
     //  Is not $_POST
     if (!$this->request->isPost()) {
         $this->view->disable();
         return $this->response->redirect($this->router->getControllerName());
     }
     $id = $this->request->getPost('id');
     $auth = $this->auth->getAuth();
     if (!$auth) {
         $this->flashSession->error('You must be logged first');
         return $this->currentRedirect();
     }
     if (!empty($id)) {
         $object = Posts::findFirstById($id);
         $object->setSlug(Slug::generate($this->request->getPost('title')));
         //@Todo continue When moderator or admin edit post
         if ($this->auth->isTrustModeration()) {
             $object->setEditedAt(time());
             $postHistory = new PostsHistory();
             $postHistory->setPostsId($id);
             $postHistory->setUsersId($auth['id']);
             $postHistory->setContent($this->request->getPost('content'));
             if (!$postHistory->save()) {
                 $this->saveLoger($postHistory->getMessages());
             }
         }
     } else {
         $object = new Posts();
         $object->setType(Posts::POST_HACKERNEWS);
         $object->setSlug(Slug::generate($this->request->getPost('title')));
         $object->setUsersId($auth['id']);
         $user = Users::findFirstById($auth['id']);
         $user->increaseKarma(Karma::ADD_NEW_POST_HACKERNEWS);
         if (!$user->save()) {
             $this->saveLoger($user->getMessages());
         }
     }
     $form = new HackernewForm($object);
     $form->bind($_POST, $object);
     //  Form isn't valid
     if (!$form->isValid($this->request->getPost())) {
         $this->saveLoger($form->getMessages());
         // Redirect to edit form if we have an ID in page, otherwise redirect to add a new item page
         return $this->response->redirect($this->router->getControllerName() . (!is_null($id) ? '/edit/' . $id : '/hackernew'));
     } else {
         if (!$object->save()) {
             $this->saveLoger($object->getMessages());
         }
         $this->flashSession->success(t('Data was successfully saved'));
         return $this->response->redirect($this->router->getControllerName());
     }
     $this->view->disable();
 }
Esempio n. 5
0
 public function slugAction()
 {
     $text = '85, Hồ văn hêu, phú nhuận, Tp Ho Chi Minh, VN';
     //d(GeoCoding::getData());
     d(Slug::generate($text, '+'));
 }