Beispiel #1
0
 public static function getUnansweredCount($categoryId = '0', $excludeFeatured = false)
 {
     $db = DiscussHelper::getDBO();
     $excludeCats = DiscussHelper::getPrivateCategories();
     $catModel = DiscussHelper::getModel('Categories');
     if (!is_array($categoryId) && !empty($categoryId)) {
         $categoryId = array($categoryId);
     }
     $childs = array();
     if ($categoryId) {
         foreach ($categoryId as $id) {
             $data = $catModel->getChildIds($id);
             if ($data) {
                 foreach ($data as $childCategory) {
                     $childs[] = $childCategory;
                 }
             }
             $childs[] = $id;
         }
     }
     if (!$categoryId) {
         $categoryIds = false;
     } else {
         $categoryIds = array_diff($childs, $excludeCats);
     }
     $query = 'SELECT COUNT(a.`id`) FROM `#__discuss_posts` AS a';
     $query .= '  LEFT JOIN `#__discuss_posts` AS b';
     $query .= '    ON a.`id`=b.`parent_id`';
     $query .= '    AND b.`published`=' . $db->Quote('1');
     $query .= ' WHERE a.`parent_id` = ' . $db->Quote('0');
     $query .= ' AND a.`published`=' . $db->Quote('1');
     $query .= ' AND  a.`answered` = 0';
     $query .= ' AND a.`isresolve`=' . $db->Quote('0');
     $query .= ' AND b.`id` IS NULL';
     if ($categoryIds) {
         if (count($categoryIds) == 1) {
             $categoryIds = array_shift($categoryIds);
             $query .= ' AND a.`category_id` = ' . $db->Quote($categoryIds);
         } else {
             $query .= ' AND a.`category_id` IN (' . implode(',', $categoryIds) . ')';
         }
     }
     if ($excludeFeatured) {
         $query .= ' AND a.`featured`=' . $db->Quote('0');
     }
     if (!EDC::isSiteAdmin() && !EDC::isModerator()) {
         $query .= ' AND a.`private`=' . $db->Quote(0);
     }
     $db->setQuery($query);
     return $db->loadResult();
 }
