public function deleteAction()
 {
     $postMapper = new PostMapper();
     $topicMapper = new TopicMapper();
     $forumMapper = new ForumMapper();
     $postId = (int) $this->getRequest()->getParam('id');
     $topicId = (int) $this->getRequest()->getParam('topicid');
     $forumId = (int) $this->getRequest()->getParam('forumid');
     $countPosts = $forumMapper->getCountPostsByTopicId($topicId);
     if ($this->getUser()) {
         if ($this->getUser()->isAdmin()) {
             $postMapper->deleteById($postId);
             if ($countPosts === '1') {
                 $topicMapper->deleteById($topicId);
                 $this->redirect(array('controller' => 'showtopics', 'action' => 'index', 'forumid' => $forumId));
             }
             $this->redirect(array('controller' => 'showposts', 'action' => 'index', 'topicid' => $topicId, 'forumid' => $forumId));
         }
     }
     $this->addMessage('noAccess', 'danger');
     $this->redirect(array('controller' => 'showposts', 'action' => 'index', 'topicid' => $topicId, 'forumid' => $forumId));
 }
Exemple #2
0
 public function getLastPostByTopicId($id)
 {
     $sql = 'SELECT p.id, p.topic_id, p.date_created, p.user_id, p.read
             FROM [prefix]_forum_posts as p 
             WHERE p.topic_id = ' . $id . '
               ORDER BY p.id DESC         ';
     $fileRow = $this->db()->queryRow($sql);
     if (empty($fileRow)) {
         return null;
     }
     $entryModel = new PostModel();
     $userMapper = new UserMapper();
     $forumMapper = new ForumMapper();
     $entryModel->setId($fileRow['id']);
     $entryModel->setAutor($userMapper->getUserById($fileRow['user_id']));
     $entryModel->setDateCreated($fileRow['date_created']);
     $entryModel->setTopicId($fileRow['topic_id']);
     $entryModel->setRead($fileRow['read']);
     $posts = $forumMapper->getCountPostsByTopicId($fileRow['topic_id']) - 1;
     $page = floor($posts / 20) + 1;
     $entryModel->setPage($page);
     return $entryModel;
 }