Added object results in search, scope in search and other minor items
This commit is contained in:
parent
732ea8b978
commit
06bf21f1aa
@ -23,31 +23,33 @@ abstract class Kohana_Database_LDAP_Result extends Database_Result {
|
||||
if (! $this->_current_entry)
|
||||
return array();
|
||||
|
||||
// Return an array of the row
|
||||
// @todo We could probably cache this for optimisation
|
||||
$attrs = $vals = array();
|
||||
array_push($attrs,ldap_first_attribute($this->_result['l'],$this->_current_entry));
|
||||
|
||||
while ($x = ldap_next_attribute($this->_result['l'],$this->_current_entry))
|
||||
array_push($attrs,$x);
|
||||
|
||||
foreach ($attrs as $attr) {
|
||||
$vals[strtolower($attr)] = ldap_get_values($this->_result['l'],$this->_current_entry,$attr);
|
||||
|
||||
// We dont need the count entry
|
||||
unset($vals[strtolower($attr)]['count']);
|
||||
}
|
||||
|
||||
$vals['dn'] = $this->key();
|
||||
|
||||
if ($this->_as_object === TRUE) {
|
||||
// Return an stdClass
|
||||
throw HTTP_Exception::factory(501,'Not implemented');
|
||||
throw HTTP_Exception::factory(501,'Not implemented',array(':method'=>__METHOD__));
|
||||
|
||||
} elseif (is_string($this->_as_object)) {
|
||||
// Return an object of given class name
|
||||
throw HTTP_Exception::factory(501,'Not implemented');
|
||||
$x = new $this->_as_object;
|
||||
|
||||
return $x->result_load_values($vals);
|
||||
|
||||
} else {
|
||||
// Return an array of the row
|
||||
// @todo We could probably cache this for optimisation
|
||||
$attrs = $vals = array();
|
||||
array_push($attrs,ldap_first_attribute($this->_result['l'],$this->_current_entry));
|
||||
|
||||
while ($x = ldap_next_attribute($this->_result['l'],$this->_current_entry))
|
||||
array_push($attrs,$x);
|
||||
|
||||
foreach ($attrs as $attr) {
|
||||
$vals[strtolower($attr)] = ldap_get_values($this->_result['l'],$this->_current_entry,$attr);
|
||||
|
||||
// We dont need the count entry
|
||||
unset($vals[strtolower($attr)]['count']);
|
||||
}
|
||||
|
||||
$vals['dn'] = $this->key();
|
||||
return $vals;
|
||||
}
|
||||
}
|
||||
@ -165,17 +167,17 @@ abstract class Kohana_Database_LDAP_Result extends Database_Result {
|
||||
$result[$dn] = $row;
|
||||
|
||||
} elseif ($key === NULL) {
|
||||
throw HTTP_Exception::factory(501,'Not implemented');
|
||||
throw HTTP_Exception::factory(501,'Not implemented :method',array(':method'=>__METHOD__));
|
||||
|
||||
// Indexed columns
|
||||
|
||||
} elseif ($value === NULL) {
|
||||
throw HTTP_Exception::factory(501,'Not implemented');
|
||||
throw HTTP_Exception::factory(501,'Not implemented :method',array(':method'=>__METHOD__));
|
||||
|
||||
// Associative rows
|
||||
|
||||
} else {
|
||||
throw HTTP_Exception::factory(501,'Not implemented');
|
||||
throw HTTP_Exception::factory(501,'Not implemented :method',array(':method'=>__METHOD__));
|
||||
|
||||
// Associative columns
|
||||
}
|
||||
|
@ -30,6 +30,9 @@ abstract class Kohana_Database_LDAP_Search {
|
||||
// Parameters for __construct when using object results
|
||||
protected $_object_params = array();
|
||||
|
||||
// Return results as associative arrays or objects
|
||||
protected $_as_object = FALSE;
|
||||
|
||||
/**
|
||||
* Callable database methods
|
||||
* @var array
|
||||
@ -37,7 +40,7 @@ abstract class Kohana_Database_LDAP_Search {
|
||||
protected static $_db_methods = array(
|
||||
'where', 'and_where', 'or_where', 'where_open', 'and_where_open', 'or_where_open', 'where_close',
|
||||
'and_where_close', 'or_where_close',
|
||||
'limit',
|
||||
'limit','scope',
|
||||
);
|
||||
|
||||
/**
|
||||
@ -132,6 +135,23 @@ abstract class Kohana_Database_LDAP_Search {
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns results as objects
|
||||
*
|
||||
* @param string $class classname or TRUE for stdClass
|
||||
* @param array $params
|
||||
* @return $this
|
||||
*/
|
||||
public function as_object($class = TRUE, array $params = NULL) {
|
||||
$this->_as_object = $class;
|
||||
|
||||
// Add object parameters
|
||||
if ($params)
|
||||
$this->_object_params = $params;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Figure out the bases
|
||||
*/
|
||||
@ -188,7 +208,7 @@ abstract class Kohana_Database_LDAP_Search {
|
||||
/**
|
||||
* Search the LDAP database
|
||||
*/
|
||||
public function execute($db=NULL,$as_object=FALSE,$object_params=NULL) {
|
||||
public function execute($db=NULL,$as_object=NULL,$object_params=NULL) {
|
||||
$query = array();
|
||||
|
||||
if (! is_object($this->_db))
|
||||
|
@ -25,6 +25,8 @@ abstract class Kohana_ORM_LDAP extends ORM {
|
||||
foreach ($id as $column => $value)
|
||||
$this->where($column, '=', $value);
|
||||
|
||||
$this->limit(1);
|
||||
$this->scope('sub');
|
||||
$this->find();
|
||||
|
||||
} else {
|
||||
@ -220,9 +222,33 @@ abstract class Kohana_ORM_LDAP extends ORM {
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Kohana_Exception('The :property property does not exist in the :class class',
|
||||
array(':property' => $column, ':class' => get_class($this)));
|
||||
// The item doesnt exist.
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
public function result_load_values(array $values) {
|
||||
$this->clear();
|
||||
$this->_load_values($values);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
// @todo Taken into account the schema definition
|
||||
public function resolve($key) {
|
||||
eval("\$x = \$this->get_first('$key');");
|
||||
|
||||
return $x;
|
||||
}
|
||||
|
||||
public function scope($scope) {
|
||||
// Add pending database call which is executed after query type is determined
|
||||
$this->_db_pending[] = array(
|
||||
'name' => 'scope',
|
||||
'args' => array($scope),
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@ -13,7 +13,7 @@ class Model_LDAP_Schema extends ORM_LDAP {
|
||||
public function attribute($column) {
|
||||
$k = 'attributetypes';
|
||||
|
||||
return new Schema_Attribute(($x = $this->_attr_search($k,$column) ? $this->_object[$k][$x] : '');
|
||||
return new Schema_Attribute(($x = $this->_attr_search($k,$column)) ? $this->_object[$k][$x] : '');
|
||||
}
|
||||
|
||||
private function _attr_search($key,$column) {
|
||||
|
Reference in New Issue
Block a user