Source for file Record.class.php

Documentation is available at Record.class.php

  1. <?php
  2. /**
  3.  * Gumbo Library Framework
  4.  *
  5.  * LICENSE
  6.  * This library is being released under the terms of the New BSD License.  A
  7.  * copy of the license is packaged with the software (LICENSE.txt).  If no
  8.  * copy is found, a copy of the license template can be found at:
  9.  * http://www.opensource.org/licenses/bsd-license.php
  10.  * 
  11.  * @category Gumbo
  12.  * @package DB
  13.  * @copyright Copyright (c) 2007, iBayou, Michael Luster
  14.  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
  15.  * @author Michael Luster <mluster79@yahoo.com>
  16.  * @link http://sourceforge.net/projects/phpgumbo
  17.  * @version 0.0.1
  18.  */
  19.  
  20. /**
  21.  * Record Interface
  22.  * 
  23.  * This Interface is responsible for representing a database table record.  It
  24.  * provides methods to retrieve record information as well as manipulating the
  25.  * data.  The record can be saved, removed, or a new one created.
  26.  *
  27.  * @category Gumbo
  28.  * @package DB
  29.  * @copyright Copyright (c) 2007, iBayou, Michael Luster
  30.  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
  31.  * @author Michael Luster <mluster79@yahoo.com>
  32.  * @link http://sourceforge.net/projects/phpgumbo
  33.  * @desc Record Interface
  34.  * @version 0.0.1
  35.  */
  36.  
  37.     
  38.     /**
  39.      * Serialized method
  40.      * @return array 
  41.      */
  42.     public function __sleep ();
  43.     
  44.     /**
  45.      * Unserialized method
  46.      */
  47.     public function __wakeup ();
  48.     
  49.     /**
  50.      * Sets the value of a table column
  51.      * @param string $column 
  52.      * @param mixed $val 
  53.      */
  54.     public function __set ($column$val);
  55.     
  56.     /**
  57.      * Unsets the value of the supplied table column
  58.      * @param string $column 
  59.      */
  60.     public function __unset ($column);
  61.     
  62.     /**
  63.      * Returns the raw value of the column name
  64.      * @param string $column 
  65.      * @return mixed 
  66.      */
  67.     public function __get ($column);
  68.     
  69.     /**
  70.      * Returns if the Column is set
  71.      * @param string $column 
  72.      * @return bool 
  73.      */
  74.     public function __isset ($column);
  75.     
  76.     
  77.     
  78.     
  79.     
  80.     /** ACTION METHODS **/
  81.     /**
  82.      * Loads the record into memory
  83.      */
  84.     public function load ();
  85.     
  86.     /**
  87.      * Loads an XML string, but only the first level of the parent
  88.      * 
  89.      * @param string $xml 
  90.      * @param string $parent name of top level XML element
  91.      */
  92.     public function loadXML ($xml$parent=null);
  93.     
  94.     /**
  95.      * Clears the object values, leaves the columns structure
  96.      * @param bool $erase_all clears extra values from memory
  97.      */
  98.     public function unload ($erase_all=false);
  99.     
  100.     
  101.     
  102.     /**
  103.      * Removes the record from the database
  104.      * @precondition isLoaded ()
  105.      * @precondition !isReadOnly ()
  106.      */
  107.     public function kill ();
  108.     
  109.     /**
  110.      * Saves a modified record to the database
  111.      * @precondition isLoaded ()
  112.      * @precondition isModified ()
  113.      * @precondition !isReadOnly ()
  114.      */
  115.     public function save ();
  116.     
  117.     /**
  118.      * Creates a new record in the database
  119.      * @precondition !isLoaded ()
  120.      * @precondition isModified ()
  121.      * @precondition !isReadOnly
  122.      */
  123.     public function create ();
  124.     
  125.     
  126.     
  127.     /**
  128.      * Resets the object by removing the values from the modified array
  129.      */
  130.     public function reset ();
  131.     
  132.     
  133.     
  134.     /** MUTATOR METHODS **/
  135.     /**
  136.      * Sets the object as read only
  137.      * @param bool $val 
  138.      */
  139.     public function setReadOnly ($val);
  140.     
  141.     /**
  142.      * Adds (increments) to the current count columns value
  143.      * @precondition _isColumnCount ($column)
  144.      * @param string $column count column name
  145.      * @param int $num increases by the supplied number
  146.      */
  147.     public function add ($column$num=1);
  148.     
  149.     /**
  150.      * Wrapper to add() method
  151.      * @param string $column count column name
  152.      * @param int $num increases by the supplied number
  153.      */
  154.     public function increment ($column$num=1);
  155.     
  156.     /**
  157.      * Subtracts (decrement) one from the count column value
  158.      * @precondition _isColumnCount ($column)
  159.      * @param string $column count column name
  160.      * @param int $num decreases by the supplied number
  161.      * @param bool $allow_negative allows negative values
  162.      */
  163.     public function sub ($column$num=1$allow_negative=false);
  164.     
  165.     /**
  166.      * Wrapper to sub() method
  167.      * @param string $column count column name
  168.      * @param int $num decreases by the supplied number
  169.      * @param bool $allow_negative allows negative values
  170.      */
  171.     public function decrement ($column$num=1$allow_negative=false);
  172.     
  173.     
  174.     
  175.     /** ACCESSOR METHODS **/
  176.     /**
  177.      * Returns the table name
  178.      * @return string 
  179.      */
  180.     public function getTable ();
  181.     
  182.     /**
  183.      * Returns the primary key name
  184.      * @return string 
  185.      */
  186.     public function getPrimaryKey ();
  187.     
  188.     /**
  189.      * Returns the primary key value
  190.      * @return mixed 
  191.      */
  192.     public function getPrimaryValue ();
  193.     
  194.     /**
  195.      * Returns the value of a column
  196.      * @param string $column Column Name
  197.      * @return mixed 
  198.      */
  199.     public function get ($column);
  200.     
  201.     /**
  202.      * Returns the XML parent element name
  203.      * @return string 
  204.      */
  205.     public function getXMLParent ();
  206.     
  207.     // Table Columns
  208.     /**
  209.      * Returns the entire Columns array
  210.      * @return array 
  211.      */
  212.     public function getAllColumns ();
  213.     
  214.     // Modified table columns
  215.     /**
  216.      * Returns all modified table columns array
  217.      * @return array 
  218.      */
  219.     public function getAllColumnsMod ();
  220.     
  221.     // Extra columns
  222.     /**
  223.      * Returns all the extra columns array
  224.      * @return array 
  225.      */
  226.     public function getAllColumnsExtra ();
  227.     
  228.     // Count Columns
  229.     /**
  230.      * Returns all the count columns
  231.      * @return array 
  232.      */
  233.     public function getAllColumnsCount ();
  234.     
  235.     
  236.     
  237.     /**
  238.      * Returns if the records was loaded
  239.      * @return bool 
  240.      */
  241.     public function isLoaded ();
  242.     
  243.     /**
  244.      * Returns if the record was modified
  245.      * @return bool 
  246.      */
  247.     public function isModified ();
  248.     
  249.     /**
  250.      * Returns if the record accesses the database
  251.      * @return bool 
  252.      */
  253.     public function isReadOnly ();
  254.     
  255.     /**
  256.      * Returns the object as an XML formatted string
  257.      * @param string $parent parent element name
  258.      * @return string 
  259.      */
  260.     public function asXML ($parent=null);
  261.     
  262. }
  263.  
  264. ?>