Пример #1
0
 public static function getChildCategories($parentId, $isPublishedOnly = false, $includePrivate = true)
 {
     static $categories = array();
     $sig = $parentId . '-' . (int) $isPublishedOnly . '-' . (int) $includePrivate;
     if (!array_key_exists($sig, $categories)) {
         $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($parentId);
         if ($isPublishedOnly) {
             $query .= ' AND a.`published` = ' . $db->Quote('1');
         }
         if (!$mainframe->isAdmin()) {
             if (!$includePrivate) {
                 //check categories acl here.
                 $catIds = DiscussHelper::getAclCategories(DISCUSS_CATEGORY_ACL_ACTION_VIEW, $my->id, $parentId);
                 if (count($catIds) > 0) {
                     $strIds = '';
                     foreach ($catIds as $cat) {
                         $strIds = empty($strIds) ? $cat->id : $strIds . ', ' . $cat->id;
                     }
                     $query .= ' AND a.id NOT IN (';
                     $query .= $strIds;
                     $query .= ')';
                 }
             }
         }
         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();
         $categories[$sig] = $result;
     }
     return $categories[$sig];
 }
Пример #2
0
 /**
  * Retrieves a list of categories from the site.
  *
  * @since	3.0
  * @access	public
  * @param	int 	If there's a parent id provided, it would load sub categories.
  */
 public function getCategories($options = array())
 {
     // Legacy
     if (!is_array($options)) {
         $parent_id = $options;
         $options = array('parent_id' => $parent_id);
     }
     $default = array('acl_type' => DISCUSS_CATEGORY_ACL_ACTION_VIEW, 'bind_table' => true, 'parent_id' => 0);
     $options += $default;
     $db = DiscussHelper::getDBO();
     $my = JFactory::getUser();
     $query = 'SELECT * FROM ' . $db->nameQuote('#__discuss_category');
     $query .= ' WHERE ' . $db->nameQuote('parent_id') . '=' . $db->Quote($options['parent_id']);
     $query .= ' AND ' . $db->nameQuote('published') . '=' . $db->Quote(1);
     if ($my->id == 0) {
         $query .= ' AND ' . $db->nameQuote('private') . '!=' . $db->Quote('1');
     }
     //check categories acl here.
     $catIds = DiscussHelper::getAclCategories($options['acl_type'], $my->id, $options['parent_id']);
     if (count($catIds) > 0) {
         $strIds = '';
         foreach ($catIds as $cat) {
             $strIds = empty($strIds) ? $cat->id : $strIds . ', ' . $cat->id;
         }
         $query .= ' AND ' . $db->nameQuote('id') . ' NOT IN (' . $strIds . ')';
     }
     $query .= ' ORDER BY ' . $db->nameQuote('lft');
     $db->setQuery($query);
     $rows = $db->loadObjectList();
     if ($options['bind_table']) {
         $total = count($rows);
         $categories = array();
         for ($i = 0; $i < $total; $i++) {
             $ignore['alias'] = true;
             $category = DiscussHelper::getTable('Category');
             $category->bind($rows[$i], $ignore);
             $categories[] = $category;
         }
         return $categories;
     }
     return $rows;
 }