Ejemplo n.º 1
0
 public static function buildNestedCategories($parentId, $parent, $ignorePrivate = false, $isPublishedOnly = false, $showPrivate = true, $selectACLOnly = false)
 {
     $catsModel = self::getModel('Categories');
     // [model:category]
     $catModel = self::getModel('Category');
     $childs = $catsModel->getChildCategories($parentId, $isPublishedOnly, $showPrivate);
     $aclType = $selectACLOnly ? DISCUSS_CATEGORY_ACL_ACTION_SELECT : DISCUSS_CATEGORY_ACL_ACTION_VIEW;
     $accessibleCatsIds = DiscussHelper::getAccessibleCategories($parentId, $aclType);
     if (!empty($childs)) {
         for ($j = 0; $j < count($childs); $j++) {
             $child = $childs[$j];
             $child->count = $catModel->getTotalPostCount($child->id);
             $child->childs = null;
             if (!$ignorePrivate) {
                 if (count($accessibleCatsIds) > 0) {
                     $access = false;
                     foreach ($accessibleCatsIds as $canAccess) {
                         if ($canAccess->id == $child->id) {
                             $access = true;
                         }
                     }
                     if (!$access) {
                         continue;
                     }
                 } else {
                     continue;
                 }
             }
             if (!DiscussHelper::buildNestedCategories($child->id, $child, $ignorePrivate, $isPublishedOnly, $showPrivate, $selectACLOnly)) {
                 $parent->childs[] = $child;
             }
         }
         // for $j
         if (!empty($parent->childs)) {
             // $parent->childs	= array_reverse( $parent->childs );
         }
     } else {
         return false;
     }
 }
Ejemplo n.º 2
0
 function getParentCategories($contentId, $type = 'all', $isPublishedOnly = false, $showPrivateCat = true)
 {
     $db = DiscussHelper::getDBO();
     $my = JFactory::getUser();
     $config = DiscussHelper::getConfig();
     $mainframe = JFactory::getApplication();
     $sortConfig = $config->get('layout_ordering_category', 'latest');
     $query = 'select a.`id`, a.`title`, a.`alias`, a.`private`,a.`default`,a.`container`';
     $query .= ' from `#__discuss_category` as a';
     $query .= ' where a.parent_id = ' . $db->Quote('0');
     if ($type == 'poster') {
         $query .= ' and a.created_by = ' . $db->Quote($contentId);
     } else {
         if ($type == 'category') {
             $query .= ' and a.`id` = ' . $db->Quote($contentId);
         }
     }
     if ($isPublishedOnly) {
         $query .= ' and a.`published` = ' . $db->Quote('1');
     }
     if (!$mainframe->isAdmin()) {
         // we do not need to see the privacy when user accessing category via backend because only admin can access it.
         // in a way, we do not resttict for admin.
         //check categories acl here.
         $catIds = DiscussHelper::getAccessibleCategories('0', DISCUSS_CATEGORY_ACL_ACTION_SELECT);
         if (count($catIds) > 0) {
             $strIds = '';
             foreach ($catIds as $cat) {
                 $strIds = empty($strIds) ? $cat->id : $strIds . ', ' . $cat->id;
             }
             $query .= count($catIds) == 1 ? ' and a.id = ' . $strIds : ' and a.id IN (' . $strIds . ')';
         }
     }
     switch ($sortConfig) {
         case 'alphabet':
             $orderBy = ' ORDER BY a.`title` ';
             break;
         case 'ordering':
             $orderBy = ' ORDER BY a.`lft` ';
             break;
         case 'latest':
             $orderBy = ' ORDER BY a.`created` ';
             break;
         default:
             $orderBy = ' ORDER BY a.`lft` ';
             break;
     }
     $sort = $config->get('layout_sort_category', 'asc');
     $query .= $orderBy . $sort;
     $db->setQuery($query);
     $result = $db->loadObjectList();
     return $result;
 }
