/** * Return in a array all the authorised categories * * @param string $mode * @return Array */ static public function getAuthorisedCategories($mode){ //If the static variable is already set, we directly return it if (self::$listcategories == null) { $user = JFactory::getUser(); $userGroups = array(); //If the user is a guest, we authorise the public group //else we return the authorised group of the user if($user->guest) $userGroups[] = 1; else $userGroups = JHTMLAdsmanagerUserGroups::getUserGroup($user->id); $authorisedCategories = array(); $modelCategories = new AdsmanagerModelCategory(); $categories = $modelCategories->getCategories(false); foreach($categories as $category){ $labelUsergroups = 'usergroups'.$mode; $catUserGroups = $category->$labelUsergroups; $catUserGroupsArray = explode(',', $catUserGroups); //We load the usergroups authorised by the category //If there is no usergroups saved, we authorised the category if($catUserGroups != ''){ //We compare the authorised usergroups of the two array //And save in a array the matching value. foreach($userGroups as $userGroup){ if(array_search($userGroup, $catUserGroupsArray) !== false){ if(array_search($category->id, $authorisedCategories) === false) $authorisedCategories[] = $category->id; } } } else { if(array_search($category->id, $authorisedCategories) === false) $authorisedCategories[] = $category->id; } } self::$listcategories = $authorisedCategories; } return self::$listcategories; }
$displaynumads = $params->def('displaynumads', 1); $catmodel = new AdsmanagerModelCategory(); $rootid = (int) $params->def('rootid', 0); $cats = $catmodel->getCatTree(true, true, $nbcontents, "read", $rootid); $displayhome = $params->def('displayhome', 1); $displaywritead = $params->def('displaywritead', 1); $displayprofile = $params->def('displayprofile', 1); $displaymyads = $params->def('displaymyads', 1); $displayrules = $params->def('displayrules', 1); $displayallads = $params->def('displayallads', 1); $displaycategories = $params->def('displaycategories', 1); $displayfavorites = $params->def('displayfavorites', 1); $displayseparators = $params->def('displayseparators', 1); $moduleclass_sfx = htmlspecialchars($params->get('moduleclass_sfx')); if ($displaycategories == 1) { $cc = $catmodel->getCategories(true, "read", $rootid); $orderlist = array(); // first pass - collect children foreach ($cc as $v) { $orderlist[$v->id] = $v; } $current_list[] = $catid; if ($catid != -1) { $current = $catid; while (isset($orderlist[$current]) && $orderlist[$current]->parent != 0) { $current_list[] = $orderlist[$current]->parent; $current = $orderlist[$current]->parent; } } } $link_show_profile = TLink::getProfileLink();