• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List

E:/E/GEAMP/www/openbiz/openbiz/others/Zend/Db/Table/Row/Abstract.php

00001 <?php
00026 require_once 'Zend/Db.php';
00027 
00035 abstract class Zend_Db_Table_Row_Abstract implements ArrayAccess
00036 {
00037 
00045     protected $_data = array();
00046 
00054     protected $_cleanData = array();
00055 
00062     protected $_modifiedFields = array();
00063 
00069     protected $_table = null;
00070 
00078     protected $_connected = true;
00079 
00087     protected $_readOnly = false;
00088 
00094     protected $_tableClass = null;
00095 
00101     protected $_primary;
00102 
00114     public function __construct(array $config = array())
00115     {
00116         if (isset($config['table']) && $config['table'] instanceof Zend_Db_Table_Abstract) {
00117             $this->_table = $config['table'];
00118             $this->_tableClass = get_class($this->_table);
00119         } elseif ($this->_tableClass !== null) {
00120             $this->_table = $this->_getTableFromString($this->_tableClass);
00121         }
00122 
00123         if (isset($config['data'])) {
00124             if (!is_array($config['data'])) {
00125                 require_once 'Zend/Db/Table/Row/Exception.php';
00126                 throw new Zend_Db_Table_Row_Exception('Data must be an array');
00127             }
00128             $this->_data = $config['data'];
00129         }
00130         if (isset($config['stored']) && $config['stored'] === true) {
00131             $this->_cleanData = $this->_data;
00132         }
00133 
00134         if (isset($config['readOnly']) && $config['readOnly'] === true) {
00135             $this->setReadOnly(true);
00136         }
00137 
00138         // Retrieve primary keys from table schema
00139         if (($table = $this->_getTable())) {
00140             $info = $table->info();
00141             $this->_primary = (array) $info['primary'];
00142         }
00143 
00144         $this->init();
00145     }
00146 
00157     protected function _transformColumn($columnName)
00158     {
00159         if (!is_string($columnName)) {
00160             require_once 'Zend/Db/Table/Row/Exception.php';
00161             throw new Zend_Db_Table_Row_Exception('Specified column is not a string');
00162         }
00163         // Perform no transformation by default
00164         return $columnName;
00165     }
00166 
00174     public function __get($columnName)
00175     {
00176         $columnName = $this->_transformColumn($columnName);
00177         if (!array_key_exists($columnName, $this->_data)) {
00178             require_once 'Zend/Db/Table/Row/Exception.php';
00179             throw new Zend_Db_Table_Row_Exception("Specified column \"$columnName\" is not in the row");
00180         }
00181         return $this->_data[$columnName];
00182     }
00183 
00192     public function __set($columnName, $value)
00193     {
00194         $columnName = $this->_transformColumn($columnName);
00195         if (!array_key_exists($columnName, $this->_data)) {
00196             require_once 'Zend/Db/Table/Row/Exception.php';
00197             throw new Zend_Db_Table_Row_Exception("Specified column \"$columnName\" is not in the row");
00198         }
00199         $this->_data[$columnName] = $value;
00200         $this->_modifiedFields[$columnName] = true;
00201     }
00202 
00210     public function __unset($columnName)
00211     {
00212         $columnName = $this->_transformColumn($columnName);
00213         if (!array_key_exists($columnName, $this->_data)) {
00214             require_once 'Zend/Db/Table/Row/Exception.php';
00215             throw new Zend_Db_Table_Row_Exception("Specified column \"$columnName\" is not in the row");
00216         }
00217         if ($this->isConnected() && in_array($columnName, $this->_table->info('primary'))) {
00218             require_once 'Zend/Db/Table/Row/Exception.php';
00219             throw new Zend_Db_Table_Row_Exception("Specified column \"$columnName\" is a primary key and should not be unset");
00220         }
00221         unset($this->_data[$columnName]);
00222         return $this;
00223     }
00224 
00231     public function __isset($columnName)
00232     {
00233         $columnName = $this->_transformColumn($columnName);
00234         return array_key_exists($columnName, $this->_data);
00235     }
00236 
00242     public function __sleep()
00243     {
00244         return array('_tableClass', '_primary', '_data', '_cleanData', '_readOnly' ,'_modifiedFields');
00245     }
00246 
00254     public function __wakeup()
00255     {
00256         $this->_connected = false;
00257     }
00258 
00266     public function offsetExists($offset)
00267     {
00268         return $this->__isset($offset);
00269     }
00270 
00278      public function offsetGet($offset)
00279      {
00280          return $this->__get($offset);
00281      }
00282 
00290      public function offsetSet($offset, $value)
00291      {
00292          $this->__set($offset, $value);
00293      }
00294 
00301      public function offsetUnset($offset)
00302      {
00303      }
00304 
00312     public function init()
00313     {
00314     }
00315 
00321     public function getTable()
00322     {
00323         return $this->_table;
00324     }
00325 
00334     public function setTable(Zend_Db_Table_Abstract $table = null)
00335     {
00336         if ($table == null) {
00337             $this->_table = null;
00338             $this->_connected = false;
00339             return false;
00340         }
00341 
00342         $tableClass = get_class($table);
00343         if (! $table instanceof $this->_tableClass) {
00344             require_once 'Zend/Db/Table/Row/Exception.php';
00345             throw new Zend_Db_Table_Row_Exception("The specified Table is of class $tableClass, expecting class to be instance of $this->_tableClass");
00346         }
00347 
00348         $this->_table = $table;
00349         $this->_tableClass = $tableClass;
00350 
00351         $info = $this->_table->info();
00352 
00353         if ($info['cols'] != array_keys($this->_data)) {
00354             require_once 'Zend/Db/Table/Row/Exception.php';
00355             throw new Zend_Db_Table_Row_Exception('The specified Table does not have the same columns as the Row');
00356         }
00357 
00358         if (! array_intersect((array) $this->_primary, $info['primary']) == (array) $this->_primary) {
00359 
00360             require_once 'Zend/Db/Table/Row/Exception.php';
00361             throw new Zend_Db_Table_Row_Exception("The specified Table '$tableClass' does not have the same primary key as the Row");
00362         }
00363 
00364         $this->_connected = true;
00365         return true;
00366     }
00367 
00374     public function getTableClass()
00375     {
00376         return $this->_tableClass;
00377     }
00378 
00384     public function isConnected()
00385     {
00386         return $this->_connected;
00387     }
00388 
00394     public function isReadOnly()
00395     {
00396         return $this->_readOnly;
00397     }
00398 
00405     public function setReadOnly($flag)
00406     {
00407         $this->_readOnly = (bool) $flag;
00408     }
00409 
00415     public function select()
00416     {
00417         return $this->getTable()->select();
00418     }
00419 
00429     public function save()
00430     {
00436         if (empty($this->_cleanData)) {
00437             return $this->_doInsert();
00438         } else {
00439             return $this->_doUpdate();
00440         }
00441     }
00442 
00447     protected function _doInsert()
00448     {
00452         if ($this->_readOnly === true) {
00453             require_once 'Zend/Db/Table/Row/Exception.php';
00454             throw new Zend_Db_Table_Row_Exception('This row has been marked read-only');
00455         }
00456 
00460         $this->_insert();
00461 
00465         $data = array_intersect_key($this->_data, $this->_modifiedFields);
00466         $primaryKey = $this->_getTable()->insert($data);
00467 
00472         if (is_array($primaryKey)) {
00473             $newPrimaryKey = $primaryKey;
00474         } else {
00475             //ZF-6167 Use tempPrimaryKey temporary to avoid that zend encoding fails.
00476             $tempPrimaryKey = (array) $this->_primary;
00477             $newPrimaryKey = array(current($tempPrimaryKey) => $primaryKey);
00478         }
00479 
00486         $this->_data = array_merge($this->_data, $newPrimaryKey);
00487 
00491         $this->_postInsert();
00492 
00496         $this->_refresh();
00497 
00498         return $primaryKey;
00499     }
00500 
00505     protected function _doUpdate()
00506     {
00510         if ($this->_readOnly === true) {
00511             require_once 'Zend/Db/Table/Row/Exception.php';
00512             throw new Zend_Db_Table_Row_Exception('This row has been marked read-only');
00513         }
00514 
00519         $where = $this->_getWhereQuery(false);
00520 
00524         $this->_update();
00525 
00530         $diffData = array_intersect_key($this->_data, $this->_modifiedFields);
00531 
00535         $pkDiffData = array_intersect_key($diffData, array_flip((array)$this->_primary));
00536 
00541         if (count($pkDiffData) > 0) {
00542             $depTables = $this->_getTable()->getDependentTables();
00543             if (!empty($depTables)) {
00544                 $pkNew = $this->_getPrimaryKey(true);
00545                 $pkOld = $this->_getPrimaryKey(false);
00546                 foreach ($depTables as $tableClass) {
00547                     $t = $this->_getTableFromString($tableClass);
00548                     $t->_cascadeUpdate($this->getTableClass(), $pkOld, $pkNew);
00549                 }
00550             }
00551         }
00552 
00559         if (count($diffData) > 0) {
00560             $this->_getTable()->update($diffData, $where);
00561         }
00562 
00568         $this->_postUpdate();
00569 
00574         $this->_refresh();
00575 
00581         $primaryKey = $this->_getPrimaryKey(true);
00582         if (count($primaryKey) == 1) {
00583             return current($primaryKey);
00584         }
00585 
00586         return $primaryKey;
00587     }
00588 
00594     public function delete()
00595     {
00599         if ($this->_readOnly === true) {
00600             require_once 'Zend/Db/Table/Row/Exception.php';
00601             throw new Zend_Db_Table_Row_Exception('This row has been marked read-only');
00602         }
00603 
00604         $where = $this->_getWhereQuery();
00605 
00609         $this->_delete();
00610 
00614         $depTables = $this->_getTable()->getDependentTables();
00615         if (!empty($depTables)) {
00616             $pk = $this->_getPrimaryKey();
00617             foreach ($depTables as $tableClass) {
00618                 $t = $this->_getTableFromString($tableClass);
00619                 $t->_cascadeDelete($this->getTableClass(), $pk);
00620             }
00621         }
00622 
00626         $result = $this->_getTable()->delete($where);
00627 
00631         $this->_postDelete();
00632 
00636         $this->_data = array_combine(
00637             array_keys($this->_data),
00638             array_fill(0, count($this->_data), null)
00639         );
00640 
00641         return $result;
00642     }
00643 
00649     public function toArray()
00650     {
00651         return (array)$this->_data;
00652     }
00653 
00660     public function setFromArray(array $data)
00661     {
00662         $data = array_intersect_key($data, $this->_data);
00663 
00664         foreach ($data as $columnName => $value) {
00665             $this->__set($columnName, $value);
00666         }
00667 
00668         return $this;
00669     }
00670 
00676     public function refresh()
00677     {
00678         return $this->_refresh();
00679     }
00680 
00686     protected function _getTable()
00687     {
00688         if (!$this->_connected) {
00689             require_once 'Zend/Db/Table/Row/Exception.php';
00690             throw new Zend_Db_Table_Row_Exception('Cannot save a Row unless it is connected');
00691         }
00692         return $this->_table;
00693     }
00694 
00701     protected function _getPrimaryKey($useDirty = true)
00702     {
00703         if (!is_array($this->_primary)) {
00704             require_once 'Zend/Db/Table/Row/Exception.php';
00705             throw new Zend_Db_Table_Row_Exception("The primary key must be set as an array");
00706         }
00707 
00708         $primary = array_flip($this->_primary);
00709         if ($useDirty) {
00710             $array = array_intersect_key($this->_data, $primary);
00711         } else {
00712             $array = array_intersect_key($this->_cleanData, $primary);
00713         }
00714         if (count($primary) != count($array)) {
00715             require_once 'Zend/Db/Table/Row/Exception.php';
00716             throw new Zend_Db_Table_Row_Exception("The specified Table '$this->_tableClass' does not have the same primary key as the Row");
00717         }
00718         return $array;
00719     }
00720 
00727     protected function _getWhereQuery($useDirty = true)
00728     {
00729         $where = array();
00730         $db = $this->_getTable()->getAdapter();
00731         $primaryKey = $this->_getPrimaryKey($useDirty);
00732         $info = $this->_getTable()->info();
00733         $metadata = $info[Zend_Db_Table_Abstract::METADATA];
00734 
00735         // retrieve recently updated row using primary keys
00736         $where = array();
00737         foreach ($primaryKey as $column => $value) {
00738             $tableName = $db->quoteIdentifier($info[Zend_Db_Table_Abstract::NAME], true);
00739             $type = $metadata[$column]['DATA_TYPE'];
00740             $columnName = $db->quoteIdentifier($column, true);
00741             $where[] = $db->quoteInto("{$tableName}.{$columnName} = ?", $value, $type);
00742         }
00743         return $where;
00744     }
00745 
00751     protected function _refresh()
00752     {
00753         $where = $this->_getWhereQuery();
00754         $row = $this->_getTable()->fetchRow($where);
00755 
00756         if (null === $row) {
00757             require_once 'Zend/Db/Table/Row/Exception.php';
00758             throw new Zend_Db_Table_Row_Exception('Cannot refresh row as parent is missing');
00759         }
00760 
00761         $this->_data = $row->toArray();
00762         $this->_cleanData = $this->_data;
00763         $this->_modifiedFields = array();
00764     }
00765 
00772     protected function _insert()
00773     {
00774     }
00775 
00782     protected function _postInsert()
00783     {
00784     }
00785 
00792     protected function _update()
00793     {
00794     }
00795 
00802     protected function _postUpdate()
00803     {
00804     }
00805 
00812     protected function _delete()
00813     {
00814     }
00815 
00822     protected function _postDelete()
00823     {
00824     }
00825 
00836     protected function _prepareReference(Zend_Db_Table_Abstract $dependentTable, Zend_Db_Table_Abstract $parentTable, $ruleKey)
00837     {
00838         $parentTableName = (get_class($parentTable) === 'Zend_Db_Table') ? $parentTable->getDefinitionConfigName() : get_class($parentTable);
00839         $map = $dependentTable->getReference($parentTableName, $ruleKey);
00840 
00841         if (!isset($map[Zend_Db_Table_Abstract::REF_COLUMNS])) {
00842             $parentInfo = $parentTable->info();
00843             $map[Zend_Db_Table_Abstract::REF_COLUMNS] = array_values((array) $parentInfo['primary']);
00844         }
00845 
00846         $map[Zend_Db_Table_Abstract::COLUMNS] = (array) $map[Zend_Db_Table_Abstract::COLUMNS];
00847         $map[Zend_Db_Table_Abstract::REF_COLUMNS] = (array) $map[Zend_Db_Table_Abstract::REF_COLUMNS];
00848 
00849         return $map;
00850     }
00851 
00861     public function findDependentRowset($dependentTable, $ruleKey = null, Zend_Db_Table_Select $select = null)
00862     {
00863         $db = $this->_getTable()->getAdapter();
00864 
00865         if (is_string($dependentTable)) {
00866             $dependentTable = $this->_getTableFromString($dependentTable);
00867         }
00868 
00869         if (!$dependentTable instanceof Zend_Db_Table_Abstract) {
00870             $type = gettype($dependentTable);
00871             if ($type == 'object') {
00872                 $type = get_class($dependentTable);
00873             }
00874             require_once 'Zend/Db/Table/Row/Exception.php';
00875             throw new Zend_Db_Table_Row_Exception("Dependent table must be a Zend_Db_Table_Abstract, but it is $type");
00876         }
00877 
00878         // even if we are interacting between a table defined in a class and a
00879         // table via extension, ensure to persist the definition
00880         if (($tableDefinition = $this->_table->getDefinition()) !== null
00881             && ($dependentTable->getDefinition() == null)) {
00882             $dependentTable->setOptions(array(Zend_Db_Table_Abstract::DEFINITION => $tableDefinition));
00883         }
00884 
00885         if ($select === null) {
00886             $select = $dependentTable->select();
00887         } else {
00888             $select->setTable($dependentTable);
00889         }
00890 
00891         $map = $this->_prepareReference($dependentTable, $this->_getTable(), $ruleKey);
00892 
00893         for ($i = 0; $i < count($map[Zend_Db_Table_Abstract::COLUMNS]); ++$i) {
00894             $parentColumnName = $db->foldCase($map[Zend_Db_Table_Abstract::REF_COLUMNS][$i]);
00895             $value = $this->_data[$parentColumnName];
00896             // Use adapter from dependent table to ensure correct query construction
00897             $dependentDb = $dependentTable->getAdapter();
00898             $dependentColumnName = $dependentDb->foldCase($map[Zend_Db_Table_Abstract::COLUMNS][$i]);
00899             $dependentColumn = $dependentDb->quoteIdentifier($dependentColumnName, true);
00900             $dependentInfo = $dependentTable->info();
00901             $type = $dependentInfo[Zend_Db_Table_Abstract::METADATA][$dependentColumnName]['DATA_TYPE'];
00902             $select->where("$dependentColumn = ?", $value, $type);
00903         }
00904 
00905         return $dependentTable->fetchAll($select);
00906     }
00907 
00917     public function findParentRow($parentTable, $ruleKey = null, Zend_Db_Table_Select $select = null)
00918     {
00919         $db = $this->_getTable()->getAdapter();
00920 
00921         if (is_string($parentTable)) {
00922             $parentTable = $this->_getTableFromString($parentTable);
00923         }
00924 
00925         if (!$parentTable instanceof Zend_Db_Table_Abstract) {
00926             $type = gettype($parentTable);
00927             if ($type == 'object') {
00928                 $type = get_class($parentTable);
00929             }
00930             require_once 'Zend/Db/Table/Row/Exception.php';
00931             throw new Zend_Db_Table_Row_Exception("Parent table must be a Zend_Db_Table_Abstract, but it is $type");
00932         }
00933 
00934         // even if we are interacting between a table defined in a class and a
00935         // table via extension, ensure to persist the definition
00936         if (($tableDefinition = $this->_table->getDefinition()) !== null
00937             && ($parentTable->getDefinition() == null)) {
00938             $parentTable->setOptions(array(Zend_Db_Table_Abstract::DEFINITION => $tableDefinition));
00939         }
00940 
00941         if ($select === null) {
00942             $select = $parentTable->select();
00943         } else {
00944             $select->setTable($parentTable);
00945         }
00946 
00947         $map = $this->_prepareReference($this->_getTable(), $parentTable, $ruleKey);
00948 
00949         // iterate the map, creating the proper wheres
00950         for ($i = 0; $i < count($map[Zend_Db_Table_Abstract::COLUMNS]); ++$i) {
00951             $dependentColumnName = $db->foldCase($map[Zend_Db_Table_Abstract::COLUMNS][$i]);
00952             $value = $this->_data[$dependentColumnName];
00953             // Use adapter from parent table to ensure correct query construction
00954             $parentDb = $parentTable->getAdapter();
00955             $parentColumnName = $parentDb->foldCase($map[Zend_Db_Table_Abstract::REF_COLUMNS][$i]);
00956             $parentColumn = $parentDb->quoteIdentifier($parentColumnName, true);
00957             $parentInfo = $parentTable->info();
00958 
00959             // determine where part
00960             $type     = $parentInfo[Zend_Db_Table_Abstract::METADATA][$parentColumnName]['DATA_TYPE'];
00961             $nullable = $parentInfo[Zend_Db_Table_Abstract::METADATA][$parentColumnName]['NULLABLE'];
00962             if ($value === null && $nullable == true) {
00963                 $select->where("$parentColumn IS NULL");
00964             } elseif ($value === null && $nullable == false) {
00965                 return null;
00966             } else {
00967                 $select->where("$parentColumn = ?", $value, $type);
00968             }
00969 
00970         }
00971 
00972         return $parentTable->fetchRow($select);
00973     }
00974 
00984     public function findManyToManyRowset($matchTable, $intersectionTable, $callerRefRule = null,
00985                                          $matchRefRule = null, Zend_Db_Table_Select $select = null)
00986     {
00987         $db = $this->_getTable()->getAdapter();
00988 
00989         if (is_string($intersectionTable)) {
00990             $intersectionTable = $this->_getTableFromString($intersectionTable);
00991         }
00992 
00993         if (!$intersectionTable instanceof Zend_Db_Table_Abstract) {
00994             $type = gettype($intersectionTable);
00995             if ($type == 'object') {
00996                 $type = get_class($intersectionTable);
00997             }
00998             require_once 'Zend/Db/Table/Row/Exception.php';
00999             throw new Zend_Db_Table_Row_Exception("Intersection table must be a Zend_Db_Table_Abstract, but it is $type");
01000         }
01001 
01002         // even if we are interacting between a table defined in a class and a
01003         // table via extension, ensure to persist the definition
01004         if (($tableDefinition = $this->_table->getDefinition()) !== null
01005             && ($intersectionTable->getDefinition() == null)) {
01006             $intersectionTable->setOptions(array(Zend_Db_Table_Abstract::DEFINITION => $tableDefinition));
01007         }
01008 
01009         if (is_string($matchTable)) {
01010             $matchTable = $this->_getTableFromString($matchTable);
01011         }
01012 
01013         if (! $matchTable instanceof Zend_Db_Table_Abstract) {
01014             $type = gettype($matchTable);
01015             if ($type == 'object') {
01016                 $type = get_class($matchTable);
01017             }
01018             require_once 'Zend/Db/Table/Row/Exception.php';
01019             throw new Zend_Db_Table_Row_Exception("Match table must be a Zend_Db_Table_Abstract, but it is $type");
01020         }
01021 
01022         // even if we are interacting between a table defined in a class and a
01023         // table via extension, ensure to persist the definition
01024         if (($tableDefinition = $this->_table->getDefinition()) !== null
01025             && ($matchTable->getDefinition() == null)) {
01026             $matchTable->setOptions(array(Zend_Db_Table_Abstract::DEFINITION => $tableDefinition));
01027         }
01028 
01029         if ($select === null) {
01030             $select = $matchTable->select();
01031         } else {
01032             $select->setTable($matchTable);
01033         }
01034 
01035         // Use adapter from intersection table to ensure correct query construction
01036         $interInfo = $intersectionTable->info();
01037         $interDb   = $intersectionTable->getAdapter();
01038         $interName = $interInfo['name'];
01039         $interSchema = isset($interInfo['schema']) ? $interInfo['schema'] : null;
01040         $matchInfo = $matchTable->info();
01041         $matchName = $matchInfo['name'];
01042         $matchSchema = isset($matchInfo['schema']) ? $matchInfo['schema'] : null;
01043 
01044         $matchMap = $this->_prepareReference($intersectionTable, $matchTable, $matchRefRule);
01045 
01046         for ($i = 0; $i < count($matchMap[Zend_Db_Table_Abstract::COLUMNS]); ++$i) {
01047             $interCol = $interDb->quoteIdentifier('i' . '.' . $matchMap[Zend_Db_Table_Abstract::COLUMNS][$i], true);
01048             $matchCol = $interDb->quoteIdentifier('m' . '.' . $matchMap[Zend_Db_Table_Abstract::REF_COLUMNS][$i], true);
01049             $joinCond[] = "$interCol = $matchCol";
01050         }
01051         $joinCond = implode(' AND ', $joinCond);
01052 
01053         $select->from(array('i' => $interName), Zend_Db_Select::SQL_WILDCARD, $interSchema)
01054                ->joinInner(array('m' => $matchName), $joinCond, Zend_Db_Select::SQL_WILDCARD, $matchSchema)
01055                ->setIntegrityCheck(false);
01056 
01057         $callerMap = $this->_prepareReference($intersectionTable, $this->_getTable(), $callerRefRule);
01058 
01059         for ($i = 0; $i < count($callerMap[Zend_Db_Table_Abstract::COLUMNS]); ++$i) {
01060             $callerColumnName = $db->foldCase($callerMap[Zend_Db_Table_Abstract::REF_COLUMNS][$i]);
01061             $value = $this->_data[$callerColumnName];
01062             $interColumnName = $interDb->foldCase($callerMap[Zend_Db_Table_Abstract::COLUMNS][$i]);
01063             $interCol = $interDb->quoteIdentifier("i.$interColumnName", true);
01064             $interInfo = $intersectionTable->info();
01065             $type = $interInfo[Zend_Db_Table_Abstract::METADATA][$interColumnName]['DATA_TYPE'];
01066             $select->where($interDb->quoteInto("$interCol = ?", $value, $type));
01067         }
01068 
01069         $stmt = $select->query();
01070 
01071         $config = array(
01072             'table'    => $matchTable,
01073             'data'     => $stmt->fetchAll(Zend_Db::FETCH_ASSOC),
01074             'rowClass' => $matchTable->getRowClass(),
01075             'readOnly' => false,
01076             'stored'   => true
01077         );
01078 
01079         $rowsetClass = $matchTable->getRowsetClass();
01080         if (!class_exists($rowsetClass)) {
01081             try {
01082                 require_once 'Zend/Loader.php';
01083                 Zend_Loader::loadClass($rowsetClass);
01084             } catch (Zend_Exception $e) {
01085                 require_once 'Zend/Db/Table/Row/Exception.php';
01086                 throw new Zend_Db_Table_Row_Exception($e->getMessage());
01087             }
01088         }
01089         $rowset = new $rowsetClass($config);
01090         return $rowset;
01091     }
01092 
01102     public function __call($method, array $args)
01103     {
01104         $matches = array();
01105 
01106         if (count($args) && $args[0] instanceof Zend_Db_Table_Select) {
01107             $select = $args[0];
01108         } else {
01109             $select = null;
01110         }
01111 
01118         if (preg_match('/^findParent(\w+?)(?:By(\w+))?$/', $method, $matches)) {
01119             $class    = $matches[1];
01120             $ruleKey1 = isset($matches[2]) ? $matches[2] : null;
01121             return $this->findParentRow($class, $ruleKey1, $select);
01122         }
01123 
01131         if (preg_match('/^find(\w+?)Via(\w+?)(?:By(\w+?)(?:And(\w+))?)?$/', $method, $matches)) {
01132             $class    = $matches[1];
01133             $viaClass = $matches[2];
01134             $ruleKey1 = isset($matches[3]) ? $matches[3] : null;
01135             $ruleKey2 = isset($matches[4]) ? $matches[4] : null;
01136             return $this->findManyToManyRowset($class, $viaClass, $ruleKey1, $ruleKey2, $select);
01137         }
01138 
01145         if (preg_match('/^find(\w+?)(?:By(\w+))?$/', $method, $matches)) {
01146             $class    = $matches[1];
01147             $ruleKey1 = isset($matches[2]) ? $matches[2] : null;
01148             return $this->findDependentRowset($class, $ruleKey1, $select);
01149         }
01150 
01151         require_once 'Zend/Db/Table/Row/Exception.php';
01152         throw new Zend_Db_Table_Row_Exception("Unrecognized method '$method()'");
01153     }
01154 
01155 
01162     protected function _getTableFromString($tableName)
01163     {
01164 
01165         if ($this->_table instanceof Zend_Db_Table_Abstract) {
01166             $tableDefinition = $this->_table->getDefinition();
01167 
01168             if ($tableDefinition !== null && $tableDefinition->hasTableConfig($tableName)) {
01169                 return new Zend_Db_Table($tableName, $tableDefinition);
01170             }
01171         }
01172 
01173         // assume the tableName is the class name
01174         if (!class_exists($tableName)) {
01175             try {
01176                 require_once 'Zend/Loader.php';
01177                 Zend_Loader::loadClass($tableName);
01178             } catch (Zend_Exception $e) {
01179                 require_once 'Zend/Db/Table/Row/Exception.php';
01180                 throw new Zend_Db_Table_Row_Exception($e->getMessage());
01181             }
01182         }
01183 
01184         $options = array();
01185 
01186         if (($table = $this->_getTable())) {
01187             $options['db'] = $table->getAdapter();
01188         }
01189 
01190         if (isset($tableDefinition) && $tableDefinition !== null) {
01191             $options[Zend_Db_Table_Abstract::DEFINITION] = $tableDefinition;
01192         }
01193 
01194         return new $tableName($options);
01195     }
01196 
01197 }

Generated on Thu Apr 19 2012 17:01:17 for openbiz by  doxygen 1.7.2