public function indexAction() { $postMapper = new PostMapper(); $topicMapper = new TopicMapper(); $forumMapper = new ForumMapper(); $topicModel = new ForumTopicModel(); $pagination = new \Ilch\Pagination(); $pagination->setPage($this->getRequest()->getParam('page')); $topicId = (int) $this->getRequest()->getParam('topicid'); $forumId = $forumMapper->getForumByTopicId($topicId); $forum = $forumMapper->getForumById($forumId->getId()); $cat = $forumMapper->getCatByParentId($forum->getParentId()); $posts = $postMapper->getPostByTopicId($topicId, $pagination); $post = $topicMapper->getPostById($topicId); $this->getLayout()->set('metaTitle', $this->getTranslator()->trans('forum') . ' - ' . $forum->getTitle()); $this->getLayout()->set('metaDescription', $this->getTranslator()->trans('forum') . ' - ' . $forum->getDesc()); $this->getLayout()->getHmenu()->add($this->getTranslator()->trans('forum'), array('controller' => 'index', 'action' => 'index'))->add($cat->getTitle(), array('controller' => 'showcat', 'action' => 'index', 'id' => $cat->getId()))->add($forum->getTitle(), array('controller' => 'showtopics', 'action' => 'index', 'forumid' => $forumId->getId()))->add($post->getTopicTitle(), array('controller' => 'showposts', 'action' => 'index', 'topicid' => $topicId)); $topicModel->setId($topicId); $topicModel->setVisits($post->getVisits() + 1); $topicMapper->saveVisits($topicModel); $userMapper = new UserMapper(); $userId = null; if ($this->getUser()) { $userId = $this->getUser()->getId(); $postMapper = new PostMapper(); $postModel = new ForumPostModel(); $lastPost = $topicMapper->getLastPostByTopicId($topicId); $lastRead = $lastPost->getRead(); if (in_array($this->getUser()->getId(), explode(',', $lastRead)) == false) { $postModel->setId($lastPost->getId()); $postModel->setRead($lastPost->getRead() . ',' . $this->getUser()->getId()); $postMapper->saveRead($postModel); } } $user = $userMapper->getUserById($userId); $ids = array(0); if ($user) { $ids = array(); foreach ($user->getGroups() as $us) { $ids[] = $us->getId(); } } $readAccess = explode(',', implode(',', $ids)); $this->getView()->set('post', $post); $this->getView()->set('posts', $posts); $this->getView()->set('forum', $forum); $this->getView()->set('readAccess', $readAccess); $this->getView()->set('pagination', $pagination); }
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; }
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; }
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; }