PHP code example of openldapobject / ldapobjectbundle

1. Go to this page and download the library: Download openldapobject/ldapobjectbundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

openldapobject / ldapobjectbundle example snippets



// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new OpenLdapObject\Bundle\LdapObjectBundle\OpenLdapObjectLdapObjectBundle(),
        );

        // ...
    }

    // ...
}



namespace AppBundle\Entity;

use OpenLdapObject\Entity;
use OpenLdapObject\Collection\EntityCollection;
use OpenLdapObject\Annotations as OLO;

/**
 * @OLO\DN(value="ou=accounts")
 * @OLO\Entity({"udlAccount"})
 */
class Account extends Entity {
    /**
     * @OLO\Column(type="string")
     * @OLO\Index
     */
    private $uid; 

    /**
     * @OLO\Column(type="array")
     */
    private $sn;

    /**
     * @OLO\Column(type="array")
     */
    private $udlAccountDisplaySn;
    
    /**
     * @OLO\Column(type="array")
     */
    private $givenName;
    
    /**
     * @OLO\Column(type="array")
     */
    private $udlAccountDisplayGivenName;

    /**
     * @OLO\Column(type="string")
     */
    private $mail;

    /**
     * @OLO\Column(type="string")
     */
    private $supannEntiteAffectationPrincipale;
    
    /**
     * @OLO\Column(type="string")
     */
    private $eduPersonPrimaryAffiliation;

    /**
     * @OLO\Column(type="array")
     */
    private $eduPersonAffiliation;
  
    /**
     * @OLO\Column(type="array")
     */
    private $supannEntiteAffectation;
       
    /**
     * @OLO\Column(type="string")
     */
    private $supannCivilite;
    
    /**
     * @OLO\Column(type="array")
     */
    private $memberOf;
    

    public function getUid() {
        return $this->uid;
    }

    public function setUid($value) {
        $this->uid = $value;
        return $this;
    }

    public function getSn() {
        return $this->sn;
    }

    public function setSn($sn) {
        $this->sn = $sn;
        return $this;
    }
            
    public function addSn($value) {
        $this->sn->add($value);
        return $this;
    }

    public function removeSn($value) {
        $this->sn->removeElement($value);
        return $this;
    }

    public function getGivenName() {
        return $this->givenName;
    }
    
    public function setGivenName($givenName) {
        $this->givenName = $givenName;
        return $this;
    }
    
    public function addGivenName($value) {
        $this->givenName->add($value);
        return $this;
    }

    public function removeGivenName($value) {
        $this->givenName->removeElement($value);
        return $this;
    }
    
    public function getUdlAccountDisplayGivenName() {
        return $this->udlAccountDisplayGivenName;
    }
    
    public function setUdlAccountDisplayGivenName($udlAccountDisplayGivenName) {
        $this->udlAccountDisplayGivenName = $udlAccountDisplayGivenName;
        return $this;
    }
    
    public function addUdlAccountDisplayGivenName($value) {
        $this->udlAccountDisplayGivenName->add($value);
        return $this;
    }

    public function removeUdlAccountDisplayGivenName($value) {
        $this->udlAccountDisplayGivenName->removeElement($value);
        return $this;
    }

    public function getUdlAccountDisplaySn() {
        return $this->udlAccountDisplaySn;
    }
    
    public function setUdlAccountDisplaySn($udlAccountDisplaySn) {
        $this->udlAccountDisplaySn = $udlAccountDisplaySn;
        return $this;
    }
    
    public function addUdlAccountDisplaySn($value) {
        $this->udlAccountDisplaySn->add($value);
        return $this;
    }
    
    public function removeUdlAccountDisplaySn($value) {
        $this->udlAccountDisplaySn->removeElement($value);
        return $this;
    }
    
    public function getMail() {
        return $this->mail;
    }

    public function setMail($value) {
        $this->mail = $value;
        return $this;
    }
    
    public function getSupannEntiteAffectationPrincipale() {
        return $this->supannEntiteAffectationPrincipale;
    }
    
    public function setSupannEntiteAffectationPrincipale($supannEntiteAffectationPrincipale) {
        $this->supannEntiteAffectationPrincipale = $supannEntiteAffectationPrincipale;
        return $this;
    }

    public function getEduPersonPrimaryAffiliation() {
        return $this->eduPersonPrimaryAffiliation;
    }

    public function setEduPersonPrimaryAffiliation($eduPersonPrimaryAffiliation) {
        $this->eduPersonPrimaryAffiliation = $eduPersonPrimaryAffiliation;
        return $this;
    }

    public function getEduPersonAffiliation() {
        return $this->eduPersonAffiliation;
    }
    
    public function setEduPersonAffiliation($eduPersonAffiliation) {
        $this->eduPersonAffiliation = $eduPersonAffiliation;
        return $this;
    }

    public function addEduPersonAffiliation($value) {
        $this->eduPersonAffiliation->add($value);
        return $this;
    }

    public function removeEduPersonAffiliation($value) {
        $this->eduPersonAffiliation->removeElement($value);
        return $this;
    }
    
    public function getSupannEntiteAffectation() {
        return $this->supannEntiteAffectation;
    }
    
    public function setSupannEntiteAffectation($supannEntiteAffectation) {
        $this->supannEntiteAffectation = $supannEntiteAffectation;
        return $this;
    }

