Apache Zeta Components Manual :: File Source for db.php
Source for file db.php
Documentation is available at db.php
* File containing the ezcTreeDb class.
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
* @version //autogentag//
* @package TreeDatabaseTiein
* ezcTreeDb contains common methods for the different database tree backends.
* @property-read ezcTreeDbDataStore $store
* The data store that is used for retrieving/storing data.
* @property string $nodeClassName
* Which class is used as tree node - this class *must* inherit
* @package TreeDatabaseTiein
* @version //autogentag//
* Contains the database connection handler.
* Contains the name of the table to retrieve the relational data from.
* Constructs a new ezcTreeDb object.
* The different arguments to the constructor configure which database
* connection ($dbh) is used to access the database and the $indexTableName
* argument which table is used to retrieve the relation data from. The
* $store argument configure which data store is used with this tree.
* All database backends require the index table to at least define the
* field 'id', which can either be a string or an integer field.
* @param ezcDbHandler $dbh
* @param string $indexTableName
* @param ezcTreeDbDataStore $store
public function __construct( ezcDbHandler $dbh, $indexTableName, ezcTreeDbDataStore $store )
* Creates the query to insert an empty node into the database, so that the last-inserted ID can be obtained.
* Creates the query to insert/update an empty node in the database.
* The query is constructed for the child with ID $id
$q =
$db->createUpdateQuery();
->where( $q->expr->eq( 'id', $q->bindValue( $id ) ) );
$q =
$db->createInsertQuery();
* This method generates the next node ID.
* It does so by inserting a new empty node into the database, and uses
* lastInsertId() to obtain the ID for the newly inserted node.
catch
( PDOException $e )
* Returns whether the node with ID $id exists as tree node.
$q =
$db->createSelectQuery();
->where( $q->expr->eq( 'id', $q->bindValue( $id ) ) );
return count( $s->fetchAll() ) ?
true :
false;
* Returns the ID of parent of the node with ID $childId.
$q =
$db->createSelectQuery();
$q->select( 'id, parent_id' )
->where( $q->expr->eq( 'id', $q->bindValue( $childId ) ) );
return $row['parent_id'];
* Returns the parent node of the node with ID $id.
* This method returns null if there is no parent node.
return $parentId !==
null ?
new $className( $this, $parentId ) :
null;
* This methods returns null if there is no root node.
$q =
$db->createSelectQuery();
->where( $q->expr->isNull( 'parent_id' ) );
$r =
$s->fetchAll( PDO::FETCH_ASSOC );
return new $className( $this, $r[0]['id'] );