Ejemplo n.º 3
0
 private function getAccessibleCategories($categoryId)
 {
     // We only want the user to view stuffs that they can really see.
     if (!is_array($categoryId)) {
         $accessibleCategories = DiscussHelper::getAccessibleCategories();
         $cats = array();
         if ($accessibleCategories) {
             foreach ($accessibleCategories as $category) {
                 $cats[] = $category->id;
             }
         }
     } else {
         $accessibleCategories = DiscussHelper::getAccessibleCategories();
         $cats = array();
         if ($accessibleCategories) {
             foreach ($accessibleCategories as $category) {
                 if (in_array($category->id, $categoryId)) {
                     $cats[] = $category->id;
                 }
             }
         }
     }
     return $cats;
 }
Ejemplo n.º 4
0
 /**
  * Get a list of user badge history
  *
  **/
 public function getPointsHistory($userId)
 {
     $db = DiscussHelper::getDBO();
     // $query	= 'SELECT * FROM ' . $db->nameQuote( '#__discuss_users_history' )
     // 		. ' WHERE ' . $db->nameQuote( 'user_id' ) . '=' . $db->Quote( $userId )
     // 		. ' ORDER BY `created` DESC'
     // 		. ' LIMIT 0,20';
     $my = JFactory::getUser();
     // Obtain the category that I can view
     // I am able to view if my usergroup is added in the category permission "view discussion"
     $viewableCats = array();
     // First get all the accessible parentId
     $parentCats = array();
     $childCats = array();
     $parentCats = DiscussHelper::getAccessibleCategories();
     foreach ($parentCats as $parentCat) {
         $viewableCats[] = $parentCat->id;
     }
     // Second get the child cats that are accessible
     foreach ($parentCats as $parentCat) {
         $childCats = DiscussHelper::getAccessibleCategories($parentCat->id);
         foreach ($childCats as $childCat) {
             $viewableCats[] = $childCat->id;
         }
     }
     $query = 'SELECT a.*, ' . $db->Quote('post') . ' as `type`' . ' FROM ' . $db->nameQuote('#__discuss_users_history') . ' AS a' . ' LEFT JOIN ' . $db->nameQuote('#__discuss_posts') . ' AS b' . ' ON a.' . $db->nameQuote('content_id') . '=' . 'b.' . $db->nameQuote('id') . ' WHERE a.' . $db->nameQuote('user_id') . '=' . $db->Quote($userId) . ' AND a.' . $db->nameQuote('command') . ' IN(' . $db->Quote('easydiscuss.new.discussion') . ',' . $db->Quote('easydiscuss.new.reply') . ',' . $db->Quote('easydiscuss.answer.reply') . ',' . $db->Quote('easydiscuss.new.comment') . ',' . $db->Quote('easydiscuss.like.discussion') . ',' . $db->Quote('easydiscuss.like.reply') . ',' . $db->Quote('easydiscuss.resolved.discussion') . ',' . $db->Quote('easydiscuss.vote.reply') . ',' . $db->Quote('easydiscuss.unvote.reply') . ')' . ' AND b.' . $db->nameQuote('category_id') . ' IN(' . implode($viewableCats, ',') . ')' . ' UNION' . ' SELECT a.*, ' . $db->Quote('profile') . ' as `type`' . ' FROM ' . $db->nameQuote('#__discuss_users_history') . ' AS a' . ' WHERE a.' . $db->nameQuote('user_id') . '=' . $db->Quote($userId) . ' AND a.' . $db->nameQuote('command') . ' IN(' . $db->Quote('easydiscuss.new.avatar') . ' , ' . $db->Quote('easydiscuss.update.profile') . ')' . ' ORDER BY ' . $db->nameQuote('created') . ' DESC' . ' LIMIT 0,20';
     $db->setQuery($query);
     $result = $db->loadObjectList();
     return $result;
 }