2021-06-11 14:28:08 +02:00
|
|
|
<?php
|
|
|
|
/*******************************************************************************
|
|
|
|
* Copyright (C) 2021 Easter-eggs
|
|
|
|
* https://ldapsaisie.org
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
LSsession :: loadLSclass('LSformElement_supannCompositeAttribute');
|
|
|
|
LSsession :: loadLSaddon('supann');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Element supannRessourceEtat d'un formulaire pour LdapSaisie
|
|
|
|
*
|
|
|
|
* Cette classe définis les éléments supannRessourceEtat des formulaires.
|
|
|
|
* Elle étant la classe basic LSformElement.
|
|
|
|
*
|
|
|
|
* @author Benjamin Renard <brenard@easter-eggs.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
class LSformElement_supannRessourceEtat extends LSformElement_supannCompositeAttribute {
|
|
|
|
|
|
|
|
public function __construct(&$form, $name, $label, $params, &$attr_html){
|
|
|
|
$this -> components = array (
|
|
|
|
'ressource' => array (
|
|
|
|
'label' => _('Resource'),
|
|
|
|
'type' => 'select',
|
2021-07-07 13:45:00 +02:00
|
|
|
'possible_values' => array('' => '-'),
|
2021-06-11 14:28:08 +02:00
|
|
|
'get_possible_values' => 'supannGetRessourcePossibleValues',
|
|
|
|
'required' => true,
|
|
|
|
),
|
|
|
|
'etat' => array (
|
|
|
|
'label' => _('State'),
|
|
|
|
'type' => 'select',
|
2021-07-07 13:45:00 +02:00
|
|
|
'possible_values' => array('' => '-'),
|
2021-06-11 14:28:08 +02:00
|
|
|
'get_possible_values' => 'supannGetRessourceEtatPossibleValues',
|
|
|
|
'required' => true,
|
|
|
|
),
|
|
|
|
'sous_etat' => array (
|
|
|
|
'label' => _('Sub-state'),
|
|
|
|
'type' => 'select',
|
|
|
|
'possible_values' => array('' => '-'),
|
|
|
|
'get_possible_values' => 'supannGetRessourceSousEtatPossibleValues',
|
|
|
|
'required' => false,
|
|
|
|
),
|
|
|
|
);
|
2022-12-31 02:01:17 +01:00
|
|
|
parent :: __construct($form, $name, $label, $params, $attr_html);
|
2021-06-11 14:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse une valeur composite gérer par ce type d'attribut
|
|
|
|
*
|
|
|
|
* @param $value string La valeur à parser
|
|
|
|
* @return array|null La valeur parsée, ou NULL en cas de problème
|
|
|
|
*/
|
|
|
|
public function parseCompositeValue($value) {
|
2021-06-11 16:43:59 +02:00
|
|
|
if (preg_match('/\{(?<ressource>[^\}]+)\}(?<etat>[^:]+)(:(?<sous_etat>.*))?/', $value, $matches)) {
|
2021-06-11 14:28:08 +02:00
|
|
|
$parseValue = array(
|
|
|
|
'ressource' => $matches['ressource'],
|
|
|
|
'etat' => $matches['etat'],
|
|
|
|
);
|
2021-07-07 17:48:45 +02:00
|
|
|
if (isset($matches['sous_etat']) && !is_empty($matches['sous_etat']))
|
2021-07-07 16:20:00 +02:00
|
|
|
$parseValue['sous_etat'] = $matches['sous_etat'];
|
2021-06-11 14:28:08 +02:00
|
|
|
return $parseValue;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Format une valeur composite gérer par ce type d'attribut
|
|
|
|
*
|
|
|
|
* @param $value string La valeur à parser
|
|
|
|
* @return array|null|false La valeur formatée, NULL en cas de valeur vide, ou False en cas de problème
|
|
|
|
*/
|
|
|
|
public function formatCompositeValue($value) {
|
|
|
|
if (is_array($value)) {
|
|
|
|
if (!$value['ressource'] || !$value['etat'])
|
|
|
|
return null;
|
|
|
|
$ret = "{".$value['ressource']."}".$value['etat'];
|
2022-12-31 02:01:17 +01:00
|
|
|
if (isset($value['sous_etat']) && !is_empty($value['sous_etat']))
|
2021-06-11 14:28:08 +02:00
|
|
|
$ret .= ":".$value['sous_etat'];
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|