2007-11-15 19:07:24 +01:00
|
|
|
<?php
|
|
|
|
/*******************************************************************************
|
|
|
|
* Copyright (C) 2007 Easter-eggs
|
2021-04-13 18:04:19 +02:00
|
|
|
* https://ldapsaisie.org
|
2007-11-15 19:07:24 +01:00
|
|
|
*
|
|
|
|
* Author: See AUTHORS file in top-level directory.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License version 2
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
2020-05-08 15:49:55 +02:00
|
|
|
LSsession :: loadLSclass('LSlog_staticLoggerClass');
|
2007-11-15 19:07:24 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Element d'un formulaire pour LdapSaisie
|
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* Cette classe gère les éléments des formulaires.
|
2007-11-15 19:07:24 +01:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*/
|
|
|
|
|
2020-05-08 15:49:55 +02:00
|
|
|
class LSformElement extends LSlog_staticLoggerClass {
|
2007-11-15 19:07:24 +01:00
|
|
|
|
2022-12-31 21:15:19 +01:00
|
|
|
/**
|
|
|
|
* The attribute name
|
|
|
|
* @var string
|
|
|
|
*/
|
2023-01-03 12:51:45 +01:00
|
|
|
var $name;
|
2022-12-31 21:15:19 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The attribute label
|
|
|
|
* @see LSformElement::__construct()
|
|
|
|
* @see LSformElement::getLabel()
|
|
|
|
* @var string
|
|
|
|
*/
|
2023-01-03 12:51:45 +01:00
|
|
|
var $label;
|
2022-12-31 21:15:19 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Attribute configuration (LSobjects.<type>.attrs.<attr_name>)
|
|
|
|
* @see LSformElement::getParam()
|
|
|
|
* @var array<string,mixed>
|
|
|
|
*/
|
2023-01-03 12:51:45 +01:00
|
|
|
var $params;
|
2022-12-31 21:15:19 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Values of the element
|
|
|
|
* @var array<mixed>
|
|
|
|
*/
|
2023-01-03 12:51:45 +01:00
|
|
|
var $values = array();
|
2022-12-31 21:15:19 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reference of the related LSform object
|
|
|
|
* @var LSform
|
|
|
|
*/
|
2022-12-31 02:01:17 +01:00
|
|
|
var $form = null;
|
2022-12-31 21:15:19 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Require telltale
|
|
|
|
* @see LSformElement::setRequired()
|
|
|
|
* @see LSformElement::isRequired()
|
|
|
|
* @var bool
|
|
|
|
*/
|
2023-01-03 12:51:45 +01:00
|
|
|
var $_required = false;
|
2022-12-31 21:15:19 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Freeze telltale (=read-only element)
|
|
|
|
* @see LSformElement::freeze()
|
|
|
|
* @see LSformElement::isFreeze()
|
|
|
|
* @var bool
|
|
|
|
*/
|
2023-01-03 12:51:45 +01:00
|
|
|
var $_freeze = false;
|
2022-12-31 21:15:19 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reference to the related LSattr_html object
|
|
|
|
* @var LSattr_html
|
|
|
|
*/
|
2008-02-26 18:40:05 +01:00
|
|
|
var $attr_html;
|
2022-12-31 21:15:19 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The one-value template filename (=for one vaue of the form element)
|
|
|
|
* Note: commonly overwrite in implementated classes
|
|
|
|
* @var string
|
|
|
|
*/
|
2023-01-03 12:51:45 +01:00
|
|
|
var $fieldTemplate = 'LSformElement_field.tpl';
|
2022-12-31 21:15:19 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The template filename (of the form complement element)
|
|
|
|
* Note: may be overwrite in implementated classes
|
|
|
|
* @var string
|
|
|
|
*/
|
2023-01-03 12:51:45 +01:00
|
|
|
var $template = 'LSformElement.tpl';
|
2022-12-31 21:15:19 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Template variables passed to Smarty computing the form element template
|
|
|
|
* Note: this variables are commonly added in implementated classes
|
|
|
|
* @var array<string,mixed>
|
|
|
|
*/
|
2023-01-03 12:51:45 +01:00
|
|
|
var $fetchVariables = array();
|
2007-11-15 19:07:24 +01:00
|
|
|
|
|
|
|
/**
|
2021-03-03 14:34:06 +01:00
|
|
|
* Constructor
|
2007-11-15 19:07:24 +01:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @param LSform &$form The LSform parent object
|
|
|
|
* @param string $name The name of the element
|
2022-12-31 21:15:19 +01:00
|
|
|
* @param string $label The label of the element
|
|
|
|
* @param array $params The parameters of the element
|
|
|
|
* @param LSattr_html &$attr_html The LSattr_html object of the corresponding attribute
|
2007-11-15 19:07:24 +01:00
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return void
|
2020-04-29 15:54:21 +02:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function __construct(&$form, $name, $label, $params, &$attr_html){
|
2007-11-15 19:07:24 +01:00
|
|
|
$this -> name = $name;
|
2008-02-12 18:59:44 +01:00
|
|
|
$this -> label = $label;
|
|
|
|
$this -> params = $params;
|
2015-04-14 15:10:40 +02:00
|
|
|
$this -> form =& $form;
|
|
|
|
$this -> attr_html =& $attr_html;
|
2007-11-15 19:07:24 +01:00
|
|
|
}
|
|
|
|
|
2020-09-08 17:29:10 +02:00
|
|
|
/**
|
|
|
|
* Allow conversion of LSformElement to string
|
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return string The string representation of the LSformElement
|
2020-09-08 17:29:10 +02:00
|
|
|
*/
|
|
|
|
public function __toString() {
|
|
|
|
return strval($this -> form)." -> <".get_class($this)." ".$this -> name.">";
|
|
|
|
}
|
|
|
|
|
2007-11-15 19:07:24 +01:00
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
* Définis la valeur de l'élément
|
2007-11-15 19:07:24 +01:00
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* Cette méthode définis la valeur de l'élément
|
2007-11-15 19:07:24 +01:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @param string|array $data La futur valeur de l'élément
|
2007-11-15 19:07:24 +01:00
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return boolean Retourne True
|
2007-11-15 19:07:24 +01:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function setValue($data) {
|
2020-11-30 19:43:52 +01:00
|
|
|
$this -> values = ensureIsArray($data);
|
2008-02-12 18:59:44 +01:00
|
|
|
return true;
|
2007-11-15 19:07:24 +01:00
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2008-05-14 16:43:23 +02:00
|
|
|
/**
|
2020-04-29 15:54:21 +02:00
|
|
|
* Définis la valeur de l'élément à partir des données
|
2008-05-14 16:43:23 +02:00
|
|
|
* envoyées en POST du formulaire
|
|
|
|
*
|
2020-04-29 15:54:21 +02:00
|
|
|
* Cette méthode définis la valeur de l'élément à partir des données
|
2008-05-14 16:43:23 +02:00
|
|
|
* envoyées en POST du formulaire.
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @param string|array $data La futur valeur de l'élément
|
2008-05-14 16:43:23 +02:00
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return boolean Retourne True
|
2008-05-14 16:43:23 +02:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function setValueFromPostData($data) {
|
2020-11-30 19:43:52 +01:00
|
|
|
$this -> values = ensureIsArray($data);
|
2020-12-01 16:48:07 +01:00
|
|
|
self :: log_trace($this." -> setValueFromPostData(): input data=".varDump($data)." / values=".varDump($this -> values));
|
2008-05-14 16:43:23 +02:00
|
|
|
return true;
|
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
|
2008-07-18 16:02:46 +02:00
|
|
|
/**
|
|
|
|
* Exporte les valeurs de l'élément
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return array Les valeurs de l'élement
|
2008-07-18 16:02:46 +02:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function exportValues(){
|
2008-07-18 16:02:46 +02:00
|
|
|
return $this -> values;
|
|
|
|
}
|
|
|
|
|
2008-02-12 18:59:44 +01:00
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
* Ajoute une valeur à l'élément
|
2007-11-15 19:07:24 +01:00
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* Cette méthode ajoute une valeur à l'élément
|
2007-11-15 19:07:24 +01:00
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @param string|array $data La futur valeur de l'élément
|
2007-11-15 19:07:24 +01:00
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return void
|
2007-11-15 19:07:24 +01:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function addValue($data) {
|
2020-11-30 19:43:52 +01:00
|
|
|
$this -> values = array_merge($this -> values, ensureIsArray($data));
|
2007-11-15 19:07:24 +01:00
|
|
|
}
|
|
|
|
|
2008-02-12 18:59:44 +01:00
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
* Test si l'élément est éditable
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* Cette méthode test si l'élément est éditable
|
2008-02-12 18:59:44 +01:00
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return boolean
|
2008-02-12 18:59:44 +01:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function isFreeze(){
|
2008-02-12 18:59:44 +01:00
|
|
|
return $this -> _freeze;
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2008-05-15 12:56:55 +02:00
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
* Freeze l'élément
|
2007-11-15 19:07:24 +01:00
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* Rend l'élément non-editable
|
2007-11-15 19:07:24 +01:00
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return void
|
2007-11-15 19:07:24 +01:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function freeze() {
|
2008-02-12 18:59:44 +01:00
|
|
|
$this -> _freeze = true;
|
2007-11-15 19:07:24 +01:00
|
|
|
}
|
|
|
|
|
2008-05-15 12:56:55 +02:00
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
* Défini la propriété required de l'élément.
|
2007-11-15 19:07:24 +01:00
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* param boolean $isRequired true si l'élément est requis, false sinon
|
2007-11-15 19:07:24 +01:00
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return void
|
2007-11-15 19:07:24 +01:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function setRequired($isRequired=true) {
|
2008-02-12 18:59:44 +01:00
|
|
|
$this -> _required = $isRequired;
|
|
|
|
}
|
|
|
|
|
2008-05-15 12:56:55 +02:00
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
* Test si l'élément est requis
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* Cette méthode test si l'élément est requis
|
2008-02-12 18:59:44 +01:00
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return boolean
|
2008-02-12 18:59:44 +01:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function isRequired(){
|
2008-02-12 18:59:44 +01:00
|
|
|
return $this -> _required;
|
2007-11-15 19:07:24 +01:00
|
|
|
}
|
|
|
|
|
2008-02-12 18:59:44 +01:00
|
|
|
/**
|
2022-12-31 21:15:19 +01:00
|
|
|
* Return label info of the element:
|
|
|
|
* array(
|
|
|
|
* 'label' => 'The label',
|
|
|
|
* 'required' => true|false,
|
|
|
|
* 'help_info' => 'The help info of the element',
|
|
|
|
* 'help_info_in_view' => true|false,
|
|
|
|
* )
|
|
|
|
*
|
|
|
|
* @return array The label info
|
2008-02-12 18:59:44 +01:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function getLabelInfos() {
|
2008-02-12 18:59:44 +01:00
|
|
|
if ($this -> isRequired()) {
|
|
|
|
$return['required']=true;
|
|
|
|
}
|
|
|
|
$return['label'] = $this -> getLabel();
|
2019-03-11 22:21:25 +01:00
|
|
|
$help_infos = array();
|
|
|
|
if ( $this -> getParam('displayAttrName', $this -> attr_html -> attribute -> ldapObject -> getConfig('displayAttrName', false, 'bool'), 'bool') ) {
|
|
|
|
$help_infos[] = _("Attribute")." : ".$this -> name."\n";
|
2010-11-19 18:41:10 +01:00
|
|
|
}
|
2019-03-11 22:21:25 +01:00
|
|
|
if ($this -> getParam('help_info')) {
|
|
|
|
$help_infos[] = __($this -> getParam('help_info'));
|
2008-09-26 20:03:56 +02:00
|
|
|
}
|
2019-03-11 22:21:25 +01:00
|
|
|
if (!empty($help_infos))
|
|
|
|
$return['help_info'] = implode(' - ', $help_infos);
|
2019-03-29 15:49:03 +01:00
|
|
|
$return['help_info_in_view'] = $this -> getParam('help_info_in_view', false, 'bool');
|
2010-11-19 18:41:10 +01:00
|
|
|
|
2008-02-12 18:59:44 +01:00
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
* Recupère la valeur de l'élement passée en POST
|
2008-02-12 18:59:44 +01:00
|
|
|
*
|
2008-04-25 16:09:27 +02:00
|
|
|
* Cette méthode vérifie la présence en POST de la valeur de l'élément et la récupère
|
|
|
|
* pour la mettre dans le tableau passer en paramètre avec en clef le nom de l'élément
|
2008-02-12 18:59:44 +01:00
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @param array &$return Reference of the array for retrieved values
|
|
|
|
* @param boolean $onlyIfPresent If true and data of this element is not present in POST data,
|
2020-05-08 20:48:13 +02:00
|
|
|
* just ignore it.
|
2008-02-12 18:59:44 +01:00
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return boolean true si la valeur est présente en POST, false sinon
|
2008-02-12 18:59:44 +01:00
|
|
|
*/
|
2020-05-08 20:48:13 +02:00
|
|
|
public function getPostData(&$return, $onlyIfPresent=false) {
|
2008-02-12 18:59:44 +01:00
|
|
|
if($this -> isFreeze()) {
|
|
|
|
return true;
|
|
|
|
}
|
2020-06-30 15:55:21 +02:00
|
|
|
$return[$this -> name] = self :: getData($_POST, $this -> name);
|
|
|
|
if (!is_array($return[$this -> name])) {
|
|
|
|
if ($onlyIfPresent) {
|
|
|
|
self :: log_debug($this -> name.": not in POST data => ignore it");
|
|
|
|
unset($return[$this -> name]);
|
2008-02-12 18:59:44 +01:00
|
|
|
}
|
2020-06-30 15:55:21 +02:00
|
|
|
else {
|
|
|
|
$return[$this -> name] = array();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-08-25 18:02:37 +02:00
|
|
|
* Retrieve the value of the element specified by its name ($name)
|
2020-06-30 15:55:21 +02:00
|
|
|
* from POST data (provided as $post).
|
|
|
|
*
|
2022-12-31 21:15:19 +01:00
|
|
|
* @param array &$post Reference of the array for input POST data
|
2022-12-31 05:52:31 +01:00
|
|
|
* @param string $name POST data element name
|
2020-06-30 15:55:21 +02:00
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return mixed Array of POST data value if present, false otherwise
|
2020-06-30 15:55:21 +02:00
|
|
|
*/
|
|
|
|
protected static function getData(&$post, $name) {
|
|
|
|
if (isset($post[$name])) {
|
2020-11-30 19:43:52 +01:00
|
|
|
$return = array();
|
|
|
|
$post[$name] = ensureIsArray($post[$name]);
|
2020-06-30 15:55:21 +02:00
|
|
|
foreach($post[$name] as $key => $val) {
|
2020-09-11 13:34:42 +02:00
|
|
|
if (!is_empty($val)) {
|
2020-06-30 15:55:21 +02:00
|
|
|
$return[$key] = $val;
|
2008-10-15 12:32:51 +02:00
|
|
|
}
|
2008-02-12 18:59:44 +01:00
|
|
|
}
|
2020-06-30 15:55:21 +02:00
|
|
|
return $return;
|
2008-02-12 18:59:44 +01:00
|
|
|
}
|
2020-06-30 15:55:21 +02:00
|
|
|
return false;
|
2008-02-12 18:59:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-04-25 16:09:27 +02:00
|
|
|
* Retourne le label de l'élement
|
2008-02-12 18:59:44 +01:00
|
|
|
*
|
|
|
|
* Retourne $this -> label, ou $this -> params['label'], ou $this -> name
|
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return string Le label de l'élément
|
2008-02-12 18:59:44 +01:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function getLabel() {
|
2008-02-12 18:59:44 +01:00
|
|
|
if ($this -> label != "") {
|
2009-03-19 18:42:51 +01:00
|
|
|
return __($this -> label);
|
2008-02-12 18:59:44 +01:00
|
|
|
}
|
2019-03-11 22:21:25 +01:00
|
|
|
return __($this -> getParam('label', $this -> name));
|
2008-02-12 18:59:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-10-16 17:35:20 +02:00
|
|
|
* Le champ est-il a valeur multiple
|
2008-02-12 18:59:44 +01:00
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return boolean True si le champ est à valeur multiple, False sinon
|
2008-02-12 18:59:44 +01:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function isMultiple() {
|
2019-03-11 22:21:25 +01:00
|
|
|
return $this -> getParam('multiple', false, 'bool');
|
2008-10-15 19:40:04 +02:00
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2008-10-15 19:40:04 +02:00
|
|
|
/**
|
2021-03-03 14:34:06 +01:00
|
|
|
* Return HTML code of the LSformElement based on its (smarty) template file
|
2008-10-15 19:40:04 +02:00
|
|
|
*
|
2022-12-31 21:15:19 +01:00
|
|
|
* @param string $template The template filename (optional, default: $this -> template)
|
|
|
|
* @param array $variables Array of template variables to assign before template compilation (optional)
|
2020-04-29 15:54:21 +02:00
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return string HTML code of the LSformElement
|
2008-10-15 19:40:04 +02:00
|
|
|
*/
|
2019-03-12 11:42:53 +01:00
|
|
|
public function fetchTemplate($template=NULL,$variables=array()) {
|
2008-10-15 19:40:04 +02:00
|
|
|
if (!$template) {
|
|
|
|
$template = $this -> template;
|
|
|
|
}
|
2009-01-24 18:45:14 +01:00
|
|
|
return LSsession :: fetchTemplate(
|
2008-10-15 19:40:04 +02:00
|
|
|
$template,
|
|
|
|
array_merge_recursive(
|
|
|
|
$variables,
|
2008-10-15 20:29:14 +02:00
|
|
|
$this -> fetchVariables,
|
2008-10-15 19:40:04 +02:00
|
|
|
array(
|
|
|
|
'freeze' => $this -> isFreeze(),
|
|
|
|
'multiple'=> $this -> isMultiple(),
|
|
|
|
'value' => '',
|
|
|
|
'values' => $this -> values,
|
|
|
|
'attr_name' => $this -> name,
|
2019-03-11 22:21:25 +01:00
|
|
|
'noValueTxt' => __($this -> getParam('no_value_label', 'No set value', 'string')),
|
2014-11-20 00:31:08 +01:00
|
|
|
'fieldTemplate' => $this -> fieldTemplate,
|
|
|
|
'fieldType' => get_class($this)
|
2008-10-15 19:40:04 +02:00
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2020-04-29 15:54:21 +02:00
|
|
|
|
2008-10-15 19:40:04 +02:00
|
|
|
/**
|
2020-09-08 18:42:54 +02:00
|
|
|
* Return HTML code of an empty form field
|
2008-10-15 19:40:04 +02:00
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @param integer|null $value_idx The value index (optional, default: null == 0)
|
2020-09-08 18:42:54 +02:00
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return string The HTML code of an empty field
|
2008-10-15 19:40:04 +02:00
|
|
|
*/
|
2020-09-08 18:42:54 +02:00
|
|
|
public function getEmptyField($value_idx=null) {
|
|
|
|
return $this -> fetchTemplate(
|
|
|
|
$this -> fieldTemplate,
|
|
|
|
array(
|
|
|
|
'value_idx' => intval($value_idx),
|
|
|
|
)
|
|
|
|
);
|
2008-10-15 19:40:04 +02:00
|
|
|
}
|
2019-03-11 22:21:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a parameter (or default value)
|
|
|
|
*
|
2022-12-31 21:15:19 +01:00
|
|
|
* @param string $param The configuration parameter
|
|
|
|
* @param mixed $default The default value (default : null)
|
|
|
|
* @param string $cast Cast resulting value in specific type (default : disabled)
|
2019-03-11 22:21:25 +01:00
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return mixed The parameter value or default value if not set
|
2019-03-11 22:21:25 +01:00
|
|
|
**/
|
|
|
|
public function getParam($param, $default=null, $cast=null) {
|
|
|
|
return LSconfig :: get($param, $default, $cast, $this -> params);
|
|
|
|
}
|
2019-03-11 22:42:20 +01:00
|
|
|
|
2020-07-07 12:43:55 +02:00
|
|
|
/**
|
|
|
|
* CLI autocompleter for form element attribute values
|
|
|
|
*
|
2022-12-31 21:15:19 +01:00
|
|
|
* @param array &$opts Array of avalaible autocomplete options
|
|
|
|
* @param string $comp_word The (unquoted) command word to autocomplete
|
|
|
|
* @param string $attr_value The current attribute value in command word to
|
|
|
|
* autocomplete (optional, default: empty string)
|
|
|
|
* @param string $multiple_value_delimiter The multiple value delimiter
|
|
|
|
* (optional, default: "|")
|
|
|
|
* @param string $quote_char The quote character detected
|
|
|
|
* (optional, default: empty string)
|
2020-07-07 12:43:55 +02:00
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return void
|
2020-07-07 12:43:55 +02:00
|
|
|
*/
|
|
|
|
public function autocomplete_attr_values(&$opts, $comp_word, $attr_value="", $multiple_value_delimiter="|", $quote_char='') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* CLI autocompleter helper to split form element attribute values
|
|
|
|
*
|
2022-12-31 21:15:19 +01:00
|
|
|
* @param string $attr_value The current attribute value in command word
|
|
|
|
* to autocomplete
|
|
|
|
* (optional, default: empty string)
|
|
|
|
* @param string $multiple_value_delimiter The multiple value delimiter
|
|
|
|
* (optional, default: "|")
|
|
|
|
* @param array &$attr_values Array that will contain splited attribute
|
|
|
|
* values without last-one
|
|
|
|
* @param string &$last_attr_value Array that will contain the last splited
|
|
|
|
* attribute value
|
2020-07-07 12:43:55 +02:00
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return boolean True on success, False otherwise
|
2020-07-07 12:43:55 +02:00
|
|
|
*/
|
2022-12-31 02:31:21 +01:00
|
|
|
protected function split_autocomplete_attr_values($attr_value, $multiple_value_delimiter, &$attr_values, &$last_attr_value) {
|
2020-07-07 12:43:55 +02:00
|
|
|
$attr_values = explode($multiple_value_delimiter, $attr_value);
|
|
|
|
if (count($attr_values) > 1 && !$this -> getParam('multiple', false, 'bool')) {
|
|
|
|
self :: log_error("The attribute ".$this -> name." is not multivalued.");
|
2023-01-02 01:17:46 +01:00
|
|
|
return false;
|
2020-07-07 12:43:55 +02:00
|
|
|
}
|
|
|
|
self :: log_debug("split_autocomplete_attr_values('$attr_value', '$multiple_value_delimiter'): values = '".implode("', '", $attr_values)."'");
|
|
|
|
$last_attr_value = array_pop($attr_values);
|
|
|
|
self :: log_debug("split_autocomplete_attr_values('$attr_value', '$multiple_value_delimiter'): last value = '$last_attr_value'");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* CLI autocompleter helper to format and add form element attribute value option
|
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @param array &$opts Array of avalaible autocomplete options
|
|
|
|
* @param array &$attr_values Array of splited attribute values without last-one
|
|
|
|
* @param string $value The attribute value to add as option
|
|
|
|
* @param string $multiple_value_delimiter The multiple value delimiter (optional, default: "|")
|
|
|
|
* @param string $quote_char The quote character (optional, default: empty string)
|
2020-07-07 12:43:55 +02:00
|
|
|
*
|
2022-12-31 21:15:19 +01:00
|
|
|
* @return void
|
2020-07-07 12:43:55 +02:00
|
|
|
*/
|
|
|
|
protected function add_autocomplete_attr_value_opts(&$opts, &$attr_values, $value, $multiple_value_delimiter='|', $quote_char='') {
|
|
|
|
if (in_array($value, $attr_values)) {
|
|
|
|
self :: log_debug("LSformElement :: autocomplete_opts(): '$value' already one of selected value, ignore it");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$opt = $this -> name . "=" .implode($multiple_value_delimiter, array_merge($attr_values, array($value)));
|
|
|
|
self :: log_debug("LSformElement :: add_autocomplete_attr_value_opts(): option=$opt");
|
|
|
|
if ($quote_char)
|
|
|
|
$opt = LScli :: quote_word($opt, $quote_char);
|
|
|
|
if (!in_array($opt, $opts))
|
|
|
|
$opts[] = $opt;
|
|
|
|
}
|
|
|
|
|
2021-02-03 14:40:28 +01:00
|
|
|
/**
|
2021-08-25 18:02:37 +02:00
|
|
|
* Retrieve value as return in API response
|
2021-02-03 14:40:28 +01:00
|
|
|
*
|
2022-12-31 21:15:19 +01:00
|
|
|
* @param boolean $details If true, returned values will contain details if this field
|
|
|
|
* type support it (optional, default: false)
|
2021-02-05 12:22:32 +01:00
|
|
|
*
|
2022-12-31 05:52:31 +01:00
|
|
|
* @return mixed API value(s) or null/empty array if no value
|
2021-02-03 14:40:28 +01:00
|
|
|
*/
|
2021-02-05 12:22:32 +01:00
|
|
|
public function getApiValue($details=false) {
|
|
|
|
if (method_exists($this, 'parseValue')) {
|
|
|
|
$values = array();
|
|
|
|
foreach(ensureIsArray($this -> values) as $value) {
|
|
|
|
$parsed_value = $this -> parseValue($value, $details);
|
|
|
|
if ($parsed_value != false)
|
|
|
|
$values[] = $parsed_value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$values = ensureIsArray($this -> values);
|
2021-02-03 14:40:28 +01:00
|
|
|
}
|
2021-02-05 12:22:32 +01:00
|
|
|
if ($this -> isMultiple())
|
|
|
|
return $values;
|
|
|
|
if (!$values)
|
2021-02-03 14:40:28 +01:00
|
|
|
return null;
|
2021-02-05 12:22:32 +01:00
|
|
|
return $values[0];
|
2021-02-03 14:40:28 +01:00
|
|
|
}
|
|
|
|
|
2022-12-31 21:15:19 +01:00
|
|
|
/**
|
|
|
|
* Get display info of the form element
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getDisplay(){
|
|
|
|
$return = $this -> getLabelInfos();
|
|
|
|
$return['html'] = $this -> fetchTemplate();
|
|
|
|
return $return;
|
|
|
|
}
|
2007-11-15 19:07:24 +01:00
|
|
|
}
|