Verified Commit c2bd5866 authored by Côme Chilliet's avatar Côme Chilliet
Browse files

: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
No related merge requests found
Showing with 278 additions and 0 deletions
+278 -0
# Formats
# TECHONOLOGY:ENCODING;label
MIFARE:XLSB;Mifare XLSB
# 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
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org)
Copyright (C) 2010-2012 Antoine Gallavardin
Copyright (C) 2013-2020 FusionDirectory
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
class SupannCMSAffectationAttribute extends SupannCompositeAttribute
{
function __construct ($label, $description, $ldapName, $acl = '')
{
list($types, $typeLabels) = supann::get_choices_for('cmstype');
list($formats, $formatLabels) = supann::get_choices_for('cmsformat');
$attributes = [
new SelectAttribute(
_('Type'), _('supannCMSType - Card type'),
'supannCMSType_type', TRUE,
$types, '', $typeLabels
),
new SelectAttribute(
_('Format'), _('Card format'),
'none_format', TRUE,
$formats, '', $formatLabels
),
new StringAttribute(
_('Id'), _('Card id'),
'none_id', TRUE
),
new BooleanAttribute(
_('Valid'), _('Card validity'),
'none_valid', TRUE,
TRUE
),
new SelectAttribute(
_('Source'), _('Card managing system and establishment'),
'supannCMSSource_source', FALSE
),
new GeneralizedTimeDateAttribute(
_('End date'), _('End of validity date, if any'),
'supannCMSDateFin_datefin', FALSE,
''
),
];
parent::__construct($description, $ldapName, $attributes, $acl, $label);
}
function supannGetValues (&$values)
{
if ($this->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;
}
}
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org)
Copyright (C) 2019-2020 FusionDirectory
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
class TaggedAttribute extends SetAttribute
{
function __construct (Attribute $attribute, array $values = [], bool $valueUnicity = TRUE)
{
parent::__construct($attribute, $values, $valueUnicity);
}
protected function loadAttrValue (array $attrs)
{
$this->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;
}
}
}
}
}
}
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org)
Copyright (C) 2018-2020 FusionDirectory
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
class supannCMS extends simplePlugin
{
protected $displayHeader = TRUE;
static function plInfo (): array
{
return [
'plShortName' => _('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();
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment