Skip to content
Snippets Groups Projects
Select Git revision
  • f5e8085d9de76bcee48bbe154c8bdc909c02fc66
  • master default protected
  • 5.x
  • 7
  • 6.0.question
  • bg-php8
  • release_3.1.0
  • release_4.0.0
  • zf-3.0
  • zf-3.x
  • 6.0.6
  • 5.0.8
  • 5.0.7
  • 6.0.5
  • 5.0.6
  • 6.0.4
  • 5.0.5
  • 7.0.3
  • 7.0.2
  • 6.0.3
  • 6.0.2
  • 6.0.1
  • 5.0.4
  • 7.0.1
  • 5.0.3
  • 5.0.2
  • 5.0.1
  • 7.0.0
  • 6.0.0
  • 4.0.2
30 results

Structure.php

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    Structure.php 5.77 KiB
    <?php
    
    namespace UnicaenLdap\Entity\Base;
    
    use UnicaenLdap\Entity\Entity;
    use UnicaenLdap\Entity\Structure as StructureEntity;
    use UnicaenLdap\Exception;
    use Zend\Ldap\Exception\LdapException;
    
    /**
     * Classe mère des entités de la branche "structures" de l'annuaire LDAP.
     *
     * @author David Surville <david.surville@unicaen.fr>
     */
    class Structure extends Entity
    {
        protected $type = 'Structure';
    
        /**
         * Liste des classes d'objet nécessaires à la création d'une structure
         *
         * @var string[]
         */
        protected $objectClass = [
            'top',
            'organizationalUnit',
            'supannEntite',
            'ucbnEntite',
        ];
    
        /**
         * Liste des attributs autorisés pour une entité "People"
         *
         * @var array
         */
        protected $authorizedAttributes = [
            // Attributes classes
            'objectClass',
            // Attributes
            'description',
            'facsimileTelephoneNumber',
            'ou',
            'postalAddress',
            'supannCodeEntiteParent',
            'supannRefId',
            'supannTypeEntite',
            'telephoneNumber',
        ];
    
        /**
         * Liste des attributs contenant des dates
         *
         * @var array
         */
        protected $dateTimeAttributes = [];
    
        /**
         * Liste des attributs monovalués
         *
         * @var array
         */
        protected $monoValuedAttributes = [];
    
    
        /**
         * Attribut Ldap "description"
         *
         * @param array|string|null $value
         * @param bool $append
         * @return self
         * @throws Exception
         * @throws LdapException
         */
        public function setDescription($value = null, $append = false)
        {
            $value = $this->preFormat($value);
            $this->appendOrNot('description', $value, $append);
    
            return $this;
        }
    
        /**
         * Attribut Ldap "ou"
         *
         * @param array|string|null $value
         * @param bool $append
         * @return self
         * @throws Exception
         * @throws LdapException
         */
        public function setOu($value = null, $append = false)
        {
            $value = $this->preFormat($value);
            $this->appendOrNot('ou', $value, $append);
    
            return $this;
        }
    
        /**
         * Attribut Ldap "supannCodeEntiteParent"
         *
         * @param array|string|null $value
         * @param bool $append
         * @return self
         * @throws Exception
         * @throws LdapException
         */
        public function setSupannCodeEntiteParent($value = null, $append = false)
        {
            $value = $this->preFormat($value);
            $value = array_map(function ($val) {
                if (is_string($val)) {
                    if (0 !== strpos($val, $this->getService()->getCodeStructurePrefixe())) {
                        $val = $this->getService()->getCodeStructurePrefixe() . $val;
                    }
                    return $val;
                } elseif ($val instanceof StructureEntity) {
                    return $val->get('supannCodeEntite');
                } else {
                    return null;
                }
            }, $value);
    
            $this->appendOrNot('supannCodeEntiteParent', array_filter($value), $append);
    
            return $this;
        }
    
        /**
         * Attribut Ldap "supannTypeEntite"
         *
         * @param array|string|null $value
         * @param bool $append
         * @return self
         * @throws Exception
         * @throws LdapException
         */
        public function setSupannTypeEntite($value = null, $append = false)
        {
            $value = $this->preFormat($value);
            $supannLabel = $this->getLabel('SUPANN');
            $value = array_map(function ($val) use ($supannLabel) {
                if (is_string($val)) {
                    return preg_match("/^$supannLabel.+$/", $val) ? $val : sprintf('%s%s', $supannLabel, $val);
                } else {
                    return null;
                }
            }, $value);
    
            $this->appendOrNot('supannTypeEntite', array_filter($value), $append);
    
            return $this;
        }
    
        /**
         * Attribut Ldap "telephoneNumber"
         *
         * @param array|string|null $value
         * @param bool $append
         * @return self
         * @throws Exception
         * @throws LdapException
         */
        public function setTelephoneNumber($value = null, $append = false)
        {
            $value = $this->preFormat($value);
            $value = array_map([$this, 'formatTel'], $value);
            $this->appendOrNot('telephoneNumber', $value, $append);
    
            return $this;
        }
    
        /**
         * Attribut Ldap "facsimileTelephoneNumber"
         *
         * @param array|string|null $value
         * @param bool $append
         * @return self
         * @throws Exception
         * @throws LdapException
         */
        public function setFacsimileTelephoneNumber($value = null, $append = false)
        {
            $value = $this->preFormat($value);
            $value = array_map([$this, 'formatTel'], $value);
            $this->appendOrNot('facsimileTelephoneNumber', $value, $append);
    
            return $this;
        }
    
        /**
         * Attribut Ldap "postalAddress"
         *
         * @param array|string|null $value
         * @param bool $append
         * @return self
         * @throws Exception
         * @throws LdapException
         */
        public function setPostalAddress($value = null, $append = false)
        {
            $value = $this->preFormat($value);
            $value = array_filter($value, function ($v) {
                return preg_match(self::$postal_address_pattern, $v);
            });
    
            $this->appendOrNot('postalAddress', $value, $append);
    
            return $this;
        }
    
        /**
         * Attribut Ldap "supannRefId"
         *
         * @param array|string|null $value
         * @param bool $append
         * @return self
         * @throws Exception
         * @throws LdapException
         */
        public function setSupannRefId($value = null, $append = false)
        {
            $value = $this->preFormat($value);
            $value = array_filter($value, function ($v) {
                return preg_match(self::$attribute_with_label_pattern, $v);
            });
    
            $this->appendOrNot('supannRefId', $value, $append);
    
            return $this;
        }
    }