X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=gosa-core%2Finclude%2Fclass_multi_plug.inc;h=af39e67d72956abc368808cdf6179ba01236735d;hb=f43c362c3ff296dd9270bd48f2c7feecf34b7375;hp=b74f963dc6fc787fba60ab9f2edc0e653fe350d0;hpb=894aa86d1d4d57416d43052ea7b781ff680f03c9;p=gosa.git diff --git a/gosa-core/include/class_multi_plug.inc b/gosa-core/include/class_multi_plug.inc index b74f963dc..af39e67d7 100644 --- a/gosa-core/include/class_multi_plug.inc +++ b/gosa-core/include/class_multi_plug.inc @@ -1,21 +1,23 @@ tab object for dn n + +Other functions implemented: +============================ + +CLASS tab + - multiple_support_available() Check if there is at least one plugin with + enabled multiple edit support + - enable_multiple_support() Enable multiple edit, for this tab. + +CLASS plugin + - enable_multiple_support() Enable multiple support for this plugin. + - init_multiple_support() Init summy object, to preset some values. + - multiple_execute() Display dummy object ui. + - multiple_save_object() Get posted values in multiple edit mode. + - multiple_check() Check values specified in dummy object. + - get_multi_edit_values() Get values changed from dummy object. + - set_multi_edit_values() Set values collected with get_multi_edit_values. + to all objects currently edited. + + +Process: +======== + +multi_plug::multi_plug() + |->o_tab = new tab() #Initialize ui handle + | + |->handles + | |->handles[] = new tab() #Initialize objects we want to edit at once + | + |->o_tab->enable_multiple_support() #Enable multiple support for ui handle + |->detect_multiple_used_attributes() #Update ui handle with some default values + |->handles[] + |->by_object->get_multi_init_values() #Get attributes from all handles + |->o_tab + |->by_object->init_multiple_support() #Assign values to ui handle + | + |->execute() #Display ui + | |->o_tab->execute() + |->by_object->multiple_execute() + | + |->check() #Check given values + |->o_tab->check() + |->by_object->multiple_check() + | + |->save_object() #Save posts + |->o_tab->save_object() + |->by_object->multiple_save_object() + | + |->save() #Save collected values + |->populate_values() #Populate values to all handles + |->o_tab->get_multi_edit_values() #Get values to populate + |->handles->set_multi_edit_values() #Set values + |->handles->save() #Save handles + + + + Using this class: ================= Simple Example: @@ -74,6 +133,8 @@ class multi_plug public $config = NULL; private $s_class= ""; public $current = ""; + public $by_object = array(); + public $by_name = array(); /*! \brief Creates a multi_plug object @param object $config GOsa Configuration object @@ -95,8 +156,11 @@ class multi_plug /* Initialize collector object * Used to display the ui and to collect the user input. */ - $this->o_tab = new $class($config,$tab,"new",$acl_category); + $this->o_tab = new $class($config,$tab,"new",$acl_category, TRUE, TRUE); $this->o_tab->set_acl_base($acl_base); + $this->by_object = &$this->o_tab->by_object; + $this->by_name = &$this->o_tab->by_name; + $this->current = &$this->o_tab->current; /* Check if the specified tab object supports multiple edits */ @@ -109,7 +173,7 @@ class multi_plug /* Initialize the objects we want to edit at once */ foreach($dns as $dn){ - $obj = new $class($config,$tab,$dn,$acl_category); + $obj = new $class($config,$tab,$dn,$acl_category, TRUE, TRUE); $obj->set_acl_base($acl_base); $this->a_handles[] = $obj; } @@ -121,37 +185,101 @@ class multi_plug $this->detect_multiple_used_attributes(); } - - /*! \brief Detect values that are used in all edited objects. - * @returns array All multiple used attributes + + /*! \brief Combine two ldap result arrays. + * @param array $base Base array + * @param array $add Array to add + * @returns array Combination of $base and $add */ - private function detect_multiple_used_attributes() + private function array_combine($base,$add) { - $attrs = array(); - $all = array(); - $first = $this->o_tab->current; - foreach($this->a_handles as $handle){ - if(count($attrs) == 0){ - $attrs = $handle->by_object[$first]->attrs; - }else{ - foreach($attrs as $key => $attr){ - if(!isset($handle->by_object[$first]->attrs[$key]) || !($attr === $handle->by_object[$first]->attrs[$key])){ - unset($attrs[$key]); + + foreach($add as $key => $attr) { + if(!is_numeric($key)){ + + if(!is_array($add[$key])){ + $add[$key] = array('count' => 1,$add[$key]); + } + + if(!isset($base[$key])){ + $base[$key] = $add[$key]; + }else{ + + if(!isset($base[$key]['count'])){ + $base[$key]['count'] = count($base[$key]); + } + + if(!isset($add[$key]['count'])){ + $add[$key]['count'] = count($add[$key]); } - if(!is_numeric($key)){ - if(!isset($all[$key])){ - $all[$key] = $attr; - }elseif(isset($attr['count'])){ - for($i = 0; $i < $attr['count'] ; $i ++){ - $all[$key][] = $attr[$i]; - } - $all[$key] = array_unique($all[$key]); + for($i=0;$i<$add[$key]['count'];$i++){ + if(!in_array($add[$key][$i],$base[$key])){ + $base[$key][] = $add[$key][$i]; + $base[$key]['count']++; } } } } } - foreach($this->o_tab->by_object as $name => $obj){ + return($base); + } + + + /*! \brief Intersect two ldap result arrays/Inner join of two ldap result arrays + * @param array $base Base array + * @param array $minus Array number two + * @returns array Result intersection + */ + private function array_intersect($base,$minus) + { + foreach($base as $key => $entry){ + if(is_numeric($key) || !isset($minus[$key])){ + unset($base[$key]); + }elseif(gettype($base[$key]) != gettype($minus[$key])){ + unset($base[$key]); + }elseif(is_string($base[$key]) && $base[$key]!=$minus[$key]){ + unset($base[$key]); + }elseif(is_array($base[$key])){ + $tmp = array(); + if(!isset($base[$key]['count'])){ + $base[$key]['count'] = count($base[$key]); + } + for($i = 0 ; $i < $base[$key]['count'] ; $i ++){ + if(isset($base[$key][$i]) && in_array($base[$key][$i],$minus[$key])){ + $tmp[] = $base[$key][$i]; + } + } + if(count($tmp)){ + $tmp['count'] = count($tmp); + $base[$key] = $tmp; + }else{ + unset($base[$key]); + } + } + } + return($base); + } + + + /*! \brief Detect values that are used in all edited objects. + */ + private function detect_multiple_used_attributes() + { + foreach($this->o_tab->by_object as $name => $plug){ + + if(empty($name)) continue; + + $attrs = array(); + $all = array(); + foreach($this->a_handles as $hid => $handle){ + $h_attrs = $this->a_handles[$hid]->by_object[$name]->get_multi_init_values(); + if(count($attrs) == 0){ + $attrs = $h_attrs; + }else{ + $attrs = $this->array_intersect($attrs,$h_attrs); + } + $all = $this->array_combine($all,$h_attrs); + } $this->o_tab->by_object[$name]->init_multiple_support($attrs,$all); } } @@ -162,7 +290,8 @@ class multi_plug */ public function execute() { - return($this->o_tab->execute()); + $str = $this->o_tab->execute(); + return($str); } @@ -247,7 +376,6 @@ class multi_plug */ public function check() { - $this->populate_values(); $messages = $this->o_tab->check(); return($messages); } @@ -272,15 +400,12 @@ class multi_plug */ public function populate_values() { - if($this->multiple_available() && is_array($this->a_handles)){ foreach($this->o_tab->by_object as $name => $obj){ $values = $this->o_tab->by_object[$name]->get_multi_edit_values(); foreach($this->a_handles as $i_id => $o_handle){ - foreach($values as $a_name => $a_value){ - $this->a_handles[$i_id]->by_object[$name]->$a_name = $a_value; - } + $this->a_handles[$i_id]->by_object[$name]->set_multi_edit_values($values); } } }