class_SupannCMSAppAffectationAttribute.inc 3.69 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?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 SupannCMSAppAffectationAttribute extends SupannCompositeAttribute
{
  function __construct ($label, $description, $ldapName, $acl = '')
  {
    global $config;
    list($types, $typeLabels)     = supann::get_choices_for('cmstype');
    $attributes = [
      new SelectAttribute(
        _('Type'), _('supannCMSType - Card type'),
32
        'supannCMSType_type_'.$ldapName, TRUE,
33
34
35
36
        $types, '', $typeLabels
      ),
      new SelectAttribute(
        _('Source'), _('Card managing system and establishment'),
37
        'supannCMSSource_source_'.$ldapName, TRUE,
38
39
40
41
        $config->get_cfg_value('supannCMSSources', [])
      ),
      new SelectAttribute(
        _('Domain'), _('Application domain'),
42
        'none_domaine_'.$ldapName, TRUE,
43
44
45
46
        array_column($this->getConfigAppDomains(), 1)
      ),
      new StringAttribute(
        _('Id'), _('Application id'),
47
        'none_id_'.$ldapName, TRUE
48
49
50
      ),
      new BooleanAttribute(
        _('Valid'), _('Application validity'),
51
        'none_valide_'.$ldapName, TRUE,
52
53
54
55
56
        TRUE, '',
        'vrai', 'faux'
      ),
      new GeneralizedTimeDateAttribute(
        _('End date'), _('End of validity date, if any'),
57
        'supannCMSDateFin_datefin_'.$ldapName, FALSE,
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
        ''
      ),
    ];
    parent::__construct($description, $ldapName, $attributes, $acl, $label);
  }

  protected function isValid (): bool
  {
    return ($this->attributes[4]->getValue() === TRUE);
  }

  protected function getConfigAppDomains (): array
  {
    global $config;
    return array_map(
      function ($supannCMSAppDomain) {
        return explode(';', $supannCMSAppDomain, 2);
      },
      $config->get_cfg_value('supannCMSAppDomains', [])
    );
  }

  function supannGetValues (&$values)
  {
    foreach ($this->attributes as &$attribute) {
83
84
      list($attrname, ) = explode('_', $attribute->getLdapName());
      if ($attrname == 'none') {
85
86
87
        continue;
      }
      $value = $attribute->getValue();
88
89
      if (!isset($values[$attrname])) {
        $values[$attrname] = [];
90
91
92
93
94
      }
      if ($value == '') {
        continue;
      }
      if ($this->isValid()) {
95
        $values[$attrname][$value] = $value;
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
      }
    }
    unset($attribute);
    if ($this->isValid()) {
      $domains  = array_column($this->getConfigAppDomains(), 0, 1);
      $domain   = $this->attributes[2]->getValue();
      $id       = $this->attributes[3]->getValue();
      $supannCMSAppIdDomaine  = $id.'@'.$domain;
      $supannCMSAppId         = $domains[$domain].';'.$id;
      $values['supannCMSAppIdDomaine'][$supannCMSAppIdDomaine] = $supannCMSAppIdDomaine;
      $values['supannCMSAppId'][$supannCMSAppId] = $supannCMSAppId;
    } else {
      if (!isset($values['supannCMSAppIdDomaine'])) {
        $values['supannCMSAppIdDomaine'] = [];
      }
      if (!isset($values['supannCMSAppId'])) {
        $values['supannCMSAppId'] = [];
      }
    }
  }
}