Source for file PNObject.class.php
Documentation is available at PNObject.class.php
* Zikula Application Framework
* @copyright Robert Gasch
* @link http://www.zikula.org
* @version $Id: PNObject.class.php 24342 2008-06-06 12:03:14Z markwest $
* @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
* @author Robert Gasch rgasch@gmail.com
* @subpackage PNObjectUtil
* @subpackage PNObjectUtil
// data + access descriptor
* Constructur, init everything to sane defaults and handle parameters
* @param init Initialization value (see _init() for details)
* @param key The DB key to use to retrieve the object (optional) (default=null)
* @param field The field containing the key value (optional) (default=null)
function PNObject ($init= null, $key= null, $field= null)
$this->_objCategoryFilter = null;
$this->_init ($init, $key, $field);
* Internal intialization routine
* @param init Initialization value (can be an object or a string directive)
* @param key The DB key to use to retrieve the object (optional) (default=null)
* @param field The field containing the key value (optional) (default=null)
* If $_init is an arrary it is set(), otherwise it is interpreted as a string specifying
* the source from where the data should be retrieved from.
function _init ($init= null, $key= null, $field= null)
$this->_table = $pntables[$tkey];
return pn_exit ("Missing DB-key in PNObject::init() ...");
return pn_exit ("Invalid init-directive [$init] found in PNObject::init() ...");
return pn_exit ("Unexpected parameter type init [$init] in PNObject::init() ...");
* Generate an empty object with the fields initialized to null
$this->_table = isset ($pntables[$tkey]) ? $pntables[$tkey] : '';
$this->_columns = isset ($pntables[$ckey]) ? $pntables[$ckey] : '';
* Set (and return) the object data.
* @param data The data to assign
* @param cache Whether or not to cache the data in session (optional) (default=true)
function setData ($data, $cache= true)
* Return the current object data. If $key and $field are supplied,
* the object is fetched again from the database.
* @param key The record's key value
* @param field The field we wish to get (optional) (default='id')
* @param force If false, the system attempts to return the object from the session cache (optional) (default=false) (currently not used)
* @return The object's data value
function &get ($key= 0, $field= 'id', $force= false)
return $this->select ($key, $field);
* Return the currently set object data
* @return The object's data array
* Return the object ID field name
* @return The object's ID field name
* Return the object-ID or false
* @return The object-ID or false
* Return/Select the object using the given where clause.
* @param where The where-clause to use
* @return The object's data value
return $this->select (null, null, $where);
* Get the object which failed validation
* @return The object's data value
* Return whether or not this object has a set id field
* Select the object from the database using the specified key (and field)
* @param key The record's key value (if init is a string directive)
* @param field The key-field we wish to select by (optional) (default='id')
* @param where The key-field we wish to select by (optional) (default='id')
* @return The object's data value
function &select ($key, $field= 'id', $where= '')
if ((!$key || !$field) && !$where) {
// use explicit where clause
if ($objArray === false) {
if (isset ($objArray[0])) {
// generic key=>value lookup
* Post-Process the newly selected object. Subclasses can define appropriate implementations.
* @param obj Override object (needed for selectObjectArray processing) (optional) (default=null)
* @return The object's data value
* Get the data from the various input streams provided.
* @param key The access key of the object (optional) (default=null, reverts to $this->_objPath)
* @param default The default value to return (optional) (default=null)
* @param source Where to get the variable from (optional) (default='REQUEST')
* @return The requested object/value
* Get the data from the various input streams provided.
* @param key The access key of the object (optional) (default=null, reverts to $this->_objPath)
* @param default The default value to return (optional) (default=null)
* @param source Where to get the variable from (optional) (default=null)
* @return The requested object/value
function &getDataFromSession ($key= null, $default= null, $path= '', $autocreate= true, $overwriteExistingVar= false)
$obj = SessionUtil::getVar($key, $default, $path, $autocreate, $overwriteExistingVar);
* Set the current object data into session
* @param autocreate The autocreate passed to SessionUtil::setVar
* @param overwriteExistingVar The overwriteExistingVar variable passed to SessionUtil::setVar
* @return The session data
function &setDataToSession ($data= null, $key= null, $path= '', $autocreate= true, $overwriteExistingVar= false)
* Post-Process the data after getting it from Input. Subclasses can define appropriate implementations.
* Post-Process the data after getting it from Session. Subclasses can define appropriate implementations.
* Pre-Process the data before writing it to Session. Subclasses can define appropriate implementations.
* Generic access function to retrieve data from the specified source
* @param source The source data
* @param key The access key of the object (optional) (default=null)
* @param default The default value to return (optional) (default=null)
* @param clean Whether or not to clean the acquired data (optional) (default=true)
* @return The requested object/value
if (isset ($source[$key])) {
return $this->setData ($source[$key]);
* Generic function to retrieve
* @param key The access key of the object field
* @param default The default value to return (optional) (default=null)
* @return The Object Data
if (isset ($objData[$key])) {
* Generic function to retrieve
* @param key The access key of the object field
* @param value The value to assign to the specified object field
* @return The value which was set into the specified object field
* Generic insert handler for an object (ID is inserted into the object data). If the object
* contains a valid ID, it is updated, otherwise it it inserted
* Generic insert handler for an object (ID is inserted into the object data)
* @return The Object Data
* Pre-Process the data prior to an insert. Subclasses can define appropriate implementations.
* Post-Process the data after an insert. Subclasses can define appropriate implementations.
* Generic upate handler for an object
* @return The Object Data
* Pre-Process the data prior to an update. Subclasses can define appropriate implementations.
// empty function, should be implemented by child classes
* Post-Process the data after an update. Subclasses can define appropriate implementations.
// empty function, should be implemented by child classes
* Generic delete handler for an object
* @return The Object Data
* Pre-Process the data prior a delete. Subclasses can define appropriate implementations.
// empty function, should be implemented by child classes
* Post-Process the data after a delete. Subclasses can define appropriate implementations.
// empty function, should be implemented by child classes
* Generic function to validate an object
* @return Boolean indicating whether validation has passed or failed
* Post-Process the basic object validation with class specific logic.
* Subclasses can define appropriate implementations.
// empty function, should be implemented by child classes
* Get the hashcode for this object data
function getHash ($includeStandardFields= true, $objData= null)
if (!$includeStandardFields) {
* Clear the failed validation errors for this object
* Clear the failed validation object data for this object
* Clear the session cache for this object
* Print HTML-formatted debug output for the object
* Print HTML-formatted debug output for the object data
|