94 lines
2.3 KiB
PHP
94 lines
2.3 KiB
PHP
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||
|
|
||
|
/**
|
||
|
* Kohana ORM LDAP Extension
|
||
|
*
|
||
|
* @package LDAP/ORM
|
||
|
* @category Helpers
|
||
|
* @author Deon George
|
||
|
* @copyright (c) 2013 phpLDAPadmin Development Team
|
||
|
* @license http://dev.phpldapadmin.org/license.html
|
||
|
*/
|
||
|
abstract class Kohana_ORM_LDAP extends ORM {
|
||
|
protected $_disable_wild_select = TRUE;
|
||
|
protected $_disable_join_table_name = TRUE;
|
||
|
protected $_primary_key = 'dn';
|
||
|
|
||
|
public function __construct($id = NULL) {
|
||
|
// We'll process our $id
|
||
|
parent::__construct(NULL);
|
||
|
|
||
|
if (empty($this->_cast_data) AND $id) {
|
||
|
if (is_array($id)) {
|
||
|
// Passing an array of column => values
|
||
|
foreach ($id as $column => $value)
|
||
|
$this->where($column, '=', $value);
|
||
|
|
||
|
$this->find();
|
||
|
|
||
|
} else {
|
||
|
// Passing the primary key
|
||
|
$this->base($id)->find();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Initializes the Database Builder to given query type
|
||
|
*
|
||
|
* @param integer $type Type of Database query
|
||
|
* @return ORM
|
||
|
*/
|
||
|
protected function _build($type) {
|
||
|
// Construct new builder object based on query type
|
||
|
switch ($type) {
|
||
|
case Database::SELECT:
|
||
|
$this->_db_builder = new Database_LDAP_Search($this->_db,NULL);
|
||
|
break;
|
||
|
|
||
|
default:
|
||
|
throw HTTP_Exception::factory(501,'Unknown type :type',array(':type'=>$type));
|
||
|
}
|
||
|
|
||
|
// Process pending database method calls
|
||
|
foreach ($this->_db_pending as $method) {
|
||
|
$name = $method['name'];
|
||
|
$args = $method['args'];
|
||
|
|
||
|
$this->_db_applied[$name] = $name;
|
||
|
|
||
|
call_user_func_array(array($this->_db_builder, $name), $args);
|
||
|
}
|
||
|
|
||
|
return $this;
|
||
|
}
|
||
|
|
||
|
protected function _initialize() {
|
||
|
parent::_initialize();
|
||
|
|
||
|
// Check if this model has already been initialized
|
||
|
if ($init = Arr::get(ORM::$_init_cache, $this->_object_name, FALSE)) {
|
||
|
|
||
|
// We need to make sure that our _db is an LDAP DB source.
|
||
|
if ( ! is_object($this->_db) OR ! $this->_db instanceof LDAP) {
|
||
|
// Get database instance
|
||
|
$init['_db'] = LDAP::factory('user',NULL,$this->_db_group);
|
||
|
}
|
||
|
|
||
|
ORM::$_init_cache[$this->_object_name] = $init;
|
||
|
$this->_db = $init['_db'];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public function base($value) {
|
||
|
// Add pending database call which is executed after query type is determined
|
||
|
$this->_db_pending[] = array(
|
||
|
'name' => 'base',
|
||
|
'args' => array(array($value)),
|
||
|
);
|
||
|
|
||
|
return $this;
|
||
|
}
|
||
|
}
|
||
|
?>
|