Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Created by PhpStorm.
- * User: lasezn
- * Date: 04/12/2015
- * Time: 16:24
- */
- namespace AppBundle\Even;
- use AppBundle\Exception\EvenException;
- class EvenManager
- {
- private
- $ldap_service,
- $ldap_dn,
- $ldap_password,
- $ldap_basedn_emp,
- $ldap_basedn_ext,
- $ldap_basedn_comp,
- $ldap_basedn_loca,
- $ldap_filtre_user,
- $ldap_filtre_comp,
- $ldap_filtre_loca;
- public function __construct($ldap_service, $ldap_dn, $ldap_password, $ldap_basedn_emp, $ldap_basedn_ext, $ldap_basedn_comp, $ldap_basedn_loca, $ldap_filtre_user, $ldap_filtre_comp, $ldap_filtre_loca){
- $this->ldap_service = $ldap_service;
- $this->ldap_dn = $ldap_dn;
- $this->ldap_password = $ldap_password;
- $this->ldap_basedn_emp = $ldap_basedn_emp;
- $this->ldap_basedn_ext = $ldap_basedn_ext;
- $this->ldap_basedn_comp = $ldap_basedn_comp;
- $this->ldap_basedn_loca = $ldap_basedn_loca;
- $this->ldap_filtre_user = $ldap_filtre_user;
- $this->ldap_filtre_comp = $ldap_filtre_comp;
- $this->ldap_filtre_loca = $ldap_filtre_loca;
- }
- private function authentification(){
- $this->ldap_service->bind($this->ldap_dn, $this->ldap_password);
- return $this;
- }
- public function cleanData($datas){
- $dataclean = [];
- for( $i=0; $i < $datas['count']; $i++)
- {
- if(is_array($datas[$i]))
- {
- $subdatas = $datas[$i];
- if( !empty($subdatas['dn']) and ! isset($dataclean[$subdatas['dn']]))
- {
- if ((preg_match('#employees#i',$subdatas['dn'])) || (preg_match('#externals#i',$subdatas['dn'])))
- {
- $subdatas['dn'] = preg_replace('#cn=([a-z]*) ([a-z0-9 \'-]*),ou=([a-z]+),ou=([a-z]+),dc=([a-z]+),dc=eu#i', '$2 $1,$3', $subdatas['dn']);
- } else
- $subdatas['dn'] = preg_replace('#cn=([a-z0-9 \'-]*),ou=([a-z]+),ou=([a-z]+),dc=([a-z]+),dc=eu#i', '$1,$2', $subdatas['dn']);
- $dataclean[$subdatas['dn']] = $this->cleanData($subdatas);
- }
- else {
- $dataclean[] = $this->cleanData($subdatas);
- }
- }
- else {
- $attribut = $datas[$i];
- if( $datas[$attribut]['count'] == 1){
- $dataclean[$attribut] = $datas[$attribut][0];
- } else {
- for( $j = 0; $j < $datas[$attribut]; $j++){
- $dataclean[$attribut][] = $datas[$attribut][$j];
- }
- }
- }
- }
- return $dataclean;
- }
- public function eventestRecherche($params){
- $this->authentification();
- $resultat= [];
- // $this->ldap_service->find( $cible, $saisie, $filter )
- if (is_array($params)){ //ici c ests pour page liistage repertoire
- if (isset($params['cible']))
- {
- $cible = $params['cible'];
- //dump($cible);
- $filter = $this->getFiltre($cible);
- //dump($filter);
- if (isset($params['saisie']))
- {
- $saisie = "cn={$params['saisie']}";
- //dump($saisie);
- } else
- $saisie = "cn=*";
- }
- $reponse = $this->ldap_service->find($cible, $saisie, $filter);
- if(empty($reponse)){
- throw new EvenException("Aucun résultat avec vos criteres de recherche");
- } else
- //dump($reponse);
- foreach($reponse as $test)
- {
- if (is_array($test))
- {
- $test = $this->cleanData($test);
- array_push($resultat,$test);
- //dump($test);
- }
- }
- //dump($resultat);
- } else {
- $basedn = array($this->ldap_basedn_emp,$this->ldap_basedn_ext,$this->ldap_basedn_loca,$this->ldap_basedn_comp);
- foreach($basedn as $key => $base){
- if ($key < 2) $filter = $this->ldap_filtre_user;
- else if ($key == 2)
- $filter = $this->ldap_filtre_loca;
- else
- $filter = $this->ldap_filtre_comp;
- $reponse = $this->ldap_service->find($base, "cn=*{$params}*",$filter);
- //dump($reponse);
- if ($reponse != null){
- $cible = preg_replace('#ou=([a-z]+),ou=([a-z]+),dc=evengroup,dc=eu#i', '$1', $base);
- foreach($reponse as $repertoire){
- if (is_array($repertoire))// on supprime la ligne count et sa valeur
- {
- $repertoire=$this->cleanData($repertoire);
- $repertoire["repertoire"]= $cible;
- array_push($resultat,$repertoire);
- }
- }
- }
- }
- // ici c est qu'onn utilise le formulaire
- //dump($resultat);
- if ($resultat == null){
- throw new EvenException("Aucun résultat avec vos criteres de recherche");
- }
- }
- return $resultat;
- }
- private function getFiltre($cible){
- if ($cible == $this->ldap_basedn_ext)
- {
- $filter = $this->ldap_filtre_user;
- }
- if ($cible == $this->ldap_basedn_emp)
- {
- $filter = $this->ldap_filtre_user;
- }
- if ($cible == $this->ldap_basedn_loca)
- {
- $filter = $this->ldap_filtre_loca;
- }
- if ($cible == $this->ldap_basedn_comp)
- {
- $filter = $this->ldap_filtre_comp;
- }
- return $filter;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement