ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilLDAPResult.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-20019 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
30 {
34  private $handle;
35 
39  private $result;
40 
44  private $rows;
45 
49  private $last_row;
50 
56  public function __construct($a_ldap_handle, $a_result = null)
57  {
58  $this->handle = $a_ldap_handle;
59 
60  if ($a_result != null) {
61  $this->result = $a_result;
62  }
63  }
64 
69  public function numRows()
70  {
71  return is_array($this->rows) ? count($this->rows) : 0;
72  }
73 
78  public function getResult()
79  {
80  return $this->result;
81  }
82 
87  public function setResult($result)
88  {
89  $this->result = $result;
90  }
91 
96  public function get()
97  {
98  return is_array($this->last_row) ? $this->last_row : array();
99  }
100 
105  public function getRows()
106  {
107  return is_array($this->rows) ? $this->rows : array();
108  }
109 
114  public function run()
115  {
116  $entries = @ldap_get_entries($this->handle, $this->result);
117  $this->addEntriesToRows($entries);
118 
119  return $this;
120  }
121 
126  private function addEntriesToRows($entries)
127  {
128  if (!$entries) {
129  return;
130  }
131 
132  $num = $entries['count'];
133 
134  if ($num == 0) {
135  return;
136  }
137 
138  for ($row_counter = 0; $row_counter < $num;$row_counter++) {
139  $data = $this->toSimpleArray($entries[$row_counter]);
140  $this->rows[] = $data;
141  $this->last_row = $data;
142  }
143  }
144 
150  private function toSimpleArray($entry)
151  {
152  $data = array();
153  foreach ($entry as $key => $value) {
154  $key = strtolower($key);
155 
156  if (is_int($key)) {
157  continue;
158  }
159  if ($key == 'dn') {
160  $data['dn'] = $value;
161  continue;
162  }
163  if (is_array($value)) {
164  if ($value['count'] > 1) {
165  for ($i = 0; $i < $value['count']; $i++) {
166  $data[$key][] = $value[$i];
167  }
168  } elseif ($value['count'] == 1) {
169  $data[$key] = $value[0];
170  }
171  } else {
172  $data[$key] = $value;
173  }
174  }
175 
176  return $data;
177  }
178 
182  public function __destruct()
183  {
184  @ldap_free_result($this->result);
185  }
186 }
numRows()
Total count of resulted rows.
getResult()
Resource from ldap_search()
$data
Definition: storeScorm.php:23
toSimpleArray($entry)
Transforms results from ldap_get_entries() to a simple format.
Class ilLDAPPagedResult.
addEntriesToRows($entries)
Adds Results from ldap_get_entries() to rows.
__destruct()
Destructor.
run()
Starts ldap_get_entries() and transforms results.
setResult($result)
Resource from ldap_search()
getRows()
Returns complete results.
__construct($a_ldap_handle, $a_result=null)
ilLDAPPagedResult constructor.
$i
Definition: metadata.php:24