Example #1
0
 /**
  * Retrieve a list of Posts for a specific tags id.
  *
  * @param int    $id       The Tags ID
  * @param string $slugTags
  *
  * @return array list of posts
  */
 public function postByTagAction($id, $slugName)
 {
     $join = ['type' => 'join', 'model' => 'Phanbook\\Models\\PostsTags', 'on' => 'pt.postsId = p.id', 'alias' => 'pt'];
     /**@Todo later for security*/
     $Where = 'p.deleted = 0 AND pt.tagsId = ' . $id;
     list($itemBuilder, $totalBuilder) = $this->prepareQueries($join, $Where, self::ITEM_IN_PAGE);
     //$itemBuilder->andWhere($conditions);
     $page = isset($_GET['page']) ? (int) $_GET['page'] : 1;
     $totalPosts = $totalBuilder->getQuery()->setUniqueRow(true)->execute();
     $totalPages = ceil($totalPosts->count / self::ITEM_IN_PAGE);
     if ($page > 1) {
         $itemBuilder->offset((int) $page);
     }
     $this->view->setVars(['tab' => 'tags', 'object' => $itemBuilder->getQuery()->execute(), 'totalPages' => $totalPages, 'currentPage' => $page, 'slugName' => $slugName, 'hotPosts' => Posts::getHotPosts()]);
     $this->tag->setTitle(t('These posts fillter by tags'));
     return $this->view->pick('post');
 }
Example #2
0
 /**
  * This initializes the timezone in each request
  */
 public function initialize()
 {
     $this->view->hotPosts = Posts::getHotPosts();
     parent::initialize();
 }
 public function editAnswerAction($id)
 {
     $auth = $this->auth->getAuth();
     $postReply = PostsReply::findFirstById($id);
     if (!$auth) {
         $this->flashSession->error(t('You must be logged in first to post answer'));
         return $this->currentRedirect();
     }
     if (!$this->auth->isTrustModeration() && $auth['id'] != $postReply->getUsersId()) {
         $this->flashSession->error(t('You don\'t have permission'));
         return $this->currentRedirect();
     }
     if (!$postReply) {
         $this->flashSession->error(t('The posts replies not exist!'));
         return $this->currentRedirect();
     }
     if ($this->request->isPost()) {
         //save history  postreplies table, it just for admin or moderator
         if ($this->auth->isTrustModeration() && $auth['id'] != $postReply->getUsersId()) {
             $postReplyHistory = new PostsReplyHistory();
             $postReplyHistory->setContent($this->request->getPost('content'));
             $postReplyHistory->setPostsReplyId($id);
             $postReplyHistory->setUsersId($auth['id']);
             if (!$postReplyHistory->save()) {
                 $this->saveLoger($postReplyHistory->getMessages());
             }
         }
         //Update replies post
         $postReply->setContent($this->request->getPost('content'));
         if (!$postReply->save()) {
             $this->saveLoger($postReply->getMessages());
         }
         $this->flashSession->success(t('Data was successfully saved'));
         return $this->response->redirect('/posts/' . $postReply->getPostsId() . '/editpost');
     }
     $this->view->hotPosts = Posts::getHotPosts();
     $this->view->form = new ReplyForm($postReply);
     $this->tag->setTitle(t('Edit answer'));
     return $this->view->pickCustom('replies/editAnswer');
 }
Example #4
0
 public function initialize()
 {
     $this->view->setVars(['tab' => $this->currentOrder, 'tags' => Tags::find(), 'hotPosts' => Posts::getHotPosts(5), 'totalPost' => Posts::totalPost(), 'highestKarma' => Users::highestKarma(), 'totalReply' => PostsReply::totalReply()]);
     if (isset($this->config->perPage)) {
         $this->perPage = $this->config->perPage;
     }
 }