cvs: pear /Tree Common.php

From: Date: Wed, 24 Apr 2002 23:53:35 +0000
Subject: cvs: pear /Tree Common.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-3530@lists.php.net to get a copy of this message
cain Wed Apr 24 19:53:35 2002 EDT Modified files: /pear/Tree Common.php Log: - moved common methods here Index: pear/Tree/Common.php diff -u pear/Tree/Common.php:1.5 pear/Tree/Common.php:1.6 --- pear/Tree/Common.php:1.5 Wed Apr 17 16:23:04 2002 +++ pear/Tree/Common.php Wed Apr 24 19:53:35 2002 @@ -16,7 +16,7 @@ // | Authors: Wolfram Kriesing <wolfram@kriesing.de> | // +----------------------------------------------------------------------+ // -// $Id: Common.php,v 1.5 2002/04/17 20:23:04 cain Exp $ +// $Id: Common.php,v 1.6 2002/04/24 23:53:35 cain Exp $ require_once('Tree/OptionsDB.php'); @@ -39,26 +39,13 @@ { /** + * put proper value-keys are given in each class, depending on the implementation + * only some options are needed or allowed, see the classes which extend this one + * * @access public * @var array saves the options passed to the constructor */ - var $options = array( - // those keyName maps are supposed to name the keys that are used in the internal array (data) - // if you prefer different names, or your db-columns have different names - // then define them here - // be sure to set i.e. the columnNameMaps for the DB so that it works with those maps - // the default is as you see given -# FIXXME, finish this and let the user define its own key maps, use that throughout the entire class -# i didnt do it yet, since it requires quite some testing and i didnt need it yet, i just use the columnNameMaps in the DB for now -# but one fine day ... -/* 'keyNameMaps' => array( - 'id' => 'id', - 'parentId' => 'parentId', - 'prevId' => 'prevId', - 'name' => 'name' // - ) -*/ - ); + var $options = array(); /** @@ -244,6 +231,94 @@ function getLevel( $id ) { } // end of function + + + + + + + // + // PRIVATE METHODS + // + + + /** + * prepare multiple results + * + * @see _prepareResult() + * @access private + * @version 2002/03/03 + * @author Wolfram Kriesing <wolfram@kriesing.de> + * @param + * @return + */ + function _prepareResults( $results ) + { + $newResults = array(); + foreach( $results as $aResult ) + $newResults[] = $this->_prepareResult($aResult); + return $newResults; + } + + /** + * map back the index names to get what is expected + * + * @access private + * @version 2002/03/03 + * @author Wolfram Kriesing <wolfram@kriesing.de> + * @param + * @return + */ + function _prepareResult( $result ) + { + $map = $this->getOption('columnNameMaps'); + + if( $map ) + foreach( $map as $key=>$columnName ) + { + $result[$key] = $result[$columnName]; + unset($result[$columnName]); + } + return $result; + } + + /** + * this method retreives the real column name, as used in the DB + * since the internal names are fixed, to be portable between different + * DB-column namings, we map the internal name to the real column name here + * + * @access private + * @version 2002/03/02 + * @author Wolfram Kriesing <wolfram@kriesing.de> + * @param + * @return + */ + function _getColName( $internalName ) + { + if( $map = $this->getOption( 'columnNameMaps' ) ) + { + if( isset($map[$internalName]) ) + return $map[$internalName]; + } + return $internalName; + } + + /** + * + * + * @access private + * @version 2002/03/02 + * @author Wolfram Kriesing <wolfram@kriesing.de> + * @param + * @return + */ + function _throwError( $msg , $line , $mode=null ) + { + if( $mode===null && $this->debug>0 ) + $mode = PEAR_ERROR_PRINT; + return new Tree_Error( $msg , $line , __FILE__ , $mode , $this->dbh->last_query ); + } +

« previous php.pear.cvs (#3530) next »