limit; $sr = ldap_search( $this->con , $this->config['context'] , self::parseCriteria($criteria) , $justthese , 0 , $criteria["limit"]); if(!$sr) return false; if( isset($criteria["order"]) ) ldap_sort( $this->con, $sr, $criteria["order"] ); return self::_formatEntries( ldap_get_entries( $this->con, $sr ) ); } public function read ( $uri, $justthese = false ) { if( $justthese === false || $justthese === null ) $sr = ldap_search( $this->con, $this->config['context'], '('.$this->config['idAtribute'].'='.$uri['id'].')' ); else $sr = ldap_search( $this->con, $this->config['context'], '('.$this->config['idAtribute'].'='.$uri['id'].')', $justthese ); if(!$sr) return false; $return = self::_formatEntries( ldap_get_entries( $this->con, $sr ) ); return isset($return[0]) ? $return[0] : array(); } public function deleteAll( $uri, $justthese = false, $criteria = false ){} public function delete ( $uri, $justthese = false ) { // return ldap_delete ($this->con , $this->config['context'].','.$uri['id'] ); } public function replace ( $uri, $data, $criteria = false ){} public function update ( $uri, $data ){} public function create ( $uri, $data ){} public function open ( $config ) { $this->config = $config; $this->con = ldap_connect( $config['host'] ); ldap_set_option( $this->con,LDAP_OPT_PROTOCOL_VERSION,3 ); if( isset( $config['user'] ) && isset( $config['password'] ) ) ldap_bind( $this->con, $config['user'], $config['password'] ); return( $this->con ); } public function close() { ldap_close($this->con); } public function setup(){} public function teardown(){} public function begin( $uri ){ } public function commit( $uri ){ return( true ); } public function rollback( $uri ){ } private static function _formatEntries ( $pEntries ) { if( !$pEntries ) return( false ); $return = array(); for ($i=0; $i < $pEntries["count"]; $i++) { $entrieTmp = array(); foreach ($pEntries[$i] as $index => $value) { if(!is_numeric($index) && $index != 'count') { if(is_array($value)) { if(count($value) == 2) $entrieTmp[$index] = $value['0']; else { foreach ($value as $index2 =>$value2) { if($index != 'count') $entrieTmp[$index][$index2] = $value2; } } } else $entrieTmp[$index] = $value; } } $return[] = $entrieTmp; } return( $return ); } private static function parseCriteria( $criteria ) { $result = ""; if( isset($criteria["filter"]) ) { /* * ex: array ( * [0] 'OR', * [1] array( 'OR', array( array( '=', 'campo', 'valor' ) ), * [2] array( '=', 'campo' , 'valor' ), * [3] array( 'IN', 'campo', array( '1' , '2' , '3' ) ) * ) * OR * array( '=' , 'campo' , 'valor' ) */ $result .= self::parseFilter( $criteria['filter'] ); } return $result; } private static function parseFilter( $filter ) { $result = ''; $op = self::parseOperator( array_shift( $filter ) ); if( is_array($filter[0]) ) { $nested = ''; foreach( $filter as $i => $f ) $nested .= self::parseFilter($f); $fil = $op.$nested; } else $fil = $op[0].$filter[0].$op[1].$filter[1].$op[2]; return '('.$fil.')'; } private static function parseOperator( $op ) { switch( $op ) { case 'AND': return '&'; case 'OR': return '|'; case '^': return array('', '=*', '' ); case '$': return array('', '=' , '*' ); case '*': return array('', '=*', '*' ); case '!': return array('!(', '=', ')', ); default : return array('', $op , '' ); } } } ?>