Example #1
0
 /**
  * Get all subcats and put them in an array indexed by parent id
  *
  * @param array $categories
  *
  * @return array
  */
 public function &getSubCats($categories)
 {
     $xoops = Xoops::getInstance();
     $criteria = new CriteriaCompo(new Criteria('parentid', "(" . implode(',', array_keys($categories)) . ")", 'IN'));
     $ret = array();
     if (!PublisherUtils::IsUserAdmin()) {
         $categoriesGranted = $this->publisher->getPermissionHandler()->getGrantedItems('category_read');
         if (count($categoriesGranted) > 0) {
             $criteria->add(new Criteria('categoryid', '(' . implode(',', $categoriesGranted) . ')', 'IN'));
         } else {
             return $ret;
         }
         if ($xoops->isUser()) {
             $criteria->add(new Criteria('moderator', $xoops->user->getVar('uid')), 'OR');
         }
     }
     $criteria->setSort('weight');
     $criteria->setOrder('ASC');
     $subcats = $this->getObjects($criteria, true);
     /* @var $subcat PublisherCategory */
     foreach ($subcats as $subcat) {
         $ret[$subcat->getVar('parentid')][$subcat->getVar('categoryid')] = $subcat;
     }
     return $ret;
 }
Example #2
0
 /**
  * @param int    $limit
  * @param int    $start
  * @param string $status
  * @param  int   $categoryid
  * @param string $sort
  * @param string $order
  * @param string $notNullFields
  * @param bool   $asobject
  * @param null   $otherCriteria
  * @param string $id_key
  *
  * @return array
  */
 public function getItems($limit = 0, $start = 0, $status = '', $categoryid = -1, $sort = 'datesub', $order = 'DESC', $notNullFields = '', $asobject = true, $otherCriteria = null, $id_key = 'none')
 {
     global $publisher_isAdmin;
     if (!$publisher_isAdmin) {
         $criteriaPermissions = new CriteriaCompo();
         // Categories for which user has access
         $categoriesGranted = $this->publisher->getPermissionHandler()->getGrantedItems('category_read');
         if (!empty($categoriesGranted)) {
             $grantedCategories = new Criteria('categoryid', "(" . implode(',', $categoriesGranted) . ")", 'IN');
             $criteriaPermissions->add($grantedCategories, 'AND');
         } else {
             return array();
         }
     }
     if (isset($categoryid) && $categoryid != -1) {
         $criteriaCategory = new criteria('categoryid', $categoryid);
     }
     if (!empty($status) && is_array($status)) {
         $criteriaStatus = new CriteriaCompo();
         foreach ($status as $v) {
             $criteriaStatus->add(new Criteria('status', $v), 'OR');
         }
     } elseif (!empty($status) && $status != -1) {
         $criteriaStatus = new CriteriaCompo();
         $criteriaStatus->add(new Criteria('status', $status), 'OR');
     }
     $criteria = new CriteriaCompo();
     if (!empty($criteriaCategory)) {
         $criteria->add($criteriaCategory);
     }
     if (!empty($criteriaPermissions)) {
         $criteria->add($criteriaPermissions);
     }
     if (!empty($criteriaStatus)) {
         $criteria->add($criteriaStatus);
     }
     if (!empty($otherCriteria)) {
         $criteria->add($otherCriteria);
     }
     $criteria->setLimit($limit);
     $criteria->setStart($start);
     $criteria->setSort($sort);
     $criteria->setOrder($order);
     $ret = $this->getItemObjects($criteria, $id_key, $notNullFields);
     return $ret;
 }