ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLDAPResult.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
27{
31 private $handle;
32
36 private $result = null;
37
38 private array $rows = [];
39 private ?array $last_row;
40
45 public function __construct($a_ldap_handle, $a_result = null)
46 {
47 $this->handle = $a_ldap_handle;
48
49 if ($a_result !== null && $a_result !== false) {
50 $this->result = $a_result;
51 }
52 }
53
57 public function numRows(): int
58 {
59 return count($this->rows);
60 }
61
66 public function setResult($result): void
67 {
68 $this->result = $result;
69 }
70
75 public function get(): array
76 {
77 return is_array($this->last_row) ? $this->last_row : [];
78 }
79
83 public function getRows(): array
84 {
85 return $this->rows;
86 }
87
92 public function run(): self
93 {
94 if ($this->result) {
95 $entries = ldap_get_entries($this->handle, $this->result);
96 $this->addEntriesToRows($entries);
97 }
98
99 return $this;
100 }
101
105 private function addEntriesToRows(array $entries): void
106 {
107 $num = $entries['count'];
108 if ($num === 0) {
109 return;
110 }
111
112 for ($row_counter = 0; $row_counter < $num; $row_counter++) {
113 $data = $this->toSimpleArray($entries[$row_counter]);
114 $this->rows[] = $data;
115 $this->last_row = $data;
116 }
117 }
118
122 private function toSimpleArray(array $entry): array
123 {
124 $data = [];
125 foreach ($entry as $key => $value) {
126 if (is_int($key)) {
127 continue;
128 }
129
130 $key = strtolower($key);
131 if ($key === 'dn') {
132 $data['dn'] = $value;
133 continue;
134 }
135 if (is_array($value)) {
136 if ($value['count'] > 1) {
137 for ($i = 0; $i < $value['count']; $i++) {
138 $data[$key][] = $value[$i];
139 }
140 } elseif ($value['count'] === 1) {
141 $data[$key] = $value[0];
142 }
143 } else {
144 $data[$key] = $value;
145 }
146 }
147
148 return $data;
149 }
150
151 public function __destruct()
152 {
153 if ($this->result) {
154 ldap_free_result($this->result);
155 }
156 }
157}
Class ilLDAPPagedResult.
run()
Starts ldap_get_entries() and transforms results.
addEntriesToRows(array $entries)
Adds Results from ldap_get_entries() to rows.
toSimpleArray(array $entry)
Transforms results from ldap_get_entries() to a simple format.
numRows()
Total count of resulted rows.
setResult($result)
Resource from ldap_search()
getRows()
Returns complete results.
__construct($a_ldap_handle, $a_result=null)