ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilLDAPResult.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2006 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
35{
36 private $ldap_handle = null;
37 private $result = null;
38 private $entries = null;
39
40 private $num_results = null;
41 private $data = null;
42
51 public function __construct($a_ldap_connection, $a_result)
52 {
53 $this->ldap_handle = $a_ldap_connection;
54 $this->result = $a_result;
55
56 $this->toSimpleArray();
57 }
58
66 public function get()
67 {
68 return $this->data ? $this->data : array();
69 }
70
77 public function getRows()
78 {
79 return $this->all_rows ? $this->all_rows : array();
80 }
81
89 public function numRows()
90 {
91 return $this->num_results;
92 }
93
101 private function toSimpleArray()
102 {
103 $this->data = array();
104 $this->num_results = 0;
105
106 if (!$this->entries = $this->getEntries()) {
107 return false;
108 }
109
110 $this->num_results = $this->entries['count'];
111 if ($this->entries['count'] == 0) {
112 return true;
113 }
114
115 for ($row_counter = 0; $row_counter < $this->entries['count'];$row_counter++) {
116 $data = array();
117 foreach ($this->entries[$row_counter] as $key => $value) {
118 $key = strtolower($key);
119
120 if (is_int($key)) {
121 continue;
122 }
123 if ($key == 'dn') {
124 $data['dn'] = $value;
125 continue;
126 }
127 if (is_array($value)) {
128 if ($value['count'] > 1) {
129 for ($i = 0; $i < $value['count']; $i++) {
130 $data[$key][] = $value[$i];
131 }
132 } elseif ($value['count'] == 1) {
133 $data[$key] = $value[0];
134 }
135 } else {
136 $data[$key] = $value;
137 }
138 }
139 $this->all_rows[] = $data;
140 if ($row_counter == 0) {
141 $this->data = $data;
142 }
143 }
144 return true;
145 }
146
147 public function __destruct()
148 {
149 @ldap_free_result($this->result);
150 }
151
158 private function getEntries()
159 {
160 return $this->entries = @ldap_get_entries($this->ldap_handle, $this->result);
161
162 // this way ldap_get_entries is binary safe
163
164 $i = 0;
165 $tmp_entries = array();
166 $entry = ldap_first_entry($this->ldap_handle, $this->result);
167 do {
168 $attributes = @ldap_get_attributes($this->ldap_handle, $entry);
169 for ($j = 0; $j < $attributes['count']; $j++) {
170 $values = ldap_get_values_len($this->ldap_handle, $entry, $attributes[$j]);
171 $tmp_entries[$i][strtolower($attributes[$j])] = $values;
172 }
173 $i++;
174 } while ($entry = @ldap_next_entry($this->ldap_handle, $entry));
175
176 if ($i) {
177 $tmp_entries['count'] = $i;
178 }
179 $this->entries = $tmp_entries;
180 return $this->entries;
181 }
182}
An exception for terminatinating execution or to throw for unit testing.
numRows()
get number of rows
getEntries()
Wrapper for ldap_get_entries.
toSimpleArray()
Transform ldap result in simple array.
getRows()
Get all result rows.
__construct($a_ldap_connection, $a_result)
Constructor.
$key
Definition: croninfo.php:18
$i
Definition: disco.tpl.php:19
if(array_key_exists('yes', $_REQUEST)) $attributes
Definition: getconsent.php:85
$this data['403_header']
$values