This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
lnldap/classes/Kohana/Database/LDAP/Search/Result.php

104 lines
2.5 KiB
PHP
Raw Normal View History

2013-08-16 02:21:17 +00:00
<?php defined('SYSPATH') OR die('No direct script access.');
/**
* Return the query search result.
*
2014-02-11 00:26:11 +00:00
* @package Kohana/Database
* @category Query/Result
2013-08-16 02:21:17 +00:00
* @author Deon George
* @copyright (c) 2013 phpLDAPadmin Development Team
* @license http://dev.phpldapadmin.org/license.html
*/
abstract class Kohana_Database_LDAP_Search_Result implements ArrayAccess,Iterator,Countable {
private $_count = 0;
protected $result = array();
private $_rewound = FALSE;
private $_current_key = NULL;
/** Countable **/
public function count() {
$c = 0;
foreach ($this->result as $k=>$v)
$c += count($v);
return $c;
}
/** ArrayAccess **/
public function offsetExists($offset) {
return isset($this->result[$offset]);
}
public function offsetGet($offset) {
return $this->result[$offset];
}
public function offsetSet($offset,$value) {
if (isset($this->result[$offset]))
$this->_count -= $this->result[$offset]->count();
$this->result[$offset] = $value;
$this->_count += $value->count();
}
public function offsetUnset($offset) {
unset($this->result[$offset]);
}
/** Iterator **/
public function current() {
if (! $this->_rewound)
$this->rewind();
2015-01-09 02:58:11 +00:00
if (! is_object(current($this->result)))
throw HTTP_Exception::factory(501,'The current array is not an object');
2013-08-16 02:21:17 +00:00
return current($this->result)->current();
}
public function key() {
return current($this->result)->key();
}
public function next() {
2014-07-18 02:35:27 +00:00
// If our current entry has more valid entries, skip to the next one.
2013-08-16 02:21:17 +00:00
if (current($this->result)->valid() AND current($this->result)->next()->valid())
return current($this->result);
2014-07-18 02:35:27 +00:00
// Skip to our next record
2013-08-16 02:21:17 +00:00
next($this->result);
2014-07-18 02:35:27 +00:00
// If the next record is invalid, keep jumping to find a valid record
2013-08-16 02:21:17 +00:00
while (current($this->result) AND ! current($this->result)->valid())
if (next($this->result) === FALSE)
break;
2014-07-18 02:35:27 +00:00
// Rewind our current record
if (is_object($this->result))
current($this->result)->rewind();
2013-08-16 02:21:17 +00:00
return current($this->result);
}
public function rewind() {
2014-04-29 04:26:56 +00:00
is_resource($this->result) ? rewind($this->result) : reset($this->result);
2013-08-16 02:21:17 +00:00
2014-07-18 02:35:27 +00:00
current($this->result)->rewind();
// If our current record is invalid, skip to the next one.
2013-08-16 02:21:17 +00:00
if (! current($this->result)->valid())
$this->next(FALSE);
$this->_rewound = TRUE;
}
public function valid() {
2015-01-09 02:58:11 +00:00
return is_array(current($this->result)) ? TRUE : (is_object(current($this->result)) ? current($this->result)->valid() : FALSE);
2013-08-16 02:21:17 +00:00
}
} // End Database_LDAP_Search_Result
?>