示例#1
0
 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);
 }
示例#2
0
 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);
 }
示例#3
0
 /**
  * Updates visits.
  *
  * @param FileModel $model
  */
 public function saveVisits(TopicModel $model)
 {
     if ($model->getVisits()) {
         $this->db()->update('forum_topics')->values(array('visits' => $model->getVisits()))->where(array('id' => $model->getId()))->execute();
     }
 }