Beispiel #2
0
 public function display($tpl = null)
 {
     // Initialise variables
     $doc = JFactory::getDocument();
     $my = JFactory::getUser();
     $config = DiscussHelper::getConfig();
     $app = JFactory::getApplication();
     $registry = DiscussHelper::getRegistry();
     $categoryId = JRequest::getInt('category_id', 0);
     // Perform redirection if there is a category_id in the index view.
     if (!empty($categoryId)) {
         $app->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=categories&layout=listings&category_id=' . $categoryId, false));
         $app->close();
     }
     // Try to detect if there's any category id being set in the menu parameter.
     $activeMenu = $app->getMenu()->getActive();
     if ($activeMenu && !$categoryId) {
         // Load menu params to the registry.
         $registry->loadString($activeMenu->params);
         if ($registry->get('category_id')) {
             $categoryId = $registry->get('category_id');
         }
     }
     // Get the current logged in user's access.
     $acl = DiscussHelper::getHelper('ACL');
     // Todo: Perhaps we should fix the confused naming of filter and sort to type and sort
     $filter = JRequest::getString('filter', $registry->get('filter'));
     $sort = JRequest::getString('sort', $registry->get('sort'));
     // Get the pagination limit
     $limit = $registry->get('limit');
     $limit = $limit == '-2' ? DiscussHelper::getListLimit() : $limit;
     $limit = $limit == '-1' ? DiscussHelper::getJConfig()->get('list_limit') : $limit;
     // Add view to this page.
     $this->logView();
     // set page title.
     DiscussHelper::setPageTitle();
     // Set the meta of the page.
     DiscussHelper::setMeta();
     // Add rss feed into headers
     DiscussHelper::getHelper('Feeds')->addHeaders('index.php?option=com_easydiscuss&view=index');
     // Get list of categories on the site.
     $catModel = $this->getModel('Categories');
     // Pagination is by default disabled.
     $pagination = false;
     // Get the model.
     $postModel = DiscussHelper::getModel('Posts');
     // Get a list of accessible categories
     $cats = $this->getAccessibleCategories($categoryId);
     // Get featured posts from this particular category.
     $featured = array();
     if ($config->get('layout_featuredpost_frontpage')) {
         $options = array('pagination' => false, 'category' => $cats, 'sort' => $sort, 'filter' => $filter, 'limit' => $config->get('layout_featuredpost_limit', $limit), 'featured' => true);
         $featured = $postModel->getDiscussions($options);
         if (is_null($featured)) {
             $featured = array();
         }
     }
     // Get normal discussion posts.
     $options = array('sort' => $sort, 'category' => $cats, 'filter' => $filter, 'limit' => $limit, 'featured' => false);
     $posts = $postModel->getDiscussions($options);
     if (is_null($posts)) {
         $posts = array();
     }
     $authorIds = array();
     $topicIds = array();
     $tmpPostsArr = array_merge($featured, $posts);
     if (count($tmpPostsArr) > 0) {
         foreach ($tmpPostsArr as $tmpArr) {
             $authorIds[] = $tmpArr->user_id;
             $topicIds[] = $tmpArr->id;
         }
     }
     $pagination = $postModel->getPagination(0, 'latest', '', $cats, false);
     $postLoader = EDC::getTable('Posts');
     $postLoader->loadBatch($topicIds);
     $postTagsModel = EDC::getModel('PostsTags');
     $postTagsModel->setPostTagsBatch($topicIds);
     $model = EDC::getModel('Posts');
     $lastReplyUser = $model->setLastReplyBatch($topicIds);
     // Reduce SQL queries by pre-loading all author object.
     $authorIds = array_merge($lastReplyUser, $authorIds);
     $authorIds = array_unique($authorIds);
     // Initialize the list of user's so we run lesser sql queries.
     $profile = EDC::getTable('Profile');
     $profile->init($authorIds);
     // Format featured entries.
     $featured = EDC::formatPost($featured, false, true);
     // Format normal entries
     $posts = EDC::formatPost($posts, false, true);
     // Get unread count
     $unreadCount = $model->getUnreadCount($cats, false);
     // Get unresolved count
     // Change the "all" to TRUE or FALSE to include/exclude featured post count
     $unresolvedCount = $model->getUnresolvedCount('', $cats, '', 'all');
     // Get resolved count
     $resolvedCount = $model->getTotalResolved();
     // Get unanswered count
     $unansweredCount = EDC::getUnansweredCount($cats, true);
     // Get assigned post count that isn't answered yet.
     $assignedCount = 0;
     if (EDC::isSiteAdmin() || EDC::isModerator()) {
         $assignedModel = EDC::getModel('Assigned');
         $assignedCount = $assignedModel->getTotalUnresolved();
     }
     $activeFilter = $config->get('layout_frontpage_sorting');
     // Let's render the layout now.
     $theme = new DiscussThemes();
     $theme->set('assignedCount', $assignedCount);
     $theme->set('activeFilter', $activeFilter);
     $theme->set('activeSort', $sort);
     $theme->set('categories', $categoryId);
     $theme->set('unreadCount', $unreadCount);
     $theme->set('unansweredCount', $unansweredCount);
     $theme->set('resolvedCount', $resolvedCount);
     $theme->set('unresolvedCount', $unresolvedCount);
     $theme->set('posts', $posts);
     $theme->set('featured', $featured);
     $theme->set('pagination', $pagination);
     echo $theme->fetch('frontpage.index.php');
 }
