Source for file Record.php

Documentation is available at Record.php

  1. <?php
  2. /*
  3.  *  $Id$
  4.  *
  5.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  6.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  7.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  8.  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  9.  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15.  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16.  *
  17.  * This software consists of voluntary contributions made by many individuals
  18.  * and is licensed under the LGPL. For more information, see
  19.  * <http://www.phpdoctrine.com>.
  20.  */
  21.  
  22. /**
  23.  * Doctrine_Hydrate_Record
  24.  * defines a record fetching strategy for Doctrine_Hydrate
  25.  *
  26.  * @package     Doctrine
  27.  * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
  28.  * @category    Object Relational Mapping
  29.  * @link        www.phpdoctrine.com
  30.  * @since       1.0
  31.  * @version     $Revision$
  32.  * @author      Konsta Vesterinen <kvesteri@cc.hut.fi>
  33.  */
  34. {
  35.     protected $_collections = array();
  36.     
  37.     protected $_records = array();
  38.     
  39.     protected $_tables = array();
  40.  
  41.     public function getElementCollection($component)
  42.     {
  43.         $coll new Doctrine_Collection($component);
  44.         $this->_collections[$coll;
  45.  
  46.         return $coll;
  47.     }
  48.     public function search(Doctrine_Record $recordDoctrine_Collection $coll)
  49.     {
  50.         return array_search($record$coll->getData()true);
  51.     }
  52.     public function initRelated($record$name)
  53.     {
  54.         if is_array($record)) {
  55.             $record[$name];
  56.  
  57.             return true;
  58.         }
  59.         return false;
  60.     }
  61.     public function registerCollection(Doctrine_Collection $coll)
  62.     {
  63.         $this->_collections[$coll;
  64.     }
  65.     /**
  66.      * isIdentifiable
  67.      * returns whether or not a given data row is identifiable (it contains
  68.      * all primary key fields specified in the second argument)
  69.      *
  70.      * @param array $row 
  71.      * @param Doctrine_Table $table 
  72.      * @return boolean 
  73.      */
  74.     public function isIdentifiable(array $rowDoctrine_Table $table)
  75.     {
  76.         $primaryKeys $table->getIdentifier();
  77.  
  78.         if (is_array($primaryKeys)) {
  79.             foreach ($primaryKeys as $id{
  80.                 if isset($row[$id])) {
  81.                     return false;
  82.                 }
  83.             }
  84.         else {
  85.             if isset($row[$primaryKeys])) {
  86.                 return false;
  87.             }
  88.         }
  89.         return true;
  90.     }
  91.     public function getNullPointer(
  92.     {
  93.         return self::$_null;
  94.     }
  95.     public function getElement(array $data$component)
  96.     {
  97.         if isset($this->_tables[$component])) {
  98.             $this->_tables[$componentDoctrine_Manager::getInstance()->getTable($component);
  99.             $this->_tables[$component]->setAttribute(Doctrine::ATTR_LOAD_REFERENCESfalse);
  100.         }
  101.         $this->_tables[$component]->setData($data);
  102.         $record $this->_tables[$component]->getRecord();
  103.         $this->_records[$record;
  104.  
  105.         return $record;
  106.     }
  107.     public function flush()
  108.     {
  109.         // take snapshots from all initialized collections
  110.         foreach ($this->_collections as $key => $coll{
  111.             $coll->takeSnapshot();
  112.         }
  113.         foreach ($this->_tables as $table{
  114.             $table->setAttribute(Doctrine::ATTR_LOAD_REFERENCEStrue);
  115.         }
  116.     }
  117. }