commit | author | age
|
47124c
|
1 |
<?php |
T |
2 |
|
a95874
|
3 |
/** |
47124c
|
4 |
+-----------------------------------------------------------------------+ |
e019f2
|
5 |
| This file is part of the Roundcube Webmail client | |
1cf15e
|
6 |
| Copyright (C) 2006-2013, The Roundcube Dev Team | |
7fe381
|
7 |
| | |
T |
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. | |
47124c
|
11 |
| | |
T |
12 |
| PURPOSE: | |
|
13 |
| Class representing an address directory result set | |
|
14 |
+-----------------------------------------------------------------------+ |
|
15 |
| Author: Thomas Bruederli <roundcube@gmail.com> | |
|
16 |
+-----------------------------------------------------------------------+ |
|
17 |
*/ |
|
18 |
|
|
19 |
/** |
1cf15e
|
20 |
* Roundcube result set class |
TB |
21 |
* |
47124c
|
22 |
* Representing an address directory result set. |
1cf15e
|
23 |
* Implenets Iterator and thus be used in foreach() loops. |
47124c
|
24 |
* |
9ab346
|
25 |
* @package Framework |
AM |
26 |
* @subpackage Addressbook |
47124c
|
27 |
*/ |
143cef
|
28 |
class rcube_result_set implements Iterator, ArrayAccess |
47124c
|
29 |
{ |
1cf15e
|
30 |
public $count = 0; |
TB |
31 |
public $first = 0; |
|
32 |
public $searchonly = false; |
|
33 |
public $records = array(); |
2eb794
|
34 |
|
1cf15e
|
35 |
private $current = 0; |
2eb794
|
36 |
|
A |
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 |
} |
e9a9f2
|
47 |
|
2eb794
|
48 |
function iterate() |
A |
49 |
{ |
|
50 |
return $this->records[$this->current++]; |
|
51 |
} |
e9a9f2
|
52 |
|
2eb794
|
53 |
function first() |
A |
54 |
{ |
|
55 |
$this->current = 0; |
1cf15e
|
56 |
return $this->records[$this->current]; |
2eb794
|
57 |
} |
e9a9f2
|
58 |
|
2eb794
|
59 |
function seek($i) |
A |
60 |
{ |
|
61 |
$this->current = $i; |
|
62 |
} |
e9a9f2
|
63 |
|
143cef
|
64 |
/*** Implement PHP ArrayAccess interface ***/ |
TB |
65 |
|
|
66 |
public function offsetSet($offset, $value) |
|
67 |
{ |
|
68 |
if (is_null($offset)) { |
|
69 |
$offset = count($this->records); |
|
70 |
$this->records[] = $value; |
|
71 |
} |
|
72 |
else { |
|
73 |
$this->records[$offset] = $value; |
|
74 |
} |
|
75 |
} |
|
76 |
|
|
77 |
public function offsetExists($offset) |
|
78 |
{ |
|
79 |
return isset($this->records[$offset]); |
|
80 |
} |
|
81 |
|
|
82 |
public function offsetUnset($offset) |
|
83 |
{ |
|
84 |
unset($this->records[$offset]); |
|
85 |
} |
|
86 |
|
|
87 |
public function offsetGet($offset) |
|
88 |
{ |
|
89 |
return $this->records[$offset]; |
|
90 |
} |
|
91 |
|
1cf15e
|
92 |
/*** PHP 5 Iterator interface ***/ |
TB |
93 |
|
|
94 |
function rewind() |
|
95 |
{ |
|
96 |
$this->current = 0; |
|
97 |
} |
|
98 |
|
|
99 |
function current() |
|
100 |
{ |
|
101 |
return $this->records[$this->current]; |
|
102 |
} |
|
103 |
|
|
104 |
function key() |
|
105 |
{ |
|
106 |
return $this->current; |
|
107 |
} |
|
108 |
|
|
109 |
function next() |
|
110 |
{ |
|
111 |
return $this->iterate(); |
|
112 |
} |
|
113 |
|
|
114 |
function valid() |
|
115 |
{ |
|
116 |
return isset($this->records[$this->current]); |
|
117 |
} |
2eb794
|
118 |
} |