You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rcube_result_set.php 2.8KB

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