propel-om
[ class tree: propel-om ] [ index: propel-om ] [ all elements ]

Source for file BaseObject.php

Documentation is available at BaseObject.php

  1. <?php
  2.  
  3. /*
  4.  *  $Id: BaseObject.php 621 2007-04-23 09:42:26Z heltem $
  5.  *
  6.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  7.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  8.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  9.  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  10.  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  11.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  12.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  13.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  14.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  15.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  16.  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  17.  *
  18.  * This software consists of voluntary contributions made by many individuals
  19.  * and is licensed under the LGPL. For more information please see
  20.  * <http://propel.phpdb.org>.
  21.  */
  22.  
  23. /**
  24.  * This class contains attributes and methods that are used by all
  25.  * business objects within the system.
  26.  *
  27.  * @author     Hans Lellelid <hans@xmpl.org> (Propel)
  28.  * @author     Frank Y. Kim <frank.kim@clearink.com> (Torque)
  29.  * @author     John D. McNally <jmcnally@collab.net> (Torque)
  30.  * @version    $Revision: 621 $
  31.  * @package    propel.om
  32.  */
  33. abstract class BaseObject {
  34.  
  35.     /**
  36.      * attribute to determine if this object has previously been saved.
  37.      * @var        boolean 
  38.      */
  39.     private $_new true;
  40.  
  41.     /**
  42.      * attribute to determine whether this object has been deleted.
  43.      * @var        boolean 
  44.      */
  45.     private $_deleted false;
  46.  
  47.     /**
  48.      * The columns that have been modified in current object.
  49.      * Tracking modified columns allows us to only update modified columns.
  50.      * @var        array 
  51.      */
  52.     protected $modifiedColumns = array();
  53.  
  54.     /**
  55.      * Returns whether the object has been modified.
  56.      *
  57.      * @return     boolean True if the object has been modified.
  58.      */
  59.     public function isModified()
  60.     {
  61.         return !empty($this->modifiedColumns);
  62.     }
  63.  
  64.     /**
  65.      * Has specified column been modified?
  66.      *
  67.      * @param      string $col 
  68.      * @return     boolean True if $col has been modified.
  69.      */
  70.     public function isColumnModified($col)
  71.     {
  72.         return in_array($col$this->modifiedColumns);
  73.     }
  74.  
  75.     /**
  76.      * Get the columns that have been modified in this object.
  77.      * @return     array A unique list of the modified column names for this object.
  78.      */
  79.     public function getModifiedColumns()
  80.     {
  81.         return array_unique($this->modifiedColumns);
  82.     }
  83.  
  84.     /**
  85.      * Returns whether the object has ever been saved.  This will
  86.      * be false, if the object was retrieved from storage or was created
  87.      * and then saved.
  88.      *
  89.      * @return     true, if the object has never been persisted.
  90.      */
  91.     public function isNew()
  92.     {
  93.         return $this->_new;
  94.     }
  95.  
  96.     /**
  97.      * Setter for the isNew attribute.  This method will be called
  98.      * by Propel-generated children and Peers.
  99.      *
  100.      * @param      boolean $b the state of the object.
  101.      */
  102.     public function setNew($b)
  103.     {
  104.         $this->_new = (boolean) $b;
  105.     }
  106.  
  107.     /**
  108.      * Whether this object has been deleted.
  109.      * @return     boolean The deleted state of this object.
  110.      */
  111.     public function isDeleted()
  112.     {
  113.         return $this->_deleted;
  114.     }
  115.  
  116.     /**
  117.      * Specify whether this object has been deleted.
  118.      * @param      boolean $b The deleted state of this object.
  119.      * @return     void 
  120.      */
  121.     public function setDeleted($b)
  122.     {
  123.         $this->_deleted = (boolean) $b;
  124.     }
  125.  
  126.     /**
  127.      * Sets the modified state for the object to be false.
  128.      * @param      string $col If supplied, only the specified column is reset.
  129.      * @return     void 
  130.      */
  131.     public function resetModified($col null)
  132.     {
  133.         if ($col !== null)
  134.         {
  135.             while (($offset array_search($col$this->modifiedColumns)) !== false)
  136.                 array_splice($this->modifiedColumns$offset1);
  137.         }
  138.         else
  139.         {
  140.             $this->modifiedColumns = array();
  141.         }
  142.     }
  143.  
  144.     /**
  145.      * Compares this with another <code>BaseObject</code> instance.  If
  146.      * <code>obj</code> is an instance of <code>BaseObject</code>, delegates to
  147.      * <code>equals(BaseObject)</code>.  Otherwise, returns <code>false</code>.
  148.      *
  149.      * @param      obj The object to compare to.
  150.      * @return     Whether equal to the object specified.
  151.      */
  152.     public function equals($obj)
  153.     {
  154.         $thisclazz get_class($this);
  155.         if (is_object($obj&& $obj instanceof $thisclazz{
  156.             if ($this === $obj{
  157.                 return true;
  158.             elseif ($this->getPrimaryKey(=== null || $obj->getPrimaryKey(=== null)  {
  159.                 return false;
  160.             else {
  161.                 return ($this->getPrimaryKey(=== $obj->getPrimaryKey());
  162.             }
  163.         else {
  164.             return false;
  165.         }
  166.     }
  167.  
  168.     /**
  169.      * If the primary key is not <code>null</code>, return the hashcode of the
  170.      * primary key.  Otherwise calls <code>Object.hashCode()</code>.
  171.      *
  172.      * @return     int Hashcode
  173.      */
  174.     public function hashCode()
  175.     {
  176.         $ok $this->getPrimaryKey();
  177.         if ($ok === null{
  178.             return crc32(serialize($this));
  179.         }
  180.         return crc32(serialize($ok))// serialize because it could be an array ("ComboKey")
  181.     }
  182.  
  183.     /**
  184.      * Logs a message using Propel::log().
  185.      *
  186.      * @param      string $msg 
  187.      * @param      int $priority One of the Propel::LOG_* logging levels
  188.      * @return     boolean 
  189.      */
  190.     protected function log($msg$priority Propel::LOG_INFO)
  191.     {
  192.         return Propel::log(get_class($this': ' $msg$priority);
  193.     }
  194.  
  195. }

Documentation generated on Thu, 22 Nov 2007 03:33:19 +0000 by phpDocumentor 1.4.0