Improve and translate code comments

This commit is contained in:
Benjamin Renard 2017-05-04 17:27:52 +02:00
parent 9815fb147f
commit 8fa9221a6e
2 changed files with 61 additions and 47 deletions

View file

@ -28,5 +28,5 @@
class LSattr_html_jsonCompositeAttribute extends LSattr_html { class LSattr_html_jsonCompositeAttribute extends LSattr_html {
var $LSformElement_type = 'jsonCompositeAttribute'; var $LSformElement_type = 'jsonCompositeAttribute';
} }

View file

@ -23,10 +23,9 @@
LSsession :: loadLSclass('LSformElement'); LSsession :: loadLSclass('LSformElement');
/** /**
* Element jsonCompositeAttribute d'un formulaire pour LdapSaisie * Element jsonCompositeAttribute for LSform
* *
* Cette classe permet de gérer les attributs composite encodé en JSON. * This classe permit to handle compostie attributes encoded with JSON.
* Elle étant la classe basic LSformElement.
* *
* @author Benjamin Renard <brenard@easter-eggs.com> * @author Benjamin Renard <brenard@easter-eggs.com>
*/ */
@ -42,18 +41,19 @@ class LSformElement_jsonCompositeAttribute extends LSformElement {
$this -> components = $this -> params['html_options']['components']; $this -> components = $this -> params['html_options']['components'];
} }
} }
/* /*
* Composants des valeurs composites : * Value components :
* *
* Format : * Format :
* array ( * array (
* '[clé composant1]' => array ( * '[component1_key]' => array (
* 'label' => '[label composant]', * 'label' => '[component label]',
* 'type' => '[type de composant]', * 'type' => '[component type]',
* 'required' => '[booléen obligatoire]' * 'required' => '[booléen]',
* 'check_data' => array([config LSform_rule])
* ), * ),
* '[clé composant 2]' => array ( * '[component2_key]' => array (
* 'label' => 'label2', * 'label' => 'label2',
* 'type' => 'select_list', * 'type' => 'select_list',
* 'options' => array([config as LSattr_html_select_list html_options]), * 'options' => array([config as LSattr_html_select_list html_options]),
@ -61,16 +61,16 @@ class LSformElement_jsonCompositeAttribute extends LSformElement {
* [...] * [...]
* ) * )
* Types : * Types :
* - 'select_list' => Composant alimenté à partir d'une liste de valeur configurable * - 'select_list' => Component feed by a list of valeur configured like an
* de la même manière qu'un LSattr_html :: select_list. * atribute LSattr_html :: select_list.
* - 'text' => saisie manuelle * - 'text' => manual entry
* *
*/ */
var $components = array(); var $components = array();
/** /**
* Retourne les infos d'affichage de l'élément * Retourne les infos d'affichage de l'élément
* *
* Cette méthode retourne les informations d'affichage de l'élement * Cette méthode retourne les informations d'affichage de l'élement
* *
* @retval array * @retval array
@ -110,44 +110,50 @@ class LSformElement_jsonCompositeAttribute extends LSformElement {
LSsession :: addCssFile('LSformElement_jsonCompositeAttribute.css'); LSsession :: addCssFile('LSformElement_jsonCompositeAttribute.css');
return $return; return $return;
} }
/** /**
* Retourne le code HTML d'un champ vide * Return HTML code of an empty field
* *
* @retval string Code HTML d'un champ vide. * @retval string HTML code of an empty field.
*/ */
function getEmptyField() { function getEmptyField() {
return $this -> fetchTemplate($this -> fieldTemplate,array('components' => $this -> components)); return $this -> fetchTemplate($this -> fieldTemplate,array('components' => $this -> components));
} }
/** /**
* Traduit la valeur d'un composant * Translate componant value
* *
* Retourne un array contenant : * Return an array containing :
* - label : l'étiquette de la valeur ou 'no' sinon * - value : untranslated value
* - value : la valeur brute * - translated : translated value
* - translated : la valeur traduite ou la valeur elle même *
* * @param[in] $c string The component name
* @param[in] $c string Le nom du composant * @param[in] $value string The value
* @param[in] $val string La valeur *
*
* @retval array * @retval array
**/ **/
function translateComponentValue($c,$val) { function translateComponentValue($c,$value) {
$retval = array ( $retval = array (
'translated' => $val, 'translated' => $value,
'value' => $val, 'value' => $value,
); );
if (isset($this -> components[$c])) { if (isset($this -> components[$c])) {
if ($this -> components[$c]['type']=='select_list') { if ($this -> components[$c]['type']=='select_list') {
$retval['translated'] = $this -> getSelectListComponentValueLabel($c,$val); $retval['translated'] = $this -> getSelectListComponentValueLabel($c,$value);
} }
//elseif type == 'text' => aucune transformation //elseif type == 'text' => no transformation
} }
return $retval; return $retval;
} }
/**
* Retreive possible values of an select_list component
*
* @param[in] $c string The component name
*
* @retval array
**/
protected $_cache_getSelectListComponentPossibleValues=array(); protected $_cache_getSelectListComponentPossibleValues=array();
protected function getSelectListComponentPossibleValues($c) { protected function getSelectListComponentPossibleValues($c) {
if (!isset($this -> _cache_getSelectListComponentPossibleValues[$c])) { if (!isset($this -> _cache_getSelectListComponentPossibleValues[$c])) {
@ -157,6 +163,14 @@ class LSformElement_jsonCompositeAttribute extends LSformElement {
return $this -> _cache_getSelectListComponentPossibleValues[$c]; return $this -> _cache_getSelectListComponentPossibleValues[$c];
} }
/**
* Retreive value's label of an select_list component
*
* @param[in] $c string The component name
* @param[in] $value string The value
*
* @retval array
**/
protected function getSelectListComponentValueLabel($c,$value) { protected function getSelectListComponentValueLabel($c,$value) {
if ($this -> getSelectListComponentPossibleValues($c)) { if ($this -> getSelectListComponentPossibleValues($c)) {
foreach ($this -> _cache_getSelectListComponentPossibleValues[$c] as $v => $label) { foreach ($this -> _cache_getSelectListComponentPossibleValues[$c] as $v => $label) {
@ -170,22 +184,22 @@ class LSformElement_jsonCompositeAttribute extends LSformElement {
} }
return; return;
} }
/** /**
* Recupère la valeur de l'élement passée en POST * Retreive LSformElement value from POST data
* *
* Cette méthode vérifie la présence en POST de la valeur de l'élément et la récupère * This method check present of this element's value in POST data and retreive
* pour la mettre dans le tableau passer en paramètre avec en clef le nom de l'élément * it to feed the array passed in paramater.
* *
* @param[] array Pointeur sur le tableau qui recupèrera la valeur. * @param[] array Reference of the array for retreived values
* *
* @retval boolean true si la valeur est présente en POST, false sinon * @retval boolean true if value is in POST data, false instead
*/ */
function getPostData(&$return) { function getPostData(&$return) {
if($this -> isFreeze()) { if($this -> isFreeze()) {
return true; return true;
} }
$count=0; $count=0;
$end=false; $end=false;
$return[$this -> name]=array(); $return[$this -> name]=array();
@ -236,7 +250,7 @@ class LSformElement_jsonCompositeAttribute extends LSformElement {
$end=true; $end=true;
break; break;
} }
} }
if (!$end) { if (!$end) {
if (!empty($unemptyComponents)) { if (!empty($unemptyComponents)) {
@ -250,5 +264,5 @@ class LSformElement_jsonCompositeAttribute extends LSformElement {
} }
return true; return true;
} }
} }