    public function addSupannEntiteAffectation($supannEntiteAffectation) {
        $this->supannEntiteAffectation->add($supannEntiteAffectation);
        return $this;
    }

    public function removeSupannEntiteAffectation($supannEntiteAffectation) {
        $this->supannEntiteAffectation->removeElement($supannEntiteAffectation);
        return $this;
    }
    
    public function getSupannCivilite() {
       return $this->supannCivilite; 
    } 
    
    public function setSupannCivilite($value) {
        $this->supannCivilite = $value;
        return $this;
    }
    
    public function getMemberOf(){
       return $this->memberOf; 
    } 
    
    public function setMemberOf($memberOf) {
        $this->memberOf = $memberOf;
        return $this;
    }
    
    public function addMemberOf($memberOf) {
        $this->memberOf->add($memberOf);
        return $this;
    }

    public function removeMemberOf($memberOf) {
        $this->memberOf->removeElement($memberOf);
        return $this;
    }
}

$a = new Account();
$a->setUid('john.doo');
$a->setGivenname('John');
$a->setSn('Doo');
$em = $this->get('ldap_object.manager');
$em->persist($a);
$em->flush();

$repo = $em->getRepository('AppBundle\Entity\Account');
$a = $repo->find('john.doo');

$conditions = Array();
$not = true;
$conditions[] = new Condition('sn', 'Hetru');
$conditions[] = new Condition('sn', 'Bomy', $not);
        
$query = new Query(Query::CAND); 
$query->cAnd($conditions);
        
$em = $this->get('ldap_object.manager');
$repo = $em->getRepository('AppBundle\Entity\Account');
$a = $repo->findByQuery($query);



namespace AppBundle\Entity;

use OpenLdapObject\Entity;
use OpenLdapObject\Annotations as OLO;

/**
 * @OLO\Dn(value="ou=groups")
 * @OLO\Entity({"udlGroupe"})
 */
class Group extends Entity {
    
    /**
     * @OLO\Column(type="string")
     * @OLO\Index
     */
    private $cn;
    
    /**
     * @OLO\Column(type="string")
     */
    private $description;
    
    /**
     * @OLO\Column(type="array")
     */
    private $member;

    public function getCn() {
        return $this->cn;   
    }
    
    public function setCn($cn) {
        $this->cn = $cn;
        return $this;
    }
    
    public function getDescription() {
        return $this->description;   
    }
    
    public function setDescription($description) {
        $this->description = $description;
        return $this;
    }
   
    public function getMember() {
        return $this->member;   
    }
    
    public function setMember($member) {
        $this->member = $member;
        return $this;
    }
    
    public function addMember($member) {
        $this->member->add($member);
        return $this;
    }

    public function removeMember($member) {
        $this->member->removeElement($member);
        return $this;
    }
}

$g = new Group();
$g->setCn('APP:TEST');
$g->setDescription('APPTEST');
$g->addMember('uid=1940,ou=accounts,dc=univ,dc=fr');
$em = $this->get('ldap_object.manager');
$em->persist($g);
$em->flush();

$repo = $em->getRepository('AppBundle\Entity\Group');
$g = $repo->find('APP:TEST');



namespace AppBundle\Entity;

use OpenLdapObject\Entity;
use OpenLdapObject\Annotations as OLO;

/**
 * @OLO\Dn(value="ou=structures")
 * @OLO\Entity({"udlStructure"})
 */
class Structure extends Entity {
    /**
     * @OLO\Column(type="string")
     * @OLO\Index
     */
    private $supannCodeEntite;
    
    /**
     * @OLO\Column(type="string")
     */
    private $ou;
    
    /**
     * @OLO\Column(type="string")
     */
    private $supannCodeEntiteParent;
    
    /**
     * @OLO\Column(type="string")
     */
    private $description;

    /**
     * 
     * @OLO\Column(type="string")
     */
    private $udlStructureLibelleCourt;

    public function getSupannCodeEntite() {
        return $this->supannCodeEntite;
    }

    public function setSupannCodeEntite($supannCodeEntite) {
        $this->supannCodeEntite = $supannCodeEntite;
        return $this;
    }
    
    public function getOu() {
        return $this->ou;
    }
     
    public function setOu($ou) {
        $this->ou = $ou;
        return $this;
    }
    
    public function getSupannCodeEntiteParent() {
        return $this->supannCodeEntiteParent;   
    }
    
    public function setSupannCodeEntiteParent($supannCodeEntite) {
        $this->supannCodeEntiteParent = $supannCodeEntite;
        return $this;
    }

    public function getDescription() {
        return $this->description;
    }

    public function setDescription($description) {
        $this->description = $description;
        return $this;
    }
    
    public function getUdlStructureLibelleCourt() {
        return $this->udlStructureLibelleCourt;
    }
    
    public function setUdlStructureLibelleCourt($udlStructureLibelleCourt) {
        $this->udlStructureLibelleCourt = $udlStructureLibelleCourt;
        return $this;
    }
}

$s = new Structure();
$s->setSupannCodeEntite('STTRUCMUCHE');
$s->setOu('STTRUCMUCHE);
$s->setSupannCodeEntiteParent('STUDL');
$s->setDescription('{acronyme1}STRUCTURE TRUC MUCHE');
$em = $this->get('ldap_object.manager');
$em->persist($s);
$em->flush();

$repo = $em->getRepository('AppBundle\Entity\Structure');
$s = $repo->find('STTRUCMUCHE');