|
0
|
1 <?php
|
|
|
2
|
|
|
3 /**
|
|
|
4 +-----------------------------------------------------------------------+
|
|
|
5 | This file is part of the Roundcube Webmail client |
|
|
|
6 | Copyright (C) 2006-2013, The Roundcube Dev Team |
|
|
|
7 | |
|
|
|
8 | Licensed under the GNU General Public License version 3 or |
|
|
|
9 | any later version with exceptions for skins & plugins. |
|
|
|
10 | See the README file for a full license statement. |
|
|
|
11 | |
|
|
|
12 | PURPOSE: |
|
|
|
13 | Class representing an address directory result set |
|
|
|
14 +-----------------------------------------------------------------------+
|
|
|
15 | Author: Thomas Bruederli <roundcube@gmail.com> |
|
|
|
16 +-----------------------------------------------------------------------+
|
|
|
17 */
|
|
|
18
|
|
|
19 /**
|
|
|
20 * Roundcube result set class
|
|
|
21 *
|
|
|
22 * Representing an address directory result set.
|
|
|
23 * Implenets Iterator and thus be used in foreach() loops.
|
|
|
24 *
|
|
|
25 * @package Framework
|
|
|
26 * @subpackage Addressbook
|
|
|
27 */
|
|
|
28 class rcube_result_set implements Iterator, ArrayAccess
|
|
|
29 {
|
|
|
30 public $count = 0;
|
|
|
31 public $first = 0;
|
|
|
32 public $searchonly = false;
|
|
|
33 public $records = array();
|
|
|
34
|
|
|
35 private $current = 0;
|
|
|
36
|
|
|
37 function __construct($c=0, $f=0)
|
|
|
38 {
|
|
|
39 $this->count = (int)$c;
|
|
|
40 $this->first = (int)$f;
|
|
|
41 }
|
|
|
42
|
|
|
43 function add($rec)
|
|
|
44 {
|
|
|
45 $this->records[] = $rec;
|
|
|
46 }
|
|
|
47
|
|
|
48 function iterate()
|
|
|
49 {
|
|
25
|
50 $current = $this->current();
|
|
|
51
|
|
|
52 $this->current++;
|
|
|
53
|
|
|
54 return $current;
|
|
0
|
55 }
|
|
|
56
|
|
|
57 function first()
|
|
|
58 {
|
|
|
59 $this->current = 0;
|
|
|
60 return $this->records[$this->current];
|
|
|
61 }
|
|
|
62
|
|
|
63 function seek($i)
|
|
|
64 {
|
|
|
65 $this->current = $i;
|
|
|
66 }
|
|
|
67
|
|
|
68 /*** Implement PHP ArrayAccess interface ***/
|
|
|
69
|
|
22
|
70 public function offsetSet(mixed $offset,mixed $value): void
|
|
0
|
71 {
|
|
|
72 if (is_null($offset)) {
|
|
|
73 $offset = count($this->records);
|
|
|
74 $this->records[] = $value;
|
|
|
75 }
|
|
|
76 else {
|
|
|
77 $this->records[$offset] = $value;
|
|
|
78 }
|
|
|
79 }
|
|
|
80
|
|
22
|
81 public function offsetExists(mixed $offset): bool
|
|
0
|
82 {
|
|
|
83 return isset($this->records[$offset]);
|
|
|
84 }
|
|
|
85
|
|
22
|
86 public function offsetUnset(mixed $offset): void
|
|
0
|
87 {
|
|
|
88 unset($this->records[$offset]);
|
|
|
89 }
|
|
|
90
|
|
25
|
91 public function offsetGet(mixed $offset): mixed
|
|
0
|
92 {
|
|
|
93 return $this->records[$offset];
|
|
|
94 }
|
|
|
95
|
|
|
96 /*** PHP 5 Iterator interface ***/
|
|
|
97
|
|
22
|
98 function rewind(): void
|
|
0
|
99 {
|
|
|
100 $this->current = 0;
|
|
|
101 }
|
|
|
102
|
|
22
|
103 function current(): mixed
|
|
0
|
104 {
|
|
25
|
105 return ($this->records[$this->current]??null);
|
|
0
|
106 }
|
|
|
107
|
|
22
|
108 function key(): mixed
|
|
0
|
109 {
|
|
|
110 return $this->current;
|
|
|
111 }
|
|
|
112
|
|
22
|
113 #[ReturnTypeWillChange]
|
|
0
|
114 function next()
|
|
|
115 {
|
|
|
116 return $this->iterate();
|
|
|
117 }
|
|
|
118
|
|
22
|
119 function valid(): bool
|
|
0
|
120 {
|
|
|
121 return isset($this->records[$this->current]);
|
|
|
122 }
|
|
|
123 }
|