Beispiel #3
0
 /**
  * Displays al ist of moderators on the site.
  *
  * @since   3.2
  * @access  public
  * @param   string
  * @return
  */
 public function getModerators()
 {
     $ajax = DiscussHelper::getHelper('Ajax');
     if (!EDC::isSiteAdmin() && !EDC::isModerator()) {
         return;
     }
     $postId = JRequest::getString('id');
     $categoryId = JRequest::getString('category_id');
     $moderators = DiscussHelper::getHelper('Moderator')->getModeratorsDropdown($categoryId);
     $html = '';
     if (!empty($moderators)) {
         $theme = new DiscussThemes();
         $theme->set('moderators', $moderators);
         $theme->set('postId', $postId);
         $html = $theme->fetch('post.assignment.item.php');
     } else {
         $html = '<li class="pa-10">' . JText::_('COM_EASYDISCUSS_NO_MODERATOR_FOUND') . '</li>';
     }
     $ajax->success($html);
 }
Beispiel #4
0
 public function getUnreadCount($category = 0, $excludeFeatured = false)
 {
     $db = DiscussHelper::getDBO();
     $my = JFactory::getUser();
     $excludeCats = DiscussHelper::getPrivateCategories();
     if (!is_array($category)) {
         $category = array($category);
     }
     $catModel = DiscussHelper::getModel('Categories');
     $childs = array();
     foreach ($category as $categoryId) {
         $data = $catModel->getChildIds($categoryId);
         if ($data) {
             foreach ($data as $childCategory) {
                 $childs[] = $childCategory;
             }
         }
         $childs[] = $categoryId;
     }
     if (empty($category)) {
         $categoryIds = false;
     } else {
         $categoryIds = array_diff($childs, $excludeCats);
         if (empty($categoryIds)) {
             return '0';
         }
     }
     $profile = DiscussHelper::getTable('Profile');
     $profile->load($my->id);
     $readPosts = $profile->posts_read;
     $extraSQL = '';
     if ($readPosts) {
         $readPosts = unserialize($readPosts);
         if (count($readPosts) > 1) {
             $extraSQL = implode(',', $readPosts);
             $extraSQL = ' AND `id` NOT IN (' . $extraSQL . ')';
         } else {
             $extraSQL = ' AND `id` != ' . $db->Quote($readPosts[0]);
         }
     }
     $query = 'SELECT COUNT(1) FROM `#__discuss_posts`';
     $query .= ' WHERE `published` = ' . $db->Quote('1');
     $query .= ' AND `parent_id` = ' . $db->Quote('0');
     if ($categoryIds && !(count($categoryIds) == 1 && empty($categoryIds[0]))) {
         if (count($categoryIds) == 1) {
             $query .= ' AND `category_id` = ' . $db->Quote($categoryIds[0]);
         } else {
             $query .= ' AND `category_id` IN (' . implode(',', $categoryIds) . ')';
         }
     }
     $query .= ' AND `answered` = ' . $db->Quote('0');
     if ($excludeFeatured) {
         $query .= ' AND `featured` = ' . $db->Quote('0');
     }
     if (!EDC::isSiteAdmin() && !EDC::isModerator()) {
         $query .= ' AND `private`=' . $db->Quote(0);
     }
     $query .= ' AND `legacy` = ' . $db->Quote('0');
     $query .= $extraSQL;
     $db->setQuery($query);
     $result = $db->loadResult();
     return empty($result) ? '0' : $result;
 }
		<li class="filterItem<?php 
    echo $activeFilter == 'mine' ? ' active' : '';
    ?>
" data-filter-tab data-filter-type="mine">
			<a class="mineFilter" href="javascript:void(0);">
				<?php 
    echo JText::_('COM_EASYDISCUSS_MY_POSTS');
    ?>
			</a>
		</li>
		<?php 
}
?>

		<?php 
if (EDC::isSiteAdmin() || EDC::isModerator()) {
    ?>
		<li class="filterItem<?php 
    echo $activeFilter == 'assigned' ? ' active' : '';
    ?>
" data-filter-tab data-filter-type="assigned">
			<a class="mineFilter" href="javascript:void(0);">
				<?php 
    echo JText::_('COM_EASYDISCUSS_ASSIGNED_POSTS');
    ?>
				<span class="label label-important label-notification"><?php 
    echo $assignedCount;
    ?>
</span>
			</a>
		</li>