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 778f7274..7c7fba2d 100644 --- a/doc/conf/LSattribute/LSattr_html/LSattr_html_select_list.docbook +++ b/doc/conf/LSattribute/LSattr_html/LSattr_html_select_list.docbook @@ -46,6 +46,7 @@ ) ) ), + 'get_possible_values' => [callable], 'translate_labels' => [booléen], 'sort' => [Booléen], 'sortDirection' => '[ASC|DESC]' @@ -178,6 +179,56 @@ + + get_possible_values + + Paramètre permettant de spécifier un callable qui sera utilisé + pour lister les valeurs possibles de l'attribut. Il recevra en paramètres les informations + suivantes: + + + $options + + Les options HTML de l'attribut. + + + + + $name + + Le nom de l'attribut. + + + + + &$ldapObject + + Une référence à l'objet LSldapObject. + + + + + + La valeur de retour attendue est un tableau associatif des valeurs possibles + de l'attribut avec la valeur que prendra l'attribut en tant que clé et le label + correspondant en tant que valeur. Tout autre retour sera considéré comme un échec + et déclenchera une erreur. + Il est également possible de regrouper des valeurs possibles de l'attribut: pour + cela, le tableau retourné devra lui-même contenir un tableau associatif contenant la + label traduit du groupe sous la clé label et les valeurs possibles + du groupe sous la clé possible_values. + Les valeurs retournées pourront être combinées avec les autres valeurs possibles + configurées de l'attribut. La prise en charge du tri des valeurs possibles est assurée + par la fonction appelante sauf dans le cas des sous-groupes de valeurs possibles. Dans + ce cas, la méthode LSattr_html_select_list :: _sort() pourra être + utilisée pour trier les valeurs du sous-groupe: cette méthode accepte en paramètre une + référence du tableau des valeurs possibles ainsi que les options HTML de l'attribut. + + Si la traduction des labels des valeurs possibles de l'attribut est activées + (voir ci-dessous), celle-ci doit être prise en charge par la fonction configurée. + + + translate_labels diff --git a/src/includes/class/class.LSattr_html_select_list.php b/src/includes/class/class.LSattr_html_select_list.php index 1979033f..d17df156 100644 --- a/src/includes/class/class.LSattr_html_select_list.php +++ b/src/includes/class/class.LSattr_html_select_list.php @@ -84,7 +84,7 @@ class LSattr_html_select_list extends LSattr_html{ /** * Return array of possible values with translated labels (if enabled) * - * @param[in] $options Attribute options (optional) + * @param[in] $options Attribute HTML options (optional) * @param[in] $name Attribute name (optional) * @param[in] &$ldapObject Related LSldapObject (optional) * @@ -93,10 +93,15 @@ class LSattr_html_select_list extends LSattr_html{ * @retval array Associative array with possible values as key and corresponding * translated label as value. */ - public static function _getPossibleValues($options=false,$name=false,&$ldapObject=false) { - $retInfos = array(); - $translate_labels = LSconfig :: get('translate_labels', true, 'bool', $options); - if (isset($options['possible_values']) && is_array($options['possible_values'])) { + public static function _getPossibleValues($options=false, $name=false, &$ldapObject=false) { + // Handle get_possible_values parameter + $retInfos = self :: getCallablePossibleValues($options, $name, $ldapObject); + if (!is_array($retInfos)) + $retInfos = array(); + + // Handle other configured possible values + if (is_array($options) && isset($options['possible_values']) && is_array($options['possible_values'])) { + $translate_labels = LSconfig :: get('translate_labels', true, 'bool', $options); foreach($options['possible_values'] as $val_key => $val_label) { if($val_key==='OTHER_OBJECT') { $objInfos=static :: getLSobjectPossibleValues($val_label,$options,$name); @@ -136,7 +141,7 @@ class LSattr_html_select_list extends LSattr_html{ } } - static :: _sort($retInfos,$options); + static :: _sort($retInfos, $options); return $retInfos; } @@ -163,11 +168,11 @@ class LSattr_html_select_list extends LSattr_html{ * Apply sort feature on possible values if this feature is enabled * * @param[in] &$retInfos array Possible values array reference to sort - * @param[in] $options array|false Attribute options + * @param[in] $options array|false Attribute HTML options * * @retval void **/ - protected static function _sort(&$retInfos, $options) { + public static function _sort(&$retInfos, $options) { if (!isset($options['sort']) || $options['sort']) { if (isset($options['sortDirection']) && $options['sortDirection']=='DESC') { uasort($retInfos,array('LSattr_html_select_list','_sortTwoValuesDesc')); @@ -223,7 +228,7 @@ class LSattr_html_select_list extends LSattr_html{ * Retourne un tableau des valeurs possibles d'un type d'objet * * @param[in] $conf OTHER_OBJECT configuration array - * @param[in] $options array|false Attribute options + * @param[in] $options array|false Attribute HTML options * @param[in] $name Attribute name * * @author Benjamin Renard @@ -294,7 +299,7 @@ class LSattr_html_select_list extends LSattr_html{ * 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] $options array|false Attribute HTML options * @param[in] $name Attribute name * @param[in] $LSldapObject LSldapObject reference * @@ -379,23 +384,81 @@ class LSattr_html_select_list extends LSattr_html{ return $retInfos; } + /** + * Return array of possible values with translated labels (if enabled) + * by using specify callable + * + * @param[in] $options Attribute HTML options + * @param[in] $name Attribute name + * @param[in] &$ldapObject Related LSldapObject + * + * @author Benjamin Renard + * + * @retval array|false Associative array with possible values as key and corresponding + * translated label as value, or false in case of error. + */ + public static function getCallablePossibleValues($options, $name, &$ldapObject) { + // Handle get_possible_values parameter + $get_possible_values = LSconfig :: get('get_possible_values', null, null, $options); + if (!$get_possible_values) + return array(); + + // Check callable + if (!is_callable($get_possible_values)) { + LSerror :: addErrorCode('LSattr_html_select_list_06', $name); + return false; + } + + // Run callable + try { + $retInfos = call_user_func_array( + $get_possible_values, + array($options, $name, $ldapObject) + ); + } + catch (Exception $er) { + self :: log_exception($er, strval($this)." -> _getPossibleValues(): exception occured running ".format_callable($get_possible_values)); + $retInfos = null; + } + + // Check result + if (!is_array($retInfos)) { + LSerror :: addErrorCode( + 'LSattr_html_select_list_07', + array( + 'attr' => $name, + 'callable' => format_callable($get_possible_values) + ) + ); + return false; + } + + return $retInfos; + } + } /* * Error Codes */ LSerror :: defineError('LSattr_html_select_list_01', -___("LSattr_html_select_list : Configuration data are missing to generate the select list of the attribute %{attr}.") +___("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.") +___("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.") +___("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}") +___("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}") +___("LSattr_html_select_list: No component %{component} found in the following attribute %{attr} JSON value : %{value}") +); +LSerror :: defineError('LSattr_html_select_list_06', +___("LSattr_html_select_list: Invalid get_possible_values parameter found in configuration of attribute %{attr}: must be a callable.") +); +LSerror :: defineError('LSattr_html_select_list_07', +___("LSattr_html_select_list: fail to retreive possible values of attribute %{attr} using configured function %{callable}.") ); diff --git a/src/lang/fr_FR.UTF8/LC_MESSAGES/ldapsaisie.mo b/src/lang/fr_FR.UTF8/LC_MESSAGES/ldapsaisie.mo index 54f8a4d5..7df6033a 100644 Binary files a/src/lang/fr_FR.UTF8/LC_MESSAGES/ldapsaisie.mo and b/src/lang/fr_FR.UTF8/LC_MESSAGES/ldapsaisie.mo differ diff --git a/src/lang/fr_FR.UTF8/LC_MESSAGES/ldapsaisie.po b/src/lang/fr_FR.UTF8/LC_MESSAGES/ldapsaisie.po index 89cfbfef..8e816da1 100644 --- a/src/lang/fr_FR.UTF8/LC_MESSAGES/ldapsaisie.po +++ b/src/lang/fr_FR.UTF8/LC_MESSAGES/ldapsaisie.po @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: LdapSaisie\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: \n" -"PO-Revision-Date: 2020-09-21 15:46+0200\n" +"PO-Revision-Date: 2020-09-22 14:32+0200\n" "Last-Translator: Benjamin Renard \n" "Language-Team: LdapSaisie \n" @@ -2083,46 +2083,62 @@ msgstr "Discuter avec cette personne." msgid "%s (Unparsable value)" msgstr "%s (valeur non-analysable)" -#: /home/brenard/dev/ldapsaisie_clean3/src/includes/class/class.LSattr_html_select_list.php:388 +#: /home/brenard/dev/ldapsaisie_clean3/src/includes/class/class.LSattr_html_select_list.php:445 msgid "" -"LSattr_html_select_list : Configuration data are missing to generate the " +"LSattr_html_select_list: Configuration data are missing to generate the " "select list of the attribute %{attr}." 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}." -#: /home/brenard/dev/ldapsaisie_clean3/src/includes/class/class.LSattr_html_select_list.php:391 +#: /home/brenard/dev/ldapsaisie_clean3/src/includes/class/class.LSattr_html_select_list.php:448 msgid "" -"LSattr_html_select_list : Invalid attribute %{attr} reference as " +"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)." -#: /home/brenard/dev/ldapsaisie_clean3/src/includes/class/class.LSattr_html_select_list.php:394 +#: /home/brenard/dev/ldapsaisie_clean3/src/includes/class/class.LSattr_html_select_list.php:451 msgid "" -"LSattr_html_select_list : Attribute %{attr} referenced as OTHER_ATTRIBUTE " +"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." -#: /home/brenard/dev/ldapsaisie_clean3/src/includes/class/class.LSattr_html_select_list.php:397 +#: /home/brenard/dev/ldapsaisie_clean3/src/includes/class/class.LSattr_html_select_list.php:454 msgid "" -"LSattr_html_select_list : Fail to decode the following attribute %{attr} " +"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}" -#: /home/brenard/dev/ldapsaisie_clean3/src/includes/class/class.LSattr_html_select_list.php:400 +#: /home/brenard/dev/ldapsaisie_clean3/src/includes/class/class.LSattr_html_select_list.php:457 msgid "" -"LSattr_html_select_list : No component %{component} found in the following " +"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}" +#: /home/brenard/dev/ldapsaisie_clean3/src/includes/class/class.LSattr_html_select_list.php:460 +msgid "" +"LSattr_html_select_list: Invalid get_possible_values parameter found in " +"configuration of attribute %{attr}: must be a callable." +msgstr "" +"LSattr_html_select_list : Paramètre get_possible_values invalide trouvé dans " +"la configuration de l'attribut %{attr} : cela doit être un callable." + +#: /home/brenard/dev/ldapsaisie_clean3/src/includes/class/class.LSattr_html_select_list.php:463 +msgid "" +"LSattr_html_select_list: fail to retreive possible values of attribute " +"%{attr} using configured function %{callable}." +msgstr "" +"LSattr_html_select_list : Impossible de récupérer les valeurs possibles de " +"l'attribut %{attr} en utilisant la fonction configurée %{callable}." + #: /home/brenard/dev/ldapsaisie_clean3/src/includes/class/class.LSformRule_inarray.php:57 msgid "" "LSformRule_inarray : Possible values has not been configured to validate " diff --git a/src/lang/ldapsaisie.pot b/src/lang/ldapsaisie.pot index f0ab5049..a0c6eafe 100644 --- a/src/lang/ldapsaisie.pot +++ b/src/lang/ldapsaisie.pot @@ -1765,36 +1765,48 @@ msgstr "" msgid "%s (Unparsable value)" msgstr "" -#: /home/brenard/dev/ldapsaisie_clean3/src/includes/class/class.LSattr_html_select_list.php:388 +#: /home/brenard/dev/ldapsaisie_clean3/src/includes/class/class.LSattr_html_select_list.php:445 msgid "" -"LSattr_html_select_list : Configuration data are missing to generate the " +"LSattr_html_select_list: Configuration data are missing to generate the " "select list of the attribute %{attr}." msgstr "" -#: /home/brenard/dev/ldapsaisie_clean3/src/includes/class/class.LSattr_html_select_list.php:391 +#: /home/brenard/dev/ldapsaisie_clean3/src/includes/class/class.LSattr_html_select_list.php:448 msgid "" -"LSattr_html_select_list : Invalid attribute %{attr} reference as " +"LSattr_html_select_list: Invalid attribute %{attr} reference as " "OTHER_ATTRIBUTE possible values." msgstr "" -#: /home/brenard/dev/ldapsaisie_clean3/src/includes/class/class.LSattr_html_select_list.php:394 +#: /home/brenard/dev/ldapsaisie_clean3/src/includes/class/class.LSattr_html_select_list.php:451 msgid "" -"LSattr_html_select_list : Attribute %{attr} referenced as OTHER_ATTRIBUTE " +"LSattr_html_select_list: Attribute %{attr} referenced as OTHER_ATTRIBUTE " "possible values is not a jsonCompositeAttribute." msgstr "" -#: /home/brenard/dev/ldapsaisie_clean3/src/includes/class/class.LSattr_html_select_list.php:397 +#: /home/brenard/dev/ldapsaisie_clean3/src/includes/class/class.LSattr_html_select_list.php:454 msgid "" -"LSattr_html_select_list : Fail to decode the following attribute %{attr} " +"LSattr_html_select_list: Fail to decode the following attribute %{attr} " "value as JSON : %{value}" msgstr "" -#: /home/brenard/dev/ldapsaisie_clean3/src/includes/class/class.LSattr_html_select_list.php:400 +#: /home/brenard/dev/ldapsaisie_clean3/src/includes/class/class.LSattr_html_select_list.php:457 msgid "" -"LSattr_html_select_list : No component %{component} found in the following " +"LSattr_html_select_list: No component %{component} found in the following " "attribute %{attr} JSON value : %{value}" msgstr "" +#: /home/brenard/dev/ldapsaisie_clean3/src/includes/class/class.LSattr_html_select_list.php:460 +msgid "" +"LSattr_html_select_list: Invalid get_possible_values parameter found in " +"configuration of attribute %{attr}: must be a callable." +msgstr "" + +#: /home/brenard/dev/ldapsaisie_clean3/src/includes/class/class.LSattr_html_select_list.php:463 +msgid "" +"LSattr_html_select_list: fail to retreive possible values of attribute " +"%{attr} using configured function %{callable}." +msgstr "" + #: /home/brenard/dev/ldapsaisie_clean3/src/includes/class/class.LSformRule_inarray.php:57 msgid "" "LSformRule_inarray : Possible values has not been configured to validate "