public function indexAction() { $forumMapper = new ForumMapper(); $id = (int) $this->getRequest()->getParam('id'); $forum = $forumMapper->getForumById($id); $cat = $forumMapper->getCatByParentId($forum->getParentId()); $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' => $id))->add($this->getTranslator()->trans('newTopicTitle'), array('controller' => 'newtopic', 'action' => 'index', 'id' => $id)); if ($this->getRequest()->getPost('saveNewTopic')) { $topicModel = new ForumTopicModel(); $topicMapper = new TopicMapper(); $dateTime = new \Ilch\Date(); $topicModel->setTopicTitle($this->getRequest()->getPost('topicTitle')); $topicModel->setText($this->getRequest()->getPost('text')); $topicModel->setTopicId($id); $topicModel->setForumId($id); $topicModel->setCat($id); $topicModel->setCreatorId($this->getUser()->getId()); $topicModel->setType($this->getRequest()->getPost('type')); $topicModel->setDateCreated($dateTime); $topicMapper->save($topicModel); $postMapper = new PostMapper(); $postModel = new ForumPostModel(); $lastid = $topicMapper->getLastInsertId(); $postModel->setTopicId($lastid); $postModel->setUserId($this->getUser()->getId()); $postModel->setText($this->getRequest()->getPost('text')); $postModel->setDateCreated($dateTime); $postMapper->save($postModel); $this->redirect(array('controller' => 'showposts', 'action' => 'index', 'topicid' => $lastid)); } $userMapper = new UserMapper(); $userId = null; if ($this->getUser()) { $userId = $this->getUser()->getId(); } $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('readAccess', $readAccess); $this->getView()->set('forum', $forum); }
public function indexAction() { $forumMapper = new ForumMapper(); $topicId = (int) $this->getRequest()->getParam('topicid'); $forum = $forumMapper->getForumByTopicId($topicId); $cat = $forumMapper->getCatByParentId($forum->getParentId()); $this->getLayout()->set('metaTitle', $this->getTranslator()->trans('forum') . ' - ' . $forum->getTitle()); $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' => $forum->getId()))->add($this->getTranslator()->trans('newPost'), array('controller' => 'newpost', 'action' => 'index', 'topicid' => $topicId)); if ($this->getRequest()->getPost('saveNewPost')) { $postMapper = new PostMapper(); $postModel = new ForumPostModel(); $dateTime = new \Ilch\Date(); $postModel->setTopicId($topicId); $postModel->setUserId($this->getUser()->getId()); $postModel->setText($this->getRequest()->getPost('text')); $postModel->setForumId($forum->getId()); $postModel->setDateCreated($dateTime); $postMapper->save($postModel); $lastPost = $forumMapper->getLastPostByTopicId($forum->getId()); $this->redirect(array('controller' => 'showposts', 'action' => 'index', 'topicid' => $lastPost->getTopicId(), 'page' => $lastPost->getPage())); } }
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; }