From c2bd58662e588a111d319bd9112b87610a6a4197 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Thu, 19 Mar 2020 11:28:21 +0100 Subject: [PATCH] :sparkles: feat(supann) First WIP of supannCMS support There is a bug with the tagged attribute, it fails to remove tagged values. Also the Source field cannot be set yet. issue #6015 --- supann/contrib/etc/cmsformat | 3 + supann/contrib/etc/cmstype | 11 +++ .../class_SupannCMSAffectationAttribute.inc | 90 ++++++++++++++++++ .../personal/supann/class_TaggedAttribute.inc | 80 ++++++++++++++++ supann/personal/supann/class_supannCMS.inc | 94 +++++++++++++++++++ 5 files changed, 278 insertions(+) create mode 100644 supann/contrib/etc/cmsformat create mode 100644 supann/contrib/etc/cmstype create mode 100644 supann/personal/supann/class_SupannCMSAffectationAttribute.inc create mode 100644 supann/personal/supann/class_TaggedAttribute.inc create mode 100644 supann/personal/supann/class_supannCMS.inc diff --git a/supann/contrib/etc/cmsformat b/supann/contrib/etc/cmsformat new file mode 100644 index 0000000000..f0f303cf66 --- /dev/null +++ b/supann/contrib/etc/cmsformat @@ -0,0 +1,3 @@ +# Formats +# TECHONOLOGY:ENCODING;label +MIFARE:XLSB;Mifare XLSB diff --git a/supann/contrib/etc/cmstype b/supann/contrib/etc/cmstype new file mode 100644 index 0000000000..58cbc40943 --- /dev/null +++ b/supann/contrib/etc/cmstype @@ -0,0 +1,11 @@ +# Nomenclature SupAnn +etudiant;étudiant +personnel;professionnelle +visiteur;visiteur, anonyme +invite;invité, nominative +lecteur;lecteur de bibliothèque +prestataire;prestataire de services +vehicule;véhicule +externe;externe +# Ajouter ici les types locaux étiqueté si besoin +# {ORIGINE}type_local;Type de carte défini localement par l'établissement ORIGINE diff --git a/supann/personal/supann/class_SupannCMSAffectationAttribute.inc b/supann/personal/supann/class_SupannCMSAffectationAttribute.inc new file mode 100644 index 0000000000..95a96343c6 --- /dev/null +++ b/supann/personal/supann/class_SupannCMSAffectationAttribute.inc @@ -0,0 +1,90 @@ +attributes[3]->getValue() !== TRUE) { + /* Card is not valid */ + return; + } + foreach ($this->attributes as &$attribute) { + $shortname = preg_replace('/^([^_]+)_.*$/', '\\1', $attribute->getLdapName()); + if ($shortname == 'none') { + continue; + } + $value = $attribute->getValue(); + if (!isset($values[$shortname])) { + $values[$shortname] = []; + } + if ($value == '') { + continue; + } + $values[$shortname][$value] = $value; + } + unset($attribute); + $format = $this->attributes[1]->getValue(); + $id = $this->attributes[2]->getValue(); + $supannCMSIdEtiquette = '{'.$format.'}'.$id; + $supannCMSId = 'x-'.strtolower(str_replace(':', '-', $format)).';'.$id; + $values['supannCMSIdEtiquette'][$supannCMSIdEtiquette] = $supannCMSIdEtiquette; + $values['supannCMSId'][$supannCMSId] = $supannCMSId; + } +} diff --git a/supann/personal/supann/class_TaggedAttribute.inc b/supann/personal/supann/class_TaggedAttribute.inc new file mode 100644 index 0000000000..45e31b12ec --- /dev/null +++ b/supann/personal/supann/class_TaggedAttribute.inc @@ -0,0 +1,80 @@ +value = []; + $pattern = '/^'.preg_quote($this->getLdapName(), '/').';(.+)$/'; + for ($i = 0; $i < $attrs['count']; $i++) { + if ($attrs[$i] == $this->getLdapName()) { + for ($j = 0; $j < $attrs[$attrs[$i]]['count']; $j++) { + $this->value[] = ';'.$attrs[$attrs[$i]][$j]; + } + } elseif (preg_match($pattern, $attrs[$i], $m)) { + for ($j = 0; $j < $attrs[$attrs[$i]]['count']; $j++) { + $this->value[] = $m[1].';'.$attrs[$attrs[$i]][$j]; + } + } + } + $this->sortValues(); + } + + function computeLdapValue () + { + throw new FusionDirectoryException('nope'); + } + + /*! \brief Fill LDAP value in the attrs array + */ + function fillLdapValue (array &$attrs) + { + if ($this->isInLdap()) { + $initialValues = $this->getInitialValue(); + foreach ($initialValues as $value) { + list($tag, $tagvalue) = explode(';', $value, 2); + if (empty($tag)) { + $attrs[$this->getLdapName()] = []; + } else { + $attrs[$this->getLdapName().';'.$tag] = []; + } + } + if (empty($this->value)) { + $attrs[$this->getLdapName()] = []; + } else { + foreach ($this->value as $value) { + list($tag, $tagvalue) = explode(';', $value, 2); + if (empty($tag)) { + $attrs[$this->getLdapName()][] = $tagvalue; + } else { + $attrs[$this->getLdapName().';'.$tag][] = $tagvalue; + } + } + } + } + } +} diff --git a/supann/personal/supann/class_supannCMS.inc b/supann/personal/supann/class_supannCMS.inc new file mode 100644 index 0000000000..ce2cfc158b --- /dev/null +++ b/supann/personal/supann/class_supannCMS.inc @@ -0,0 +1,94 @@ + _('Multiservice card'), + 'plDescription' => _('SupAnn CMS management'), + 'plIcon' => 'geticon.php?context=applications&icon=supann&size=48', + 'plSmallIcon' => 'geticon.php?context=applications&icon=supann&size=16', + 'plSelfModify' => TRUE, + 'plPriority' => 16, + 'plObjectClass' => ['supannCMS'], + 'plObjectType' => ['user'], + + 'plProvidedAcls' => parent::generatePlProvidedAcls(static::getAttributesInfo()) + ]; + } + + static function getAttributesInfo (): array + { + return [ + 'status' => [ + 'name' => _('Cards'), + 'class' => ['fullwidth'], + 'attrs' => [ + new HiddenArrayAttribute('supannCMSType', FALSE, []), + new TaggedAttribute(new StringAttribute('', '', 'supannCMSId', FALSE)), + new HiddenArrayAttribute('supannCMSIdEtiquette', FALSE, []), + new HiddenArrayAttribute('supannCMSSource', FALSE, []), + new HiddenArrayAttribute('supannCMSDateFin', FALSE, []), + new SupannOrderedArrayAttribute( + new SupannCMSAffectationAttribute( + _('Cards'), _('SupAnn CMS Affectation'), + 'supannCMSAffectation' + ), + // no order + FALSE, + [], + // edit button + TRUE + ), + ] + ], + ]; + } + + function __construct ($dn = NULL, $object = NULL, $parent = NULL, $mainTab = FALSE) + { + global $config; + + parent::__construct($dn, $object, $parent, $mainTab); + + $this->attributesAccess['supannCMSId']->setVisible(FALSE); + $this->attributesAccess['supannCMSAffectation']->setLinearRendering(FALSE); + $this->attributesAccess['supannCMSAffectation']->setHeaders([ + _('Type'), + _('Format'), + _('Id'), + _('Valid'), + _('Source'), + _('End date'), + '' + ]); + } + + protected function prepare_save (): array + { + $this->attributesAccess['supannCMSAffectation']->supannPrepareSave(); + return parent::prepare_save(); + } +} -- GitLab