Example #1
0
 public function getPostByTopicId($topicId, $pagination = null)
 {
     $sql = 'SELECT SQL_CALC_FOUND_ROWS *
                        FROM `[prefix]_forum_posts`
                        WHERE topic_id = ' . $topicId . '
                        LIMIT ' . implode(',', $pagination->getLimit());
     $fileArray = $this->db()->queryArray($sql);
     $pagination->setRows($this->db()->querycell('SELECT FOUND_ROWS()'));
     $postEntry = array();
     $userMapper = new UserMapper();
     foreach ($fileArray as $entries) {
         $entryModel = new PostModel();
         $entryModel->setId($entries['id']);
         $entryModel->setText($entries['text']);
         $entryModel->setDateCreated($entries['date_created']);
         $entryModel->setAutor($userMapper->getUserById($entries['user_id']));
         $postEntry[] = $entryModel;
     }
     return $postEntry;
 }
Example #2
0
 public function getLastPostByTopicId($topicId)
 {
     $sql = 'SELECT `t`.`id`, `t`.`topic_id`, `p`.`read`, `p`.`id`, `p`.`topic_id`, `p`.`date_created`, `p`.`user_id`
             FROM `[prefix]_forum_topics` AS `t`
             LEFT JOIN `[prefix]_forum_posts` AS `p` ON `t`.`id` = `p`.`topic_id`
             WHERE `t`.`topic_id` = ' . $topicId . '
             ORDER BY `p`.`id` DESC';
     $fileRow = $this->db()->queryRow($sql);
     if (empty($fileRow)) {
         return null;
     }
     $entryModel = new PostModel();
     $userMapper = new UserMapper();
     $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 = $this->getCountPostsByTopicId($fileRow['topic_id']) - 1;
     $page = floor($posts / 20) + 1;
     $entryModel->setPage($page);
     return $entryModel;
 }
Example #3
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;
 }