/** * Prepare topics by pre-loading needed information. * * @param array $userIds List of additional user Ids to be loaded. * @param array $mesIds List of additional message Ids to be loaded. * * @return void */ protected function prepareTopics(array $userIds = array(), array $mesIds = array()) { // Collect user Ids for avatar prefetch when integrated. $lastIds = array(); foreach ($this->topics as $topic) { $userIds[(int) $topic->first_post_userid] = (int) $topic->first_post_userid; $userIds[(int) $topic->last_post_userid] = (int) $topic->last_post_userid; $lastIds[(int) $topic->last_post_id] = (int) $topic->last_post_id; } // Prefetch all users/avatars to avoid user by user queries during template iterations. if (!empty($userIds)) { KunenaUserHelper::loadUsers($userIds); } $topicIds = array_keys($this->topics); KunenaForumTopicHelper::getUserTopics($topicIds); /* KunenaForumTopicHelper::getKeywords($topicIds); */ $mesIds += KunenaForumTopicHelper::fetchNewStatus($this->topics); // Fetch also last post positions when user can see unapproved or deleted posts. // TODO: Optimize? Take account of configuration option... if ($this->me->isAdmin() || KunenaAccess::getInstance()->getModeratorStatus()) { $mesIds += $lastIds; } // Load position information for all selected messages. if ($mesIds) { KunenaForumMessageHelper::loadLocation($mesIds); } }
protected function _common() { if ($this->total > 0) { $config = KunenaFactory::getConfig (); // collect user ids for avatar prefetch when integrated $userlist = array(); $lastpostlist = array(); foreach ( $this->topics as $topic ) { $userlist[intval($topic->first_post_userid)] = intval($topic->first_post_userid); $userlist[intval($topic->last_post_userid)] = intval($topic->last_post_userid); $lastpostlist[intval($topic->last_post_id)] = intval($topic->last_post_id); } // Prefetch all users/avatars to avoid user by user queries during template iterations if ( !empty($userlist) ) KunenaUserHelper::loadUsers($userlist); KunenaForumTopicHelper::getUserTopics(array_keys($this->topics)); KunenaForumTopicHelper::getKeywords(array_keys($this->topics)); $lastreadlist = KunenaForumTopicHelper::fetchNewStatus($this->topics); // Fetch last / new post positions when user can see unapproved or deleted posts $me = KunenaUserHelper::get(); if (($lastpostlist || $lastreadlist) && $me->userid && $me->isModerator()) { KunenaForumMessageHelper::loadLocation($lastpostlist + $lastreadlist); } } }
/** * @param array $userlist * @param array $postlist */ protected function _common(array $userlist = array(), array $postlist = array()) { if ($this->total > 0) { // collect user ids for avatar prefetch when integrated $lastpostlist = array(); foreach ($this->topics as $topic) { $userlist[intval($topic->first_post_userid)] = intval($topic->first_post_userid); $userlist[intval($topic->last_post_userid)] = intval($topic->last_post_userid); $lastpostlist[intval($topic->last_post_id)] = intval($topic->last_post_id); } // Prefetch all users/avatars to avoid user by user queries during template iterations if (!empty($userlist)) { KunenaUserHelper::loadUsers($userlist); } KunenaForumTopicHelper::getUserTopics(array_keys($this->topics)); KunenaForumTopicHelper::getKeywords(array_keys($this->topics)); $lastreadlist = KunenaForumTopicHelper::fetchNewStatus($this->topics); // Fetch last / new post positions when user can see unapproved or deleted posts if ($postlist || $lastreadlist || $this->me->userid && ($this->me->isAdmin() || KunenaAccess::getInstance()->getModeratorStatus())) { KunenaForumMessageHelper::loadLocation($postlist + $lastpostlist + $lastreadlist); } } }
public function getTopics() { if ($this->topics === false) { $catid = $this->getState('item.id'); $limitstart = $this->getState('list.start'); $limit = $this->getState('list.limit'); $format = $this->getState('format'); $topic_ordering = $this->getCategory()->topic_ordering; $access = KunenaAccess::getInstance(); $hold = $format == 'feed' ? 0 : $access->getAllowedHold($this->me, $catid); $moved = $format == 'feed' ? 0 : 1; $params = array('hold' => $hold, 'moved' => $moved); switch ($topic_ordering) { case 'alpha': $params['orderby'] = 'tt.ordering DESC, tt.subject ASC '; break; case 'creation': $params['orderby'] = 'tt.ordering DESC, tt.first_post_time ' . strtoupper($this->getState('list.direction')); break; case 'lastpost': default: $params['orderby'] = 'tt.ordering DESC, tt.last_post_time ' . strtoupper($this->getState('list.direction')); } if ($format == 'feed') { $catid = array_keys(KunenaForumCategoryHelper::getChildren($catid, 100) + array($catid => 1)); } list($this->total, $this->topics) = KunenaForumTopicHelper::getLatestTopics($catid, $limitstart, $limit, $params); if ($this->total > 0) { // collect user ids for avatar prefetch when integrated $userlist = array(); $lastpostlist = array(); foreach ($this->topics as $topic) { $userlist[intval($topic->first_post_userid)] = intval($topic->first_post_userid); $userlist[intval($topic->last_post_userid)] = intval($topic->last_post_userid); $lastpostlist[intval($topic->last_post_id)] = intval($topic->last_post_id); } // Prefetch all users/avatars to avoid user by user queries during template iterations if (!empty($userlist)) { KunenaUserHelper::loadUsers($userlist); } KunenaForumTopicHelper::getUserTopics(array_keys($this->topics)); KunenaForumTopicHelper::getKeywords(array_keys($this->topics)); $lastreadlist = KunenaForumTopicHelper::fetchNewStatus($this->topics); // Fetch last / new post positions when user can see unapproved or deleted posts if (($lastpostlist || $lastreadlist) && ($this->me->isAdmin() || KunenaAccess::getInstance()->getModeratorStatus())) { KunenaForumMessageHelper::loadLocation($lastpostlist + $lastreadlist); } } } return $this->topics; }
/** * Prepare category display. * * @return void * * @throws KunenaExceptionAuthorise */ protected function before() { parent::before(); require_once KPATH_SITE . '/models/category.php'; $this->model = new KunenaModelCategory(); $this->me = KunenaUserHelper::getMyself(); $catid = $this->input->getInt('catid'); $limitstart = $this->input->getInt('limitstart', 0); $limit = $this->input->getInt('limit', 0); if ($limit < 1 || $limit > 100) { $limit = $this->config->threads_per_page; } // TODO: $direction = 'DESC'; $this->category = KunenaForumCategoryHelper::get($catid); $this->category->tryAuthorise(); $this->headerText = JText::_('COM_KUNENA_THREADS_IN_FORUM') . ': ' . $this->category->name; $topic_ordering = $this->category->topic_ordering; $access = KunenaAccess::getInstance(); $hold = $access->getAllowedHold($this->me, $catid); $moved = 1; $params = array('hold' => $hold, 'moved' => $moved); switch ($topic_ordering) { case 'alpha': $params['orderby'] = 'tt.ordering DESC, tt.subject ASC '; break; case 'creation': $params['orderby'] = 'tt.ordering DESC, tt.first_post_time ' . $direction; break; case 'lastpost': default: $params['orderby'] = 'tt.ordering DESC, tt.last_post_time ' . $direction; } list($this->total, $this->topics) = KunenaForumTopicHelper::getLatestTopics($catid, $limitstart, $limit, $params); if ($this->total > 0) { // Collect user ids for avatar prefetch when integrated. $userlist = array(); $lastpostlist = array(); foreach ($this->topics as $topic) { $userlist[intval($topic->first_post_userid)] = intval($topic->first_post_userid); $userlist[intval($topic->last_post_userid)] = intval($topic->last_post_userid); $lastpostlist[intval($topic->last_post_id)] = intval($topic->last_post_id); } // Prefetch all users/avatars to avoid user by user queries during template iterations. if (!empty($userlist)) { KunenaUserHelper::loadUsers($userlist); } KunenaForumTopicHelper::getUserTopics(array_keys($this->topics)); KunenaForumTopicHelper::getKeywords(array_keys($this->topics)); $lastreadlist = KunenaForumTopicHelper::fetchNewStatus($this->topics); // Fetch last / new post positions when user can see unapproved or deleted posts. if ($lastreadlist || $this->me->isAdmin() || KunenaAccess::getInstance()->getModeratorStatus()) { KunenaForumMessageHelper::loadLocation($lastpostlist + $lastreadlist); } } $this->topicActions = $this->model->getTopicActions(); $this->actionMove = $this->model->getActionMove(); $this->pagination = new KunenaPagination($this->total, $limitstart, $limit); $this->pagination->setDisplayedPages(5); }