/**
  * Добавляет новую должность
  */
 public function addAction()
 {
     $result = array();
     $presentPost = \Posts::findFirst("title='" . $this->request->get("title") . "'");
     if ($presentPost != false) {
         $result['retcode'] = 1;
         $result['msgs'][] = "Посада із такою назвою вже існує!";
     } else {
         $namePost = new \Posts();
         $namePost->title = $this->request->get("title");
         if ($namePost->save() == false) {
             $result['retcode'] = 2;
             $result['msgs'][] = "Неможливо додати посаду \n";
             foreach ($namePost->getMessages() as $message) {
                 $result['msgs'][] = $message + "\n";
             }
         } else {
             $result['retcode'] = 0;
             $result['id'] = $namePost->id;
             $result['msgs'][] = "Нову посаду збережено";
         }
     }
     $this->view->disable();
     $this->response->setContentType('application/json', 'UTF-8');
     echo json_encode($result);
 }
Example #2
0
 public function setAction()
 {
     $post = ['name' => false, 'email' => false, 'comment' => true];
     if ($this->_status['response']['status'] && !$this->_getPost($post)) {
         $this->_status['response']['status'] = false;
         $this->_status['response']['code'] = 201;
         $this->_status['response']['detail'] = $post['empty'];
     }
     $urlId = $this->dispatcher->getParam('id');
     if (!$this->_status['response']['status'] && empty($urlId)) {
         $this->_status['response']['status'] = false;
         $this->_status['response']['code'] = 203;
     }
     $posts = Posts::findFirst($urlId);
     if ($this->_status['response']['status'] && !$posts) {
         $this->_status['response']['status'] = false;
         $this->_status['response']['code'] = 404;
     }
     if (!$this->_status['response']['status']) {
         return $this->response->setJsonContent($this->_status);
     }
     $comments = new Comments();
     $comments->assign(['posts_id' => $posts->id, 'name' => $this->_post['name'], 'email' => $this->_post['email'], 'comment' => $this->_post['comment']]);
     if (!$comments->save()) {
         $this->_status['response']['status'] = false;
         $this->_status['response']['code'] = 102;
     }
     return $this->response->setJsonContent($this->_status);
 }
 /**
  * Let’s read that record from the database. When using MySQL adapter,
  * like we do in this tutorial, $slug variable will be escaped so
  * we don’t have to deal with it.
  */
 public function showAction($slug)
 {
     $post = Posts::findFirst(array('slug = :slug:', 'bind' => array('slug' => $slug)));
     if ($post === false) {
         $this->flash->error("Sorry, post not found");
         $this->dispatcher->forward(array('controller' => 'posts', 'action' => 'index'));
     }
     $this->view->setVar('post', $post);
 }
Example #4
0
 public function postAction($id)
 {
     $post = Posts::findFirst($id);
     if (!$post) {
         return (new \Phalcon\Http\Response())->setStatusCode(404, "Not Found")->setContent("Not Found");
     }
     $this->view->pick('posts/post');
     $this->view->title = $post->getTitle();
     $this->view->content = $post->getContent();
     $this->view->id = $id;
     //select all comments for the post
     $comments = PostComments::find(array('conditions' => 'post_id = ?1', 'bind' => array(1 => $id)));
     $comment_array = array();
     foreach ($comments as $c) {
         $comment = Comments::findFirst($c->getCommentId());
         array_push($comment_array, array('commenter' => $comment->getName(), 'content' => $comment->getContent()));
     }
     $this->view->comments = $comment_array;
 }
 public function editAction($id = 0)
 {
     $editForm = new AutoForm(\Posts::findFirst($id), 'save');
     $this->view->setVars(['testForm' => $editForm]);
 }
Example #6
0
 public function articleAction()
 {
     $article_id = $this->dispatcher->getParam('id');
     $post = Posts::findFirst($article_id);
     if (!$post) {
         $this->_status['response']['status'] = false;
         $this->_status['response']['code'] = 404;
         return $this->response->setJsonContent($this->_status);
     }
     $content = preg_split('/\\[more\\]/', $post->content);
     $content = implode('', $content);
     $tags = Tags::findByPosts_id($post->id);
     $tag_array = [];
     if ($tags) {
         foreach ($tags as $tag) {
             $tag_array[] = $tag->tag;
         }
     }
     $categories = Categories::findByPosts_id($post->id);
     $category_array = [];
     if ($categories) {
         foreach ($categories as $category) {
             $category_array[] = $category->category;
         }
     }
     $comments = Comments::findByPosts_id($post->id);
     $comment_array = [];
     if ($comments) {
         foreach ($comments as $comment) {
             $array = [];
             $array['name'] = $comment->name;
             $array['email'] = $comment->email;
             $array['comment'] = $comment->comment;
             $comment_array[] = $array;
         }
     }
     $this->_status['response']['entry'] = ['id' => $post->id, 'author' => $post->users->name, 'title' => $post->title, 'content' => $content, 'tags' => $tag_array, 'categories' => $category_array, 'comments' => $comment_array];
     return $this->response->setJsonContent($this->_status);
 }