public function indexAction() { $catId = (int) $this->getRequest()->getParam('id'); $forumMapper = new ForumMapper(); $forumItems = $forumMapper->getForumItemsByParent(1, $catId); $cat = $forumMapper->getForumById($catId); $this->getLayout()->getHmenu()->add($this->getTranslator()->trans('forum'), array('controller' => 'index', 'action' => 'index'))->add($cat->getTitle(), array('controller' => 'showcat', 'action' => 'index', 'id' => $cat->getId())); $this->getLayout()->set('metaTitle', $this->getTranslator()->trans('forumOverview')); $this->getLayout()->set('metaDescription', $this->getTranslator()->trans('forumOverview')); $this->getView()->set('forumItems', $forumItems); $this->getView()->set('forumMapper', $forumMapper); $this->getView()->set('cat', $cat); $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); }
public function indexAction() { $userMapper = new UserMapper(); $forumMapper = new ForumMapper(); $visitMapper = new StatisticMapper(); $staticsMapper = new ForumStaticsMapper(); $forumItems = $forumMapper->getForumItemsByParent(1, 0); $allOnlineUsers = $visitMapper->getVisitsCountOnline(); $usersOnline = $visitMapper->getVisitsOnlineUser(); $userId = null; $groupIds = array(0); if ($this->getUser()) { $userId = $this->getUser()->getId(); $user = $userMapper->getUserById($userId); $groupIds = array(); foreach ($user->getGroups() as $groups) { $groupIds[] = $groups->getId(); } } $groupIdsArray = explode(',', implode(',', $groupIds)); $this->getLayout()->getHmenu()->add($this->getTranslator()->trans('forum'), array('action' => 'index')); $this->getLayout()->set('metaTitle', $this->getTranslator()->trans('forumOverview')); $this->getLayout()->set('metaDescription', $this->getTranslator()->trans('forumOverview')); $this->getView()->set('groupIdsArray', $groupIdsArray); $this->getView()->set('forumItems', $forumItems); $this->getView()->set('forumMapper', $forumMapper); $this->getView()->set('usersOnline', count($usersOnline)); $this->getView()->set('guestOnline', $allOnlineUsers - count($usersOnline)); $this->getView()->set('forumStatics', $staticsMapper->getForumStatistics()); }
public function indexAction() { $forumMapper = new ForumMapper(); $topicMapper = new TopicMapper(); $pagination = new \Ilch\Pagination(); $userMapper = new UserMapper(); $forumId = $this->getRequest()->getParam('forumid'); $forum = $forumMapper->getForumById($forumId); $cat = $forumMapper->getCatByParentId($forum->getParentId()); $userId = null; $groupIds = array(0); if ($this->getRequest()->isPost() && $this->getRequest()->getPost('forumEdit') === 'forumEdit') { $forumEdit = true; $this->getView()->set('forumEdit', $forumEdit); } if ($this->getUser()) { $userId = $this->getUser()->getId(); $user = $userMapper->getUserById($userId); $groupIds = array(); foreach ($user->getGroups() as $groups) { $groupIds[] = $groups->getId(); } } $groupIdsArray = explode(',', implode(',', $groupIds)); $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('action' => 'index', 'forumid' => $forumId)); $pagination->setPage($this->getRequest()->getParam('page')); $this->getView()->set('forum', $forum); $this->getView()->set('topicMapper', $topicMapper); $this->getView()->set('forumMapper', $forumMapper); $this->getView()->set('topics', $topicMapper->getTopicsByForumId($forumId, $pagination)); $this->getView()->set('groupIdsArray', $groupIdsArray); $this->getView()->set('pagination', $pagination); }
public function __construct(array $pluginData) { $request = $pluginData['request']; $router = $pluginData['router']; $forumMapper = new ForumMapper(); $permas = $forumMapper->getForumPermas(); $url = $router->getQuery(); if (isset($permas[$url])) { $request->setModuleName('forum'); $request->setControllerName('showtopics'); $request->setActionName('index'); $request->setParam('forumid', $permas[$url]['id']); } }
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 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)); }
public function indexAction() { $this->getLayout()->getAdminHmenu()->add($this->getTranslator()->trans('forum'), array('action' => 'index')); $forumMapper = new ForumMapper(); $userGroupMapper = new UserGroupMapper(); /* * Saves the item tree to database. */ if ($this->getRequest()->isPost()) { if ($this->getRequest()->getPost('save')) { $sortItems = json_decode($this->getRequest()->getPost('hiddenMenu')); $items = $this->getRequest()->getPost('items'); $oldItems = $forumMapper->getForumItems(1); /* * Deletes old entries from database. */ if (!empty($oldItems)) { foreach ($oldItems as $oldItem) { if (!isset($items[$oldItem->getId()])) { $forumMapper->deleteItem($oldItem); } } } if ($items) { $sortArray = array(); foreach ($sortItems as $sortItem) { if ($sortItem->item_id !== null) { $sortArray[$sortItem->item_id] = (int) $sortItem->parent_id; } } foreach ($items as $item) { $forumItem = new \Modules\Forum\Models\ForumItem(); if (strpos($item['id'], 'tmp_') !== false) { $tmpId = str_replace('tmp_', '', $item['id']); } else { $forumItem->setId($item['id']); } $forumItem->setForumId(1); $forumItem->setType($item['type']); $forumItem->setTitle($item['title']); $forumItem->setDesc($item['desc']); $forumItem->setReadAccess($item['readAccess']); $forumItem->setReplayAccess($item['replayAccess']); $forumItem->setCreateAccess($item['createAccess']); $newId = $forumMapper->saveItem($forumItem); if (isset($tmpId)) { foreach ($sortArray as $id => $parentId) { if ($id == $tmpId) { unset($sortArray[$id]); $sortArray[$newId] = $parentId; } if ($parentId == $tmpId) { $sortArray[$id] = $newId; } } } } $sort = 0; foreach ($sortArray as $id => $parent) { $forumItem = new \Modules\Forum\Models\ForumItem(); $forumItem->setId($id); $forumItem->setSort($sort); $forumItem->setParentId($parent); $forumMapper->saveItem($forumItem); $sort += 10; } } } $this->addMessage('saveSuccess'); $this->redirect(array('action' => 'index')); } $forumItems = $forumMapper->getForumItemsByParent(1, 0); $this->getView()->set('forumItems', $forumItems); $this->getView()->set('forumMapper', $forumMapper); $userGroupList = $userGroupMapper->getGroupList(); $this->getView()->set('userGroupList', $userGroupList); }
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; }