• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Services/LDAP/classes/class.ilLDAPResult.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2006 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00034 class ilLDAPResult
00035 {
00036         private $ldap_handle = null;
00037         private $result = null;
00038         private $entries = null;
00039         
00040         private $num_results = null;
00041         private $data = null;
00042         
00051         public function __construct($a_ldap_connection,$a_result)
00052         {
00053                 $this->ldap_handle = $a_ldap_connection;
00054                 $this->result = $a_result;
00055                 
00056                 $this->toSimpleArray();
00057         }
00058         
00066         public function get()
00067         {
00068                 return $this->data ? $this->data : array();
00069         }
00070         
00077         public function getRows()
00078         {
00079                 return $this->all_rows ? $this->all_rows : array();             
00080         }
00081         
00089         public function numRows()
00090         {
00091                 return $this->num_results;
00092         }
00093         
00101         private function toSimpleArray()
00102         {
00103                 $this->data = array();
00104                 $this->num_results = 0;
00105                 
00106                 if(!$this->entries = $this->getEntries())
00107                 {
00108                         return false;   
00109                 }
00110                 
00111                 $this->num_results = $this->entries['count'];
00112                 if($this->entries['count'] == 0)
00113                 {
00114                         return true;
00115                 }
00116                 
00117                 for($row_counter = 0; $row_counter < $this->entries['count'];$row_counter++)
00118                 {
00119                         $data = array();
00120                         foreach($this->entries[$row_counter] as $key => $value)
00121                         {
00122                                 $key = strtolower($key);
00123                                 
00124                                 if(is_int($key))
00125                                 {
00126                                         continue;
00127                                 }
00128                                 if($key == 'dn')
00129                                 {
00130                                         $data['dn'] = $value;
00131                                         continue;
00132                                 }
00133                                 
00134                                 if($value['count'] > 1)
00135                                 {
00136                                         for($i = 0; $i < $value['count']; $i++)
00137                                         {
00138                                                 $data[$key][] = $value[$i];
00139                                         }
00140                                 }
00141                                 elseif($value['count'] == 1)
00142                                 {
00143                                         $data[$key] = $value[0];
00144                                 }
00145                         }
00146                         $this->all_rows[] = $data;
00147                         if($row_counter == 0)
00148                         {
00149                                 $this->data = $data;
00150                         }
00151                 }
00152                 return true;
00153         }
00154         
00155         public function __destruct()
00156         {
00157                 @ldap_free_result($this->result);
00158         }
00159         
00166         private function getEntries()
00167         {
00168                 return $this->entries = @ldap_get_entries($this->ldap_handle,$this->result);
00169 
00170                 // this way ldap_get_entries is binary safe
00171 
00172                 $i=0;
00173                 $tmp_entries = array();
00174                 $entry = ldap_first_entry($this->ldap_handle,$this->result);
00175                 do {
00176                         $attributes = @ldap_get_attributes($this->ldap_handle, $entry);
00177                         for($j=0; $j<$attributes['count']; $j++) 
00178                         {
00179                                 $values = ldap_get_values_len($this->ldap_handle, $entry,$attributes[$j]);
00180                                 $tmp_entries[$i][strtolower($attributes[$j])] = $values;
00181                         }
00182                         $i++;               
00183                 } while ($entry = @ldap_next_entry($this->ldap_handle,$entry));
00184 
00185                 if($i)
00186                 {
00187                         $tmp_entries['count'] = $i;
00188                 }
00189                 $this->entries = $tmp_entries;
00190                 return $this->entries;
00191         }
00192 }
00193 
00194 ?>

Generated on Fri Dec 13 2013 17:56:57 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1