From: hickert Date: Wed, 10 Mar 2010 09:58:16 +0000 (+0000) Subject: Added method to return list of configured filters X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=9ccf232946ae6a819b9df4becf08454862466441;p=gosa.git Added method to return list of configured filters git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@16369 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-core/include/class_userFilter.inc b/gosa-core/include/class_userFilter.inc index 91ae157eb..b193210ec 100644 --- a/gosa-core/include/class_userFilter.inc +++ b/gosa-core/include/class_userFilter.inc @@ -28,32 +28,10 @@ class userFilter extends plugin // Load list of filters if(isset($this->attrs['gosaUserDefinedFilter'])){ for($i=0; $i< $this->attrs['gosaUserDefinedFilter']['count']; $i++){ - list($categories, $name, $description, $filter, $flags) = split(";", $this->attrs['gosaUserDefinedFilter'][$i]); - - // Ensure that we no empty category in our category list. - if(empty($categories)){ - $categories = array(); - }else{ - $categories = split(',', $categories); - } - - // Ensure that we no empty entry in out flags list. - if(empty($flags)){ - $flags = array(); - }else{ - $flags = split(',', $flags); + $tmp = userFilter::explodeFilterString($this->attrs['gosaUserDefinedFilter'][$i]); + if(isset($tmp['name'])){ + $this->filters[$tmp['name']]= $tmp; } - - // build up filter entry. - $tmp = array( - 'name' => $name, - 'categories' => $categories, - 'description' => base64_decode($description), - 'filter' => base64_decode($filter), - 'flags' => $flags); - - - $this->filters[$name] = $tmp; } } @@ -68,6 +46,38 @@ class userFilter extends plugin $this->filterWidget->setListData($this->filters, $this->convertFilterList()); } + + /*! \brief Parses a filter string into an array. + */ + static function explodeFilterString($filter) + { + list($categories, $name, $description, $filter, $flags) = split(";", $filter); + + // Ensure that we no empty category in our category list. + if(empty($categories)){ + $categories = array(); + }else{ + $categories = split(',', $categories); + } + + // Ensure that we no empty entry in out flags list. + if(empty($flags)){ + $flags = array(); + }else{ + $flags = split(',', $flags); + } + + // build up filter entry. + $tmp = array( + 'name' => $name, + 'categories' => $categories, + 'description' => base64_decode($description), + 'filter' => base64_decode($filter), + 'flags' => $flags); + + return($tmp); + } + /*! \brief Converts the list of filters ($this->filters) into data which is useable * for the sortableList object ($this->filterWidget). @@ -167,6 +177,37 @@ class userFilter extends plugin } + /*! \brief Returns user defined filter for a given list of categories, + * if no categories were specified all enabled filters will be returned. + */ + static function getFilter($category=array()) + { + global $config; + $ldap=$config->get_ldap_link(); + $ui = get_userinfo(); + $ldap->cd($config->current['BASE']); + $ldap->search("(&(objectClass=gosaProperties)(gosaUserDefinedFilter=*))",array('gosaUserDefinedFilter')); + $filter = array(); + while($attrs = $ldap->fetch()){ + for($i=0; $i < $attrs['gosaUserDefinedFilter']['count']; $i++){ + $tmp = userFilter::explodeFilterString($attrs['gosaUserDefinedFilter'][$i]); + if(!isset($tmp['name'])) continue; + + // The filter is visible if it is shared or if is one of our own creations. + // ... and enabled. + $visible = in_array('enable', $tmp['flags']) && + ($attrs['dn'] == $ui->dn || in_array('share', $tmp['flags'])); + + // Add filter if it matches the category list + if($visible && (count($category) == 0 || array_intersect($category, $tmp['categories']))){ + $filter[$tmp['name']] = $tmp; + } + } + } + return($filter); + } + + /*! \brief Write user-filter modifications back to the ldap. */ function save()