diff --git a/doc/conf/LSattribute/LSattr_html/LSattr_html.entities.xml b/doc/conf/LSattribute/LSattr_html/LSattr_html.entities.xml index e29c60a3..158a6ac7 100644 --- a/doc/conf/LSattribute/LSattr_html/LSattr_html.entities.xml +++ b/doc/conf/LSattribute/LSattr_html/LSattr_html.entities.xml @@ -20,4 +20,5 @@ +LSattr_html_jsonCompositeAttribute"> LSattr_html_select_list"> diff --git a/doc/conf/LSattribute/LSattr_html/LSattr_html_select_list.docbook b/doc/conf/LSattribute/LSattr_html/LSattr_html_select_list.docbook index ae41e1d3..f75596e5 100644 --- a/doc/conf/LSattribute/LSattr_html/LSattr_html_select_list.docbook +++ b/doc/conf/LSattribute/LSattr_html/LSattr_html_select_list.docbook @@ -22,6 +22,19 @@ 'basedn' => '[Basedn de la recherche]', 'onlyAccessible' => '[Booléen]' ), + 'OTHER_ATTRIBUTE' => '[attr]', + // Or : + 'OTHER_ATTRIBUTE' => array( + '[attr1]' => '[label1]', + '[attr2]' => '[label2]', + [...] + ), + // Or : + 'OTHER_ATTRIBUTE' => array( + 'attr' => [attr], + 'json_component_key' => '[Composant JSON clé]', + 'json_component_label' => '[Composant JSON label]', + ), array ( 'label' => '[LSformat du nom du groupe de valeurs]', 'possible_values' => array ( @@ -128,6 +141,37 @@ + Si la valeur clé est égale à OTHER_ATTRIBTE, une liste + de valeur possible sera composée à l'aide des valeurs d'un (ou plusieurs) autre + attribut de l'objet courant. La valeur associée peut être alors : + + + + soit le nom d'un attribut dont les valeurs seront utilisées comme valeurs + possibles (la valeur affichée est égale à la valeur stockée). + + + + soit un tableau associatif dont les valeurs clés sont les noms des attributs + dont les valeurs seront utilisés comme valeurs possibles et dont les valeurs associés + seront les labels sous lesquels ces valeurs seront regroupées (la valeur + affichée est égale à la valeur stockée). + + + + soit un tableau associatif référençant un attribut sous la clé attr + dont les valeurs seront utilisées comme valeurs possibles. Cet attribut + peut-être du type &LSattr_html_jsonCompositeAttribute;. Il sera alors possible d'utiliser + les valeurs d'un composant en particulier en le référençant à l'aide de la clé + json_component_key. Il est également possible de référencer un autre composant + à l'aide de la clé json_component_label et dont les valeurs seront + utilisées comme valeurs affichées lors de la sélection. À défaut, les valeurs affichées + seront identiques à celles stockées. + + + + + diff --git a/public_html/includes/class/class.LSattr_html_select_list.php b/public_html/includes/class/class.LSattr_html_select_list.php index 396d7f63..a1f564cc 100644 --- a/public_html/includes/class/class.LSattr_html_select_list.php +++ b/public_html/includes/class/class.LSattr_html_select_list.php @@ -88,6 +88,10 @@ class LSattr_html_select_list extends LSattr_html{ $objInfos=self :: getLSobjectPossibleValues($val_label,$options,$name); $retInfos=self :: _array_merge($retInfos,$objInfos); } + elseif($val_key==='OTHER_ATTRIBUTE') { + $attrInfos=self :: getLSattributePossibleValues($val_label, $options, $name, $ldapObject); + $retInfos=self :: _array_merge($retInfos,$attrInfos); + } elseif (is_array($val_label)) { if (!isset($val_label['possible_values']) || !is_array($val_label['possible_values']) || !isset($val_label['label'])) continue; @@ -273,6 +277,86 @@ class LSattr_html_select_list extends LSattr_html{ return $retInfos; } + + /** + * Retourne un tableau des valeurs possibles d'un autre attribut + * + * @param[in] $attr OTHER_ATTRIBUTE configuration value + * @param[in] $options array|false Attribute options + * @param[in] $name Attribute name + * @param[in] $LSldapObject LSldapObject reference + * + * @author Benjamin Renard + * + * @retval array Tableau associatif des valeurs possible de la liste avec en clé + * la valeur des balises option et en valeur ce qui sera affiché. + */ + protected function getLSattributePossibleValues($attr, $options ,$name ,&$ldapObject) { + $retInfos=array(); + if (is_string($attr)) { + if (isset($ldapObject->attrs[$attr]) && $ldapObject->attrs[$attr] instanceof LSattribute) { + $attr_values = $ldapObject->attrs[$attr]->getValue(); + if (!is_array($attr_values)) + $attr_values = array($attr_values); + foreach($attr_values as $attr_value) + $retInfos[$attr_value] = __($attr_value); + } + else + LSerror :: addErrorCode('LSattr_html_select_list_02',$attr); + } + elseif (is_array($attr)) { + if (isset($attr['attr'])) { + if (isset($ldapObject->attrs[$attr['attr']]) && $ldapObject->attrs[$attr['attr']] instanceof LSattribute) { + if (isset($attr['json_component_key'])) { + if (get_class($ldapObject->attrs[$attr['attr']]->html) == 'LSattr_html_jsonCompositeAttribute') { + $attr_values = $ldapObject->attrs[$attr['attr']]->getValue(); + if (!is_array($attr_values)) + $attr_values = array($attr_values); + foreach($attr_values as $attr_value) { + $value_data = @json_decode($attr_value, true); + if (!isset($value_data[$attr['json_component_key']])) { + LSerror :: addErrorCode('LSattr_html_select_list_05', array('attr' => $attr['attr'], 'value' => $attr_value, 'component' => $attr['json_component_key'])); + return $retInfos; + } + $key = $value_data[$attr['json_component_key']]; + + if (isset($attr['json_component_label'])) { + if (!isset($value_data[$attr['json_component_label']])) { + LSerror :: addErrorCode('LSattr_html_select_list_05', array('attr' => $attr['attr'], 'value' => $attr_value, 'component' => $attr['json_component_label'])); + return $retInfos; + } + $label = $value_data[$attr['json_component_label']]; + } + else + $label = $key; + + $retInfos[$key] = $label; + } + } + else + LSerror :: addErrorCode('LSattr_html_select_list_03',$attr['attr']); + } + else + $retInfos = self :: getLSattributePossibleValues($attr['attr'], $options ,$name ,$ldapObject); + } + else + LSerror :: addErrorCode('LSattr_html_select_list_02',$attr['attr']); + } + else { + foreach($attr as $sub_attr => $sub_label) { + $subRetInfos = self :: getLSattributePossibleValues($sub_attr, $options ,$name ,$ldapObject); + self :: _sort($subRetInfos,$options); + $retInfos[] = array ( + 'label' => $sub_label, + 'possible_values' => $subRetInfos + ); + } + } + } + self :: _sort($retInfos,$options); + return $retInfos; + } + } /* @@ -281,3 +365,15 @@ class LSattr_html_select_list extends LSattr_html{ LSerror :: defineError('LSattr_html_select_list_01', _("LSattr_html_select_list : Configuration data are missing to generate the select list of the attribute %{attr}.") ); +LSerror :: defineError('LSattr_html_select_list_02', +_("LSattr_html_select_list : Invalid attribute %{attr} reference as OTHER_ATTRIBUTE possible values.") +); +LSerror :: defineError('LSattr_html_select_list_03', +_("LSattr_html_select_list : Attribute %{attr} referenced as OTHER_ATTRIBUTE possible values is not a jsonCompositeAttribute.") +); +LSerror :: defineError('LSattr_html_select_list_04', +_("LSattr_html_select_list : Fail to decode the following attribute %{attr} value as JSON : %{value}") +); +LSerror :: defineError('LSattr_html_select_list_05', +_("LSattr_html_select_list : No component %{component} found in the following attribute %{attr} JSON value : %{value}") +); diff --git a/public_html/lang/fr_FR.UTF8/LC_MESSAGES/ldapsaisie.mo b/public_html/lang/fr_FR.UTF8/LC_MESSAGES/ldapsaisie.mo index f7cd32a6..f079e6c3 100644 Binary files a/public_html/lang/fr_FR.UTF8/LC_MESSAGES/ldapsaisie.mo and b/public_html/lang/fr_FR.UTF8/LC_MESSAGES/ldapsaisie.mo differ diff --git a/public_html/lang/fr_FR.UTF8/LC_MESSAGES/ldapsaisie.po b/public_html/lang/fr_FR.UTF8/LC_MESSAGES/ldapsaisie.po index d630b51d..5bfc280b 100644 --- a/public_html/lang/fr_FR.UTF8/LC_MESSAGES/ldapsaisie.po +++ b/public_html/lang/fr_FR.UTF8/LC_MESSAGES/ldapsaisie.po @@ -7,8 +7,8 @@ msgid "" msgstr "" "Project-Id-Version: LdapSaisie\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-04-26 11:34+0200\n" -"PO-Revision-Date: 2018-04-26 11:35+0200\n" +"POT-Creation-Date: 2018-04-26 11:40+0200\n" +"PO-Revision-Date: 2018-04-26 11:44+0200\n" "Last-Translator: Benjamin Renard \n" "Language-Team: LdapSaisie \n" @@ -1609,7 +1609,7 @@ msgstr "Cliquer pour supprimer cette photo." msgid "Chat with this person." msgstr "Discuter avec cette personne." -#: includes/class/class.LSattr_html_select_list.php:282 +#: includes/class/class.LSattr_html_select_list.php:366 msgid "" "LSattr_html_select_list : Configuration data are missing to generate the " "select list of the attribute %{attr}." @@ -1617,6 +1617,38 @@ msgstr "" "LSattr_html_select_list : Des données de configuration sont manquantes pour " "générer la liste de sélection de l'attribut %{attr}." +#: includes/class/class.LSattr_html_select_list.php:369 +msgid "" +"LSattr_html_select_list : Invalid attribute %{attr} reference as " +"OTHER_ATTRIBUTE possible values." +msgstr "" +"LSattr_html_select_list : Référence invalide à l'attribut %{attr} comme " +"valeurs possibles (OTHER_ATTRIBUTE)." + +#: includes/class/class.LSattr_html_select_list.php:372 +msgid "" +"LSattr_html_select_list : Attribute %{attr} referenced as OTHER_ATTRIBUTE " +"possible values is not a jsonCompositeAttribute." +msgstr "" +"LSattr_html_select_list : L'attribute %{attr} référencé comme valeurs " +"possibles (OTHER_ATTRIBUTE) n'est pas du type jsonCompositeAttribute." + +#: includes/class/class.LSattr_html_select_list.php:375 +msgid "" +"LSattr_html_select_list : Fail to decode the following attribute %{attr} " +"value as JSON : %{value}" +msgstr "" +"LSattr_html_select_list : Impossible de décodé la valeur JSON suivante de " +"l'attribut %{attr} : %{value}" + +#: includes/class/class.LSattr_html_select_list.php:378 +msgid "" +"LSattr_html_select_list : No component %{component} found in the following " +"attribute %{attr} JSON value : %{value}" +msgstr "" +"LSattr_html_select_list : Le composant %{component} n'a pas été trouvé dans " +"la valeur JSON de l'attribut %{attr} : %{value}" + #: includes/class/class.LSformRule_inarray.php:56 msgid "" "LSformRule_inarray : Possible values has not been configured to validate " diff --git a/public_html/lang/ldapsaisie.pot b/public_html/lang/ldapsaisie.pot index 6fa5ff61..31569c0c 100644 --- a/public_html/lang/ldapsaisie.pot +++ b/public_html/lang/ldapsaisie.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-04-26 11:33+0200\n" +"POT-Creation-Date: 2018-04-26 11:39+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -1385,12 +1385,36 @@ msgstr "" msgid "Chat with this person." msgstr "" -#: includes/class/class.LSattr_html_select_list.php:282 +#: includes/class/class.LSattr_html_select_list.php:366 msgid "" "LSattr_html_select_list : Configuration data are missing to generate the " "select list of the attribute %{attr}." msgstr "" +#: includes/class/class.LSattr_html_select_list.php:369 +msgid "" +"LSattr_html_select_list : Invalid attribute %{attr} reference as " +"OTHER_ATTRIBUTE possible values." +msgstr "" + +#: includes/class/class.LSattr_html_select_list.php:372 +msgid "" +"LSattr_html_select_list : Attribute %{attr} referenced as OTHER_ATTRIBUTE " +"possible values is not a jsonCompositeAttribute." +msgstr "" + +#: includes/class/class.LSattr_html_select_list.php:375 +msgid "" +"LSattr_html_select_list : Fail to decode the following attribute %{attr} " +"value as JSON : %{value}" +msgstr "" + +#: includes/class/class.LSattr_html_select_list.php:378 +msgid "" +"LSattr_html_select_list : No component %{component} found in the following " +"attribute %{attr} JSON value : %{value}" +msgstr "" + #: includes/class/class.LSformRule_inarray.php:56 msgid "" "LSformRule_inarray : Possible values has not been configured to validate "