• Home
  • Pictures
  • Portfolio
  • codez
  • comics
  • craft
  • contact
  • Rings
 
Persistent.php PDF Print E-mail
Written by alex4u2nv   
Wednesday, 14 November 2007 10:59
This function implements static methods related to persitent objects
<?php
/**
* @Author: Alexander D. Mahabir
* @since: Thu Aug 23 22:49:41 EDT 2007 AD
* @brief: This class is the controller/ procedural / functional part of
* Persistent Object classes.
* @param:
* @return:
*/
if(!class_exists('net_alex4u2nv_proc_Persistent'))
{
class net_alex4u2nv_proc_Persistent {
/***
* @Author: Alexander D. Mahabir
* @since: Sun Aug 26 07:49:09 EDT 2007 AD
* @brief:
* @param:
* @return:
*/
public static function where (ArrayObject $conditions)
{
if (!$conditions->count()) return false;
$cond = " WHERE ";
$more = false;
for ($it=$conditions->getIterator(); $it->valid(); $it->next())
{
if ($more)
$cond.= " AND ";
else
$more= true;

$cond.=" {$it->key()}='{$it->current()}' ";
if (!ctype_digit((string)$it->current()))
$cond.= "='{$it->current()}'";
else
$cond.= "={$it->current()}";

}
return $cond;
}

/**
* @Author: Alexander D. Mahabir
* @since: Sun Aug 26 07:49:04 EDT 2007 AD
* @brief:
* @param:
* @return:
*/
public static function simple_load (&$object, $param=null)
{
if ($param && is_string($param))
return self::q_load($object,$param);

$cond= " ";
if ($param) $cond= $object->whereCondition($param);
$dbtable = $object->getTable();

$query = "SELECT * FROM ${dbtable} $cond";
return self::q_load($object,$query);
}

/**
* @Author: Alexander D. Mahabir
* @since: Sat Sep 1 13:19:21 EDT 2007 AD
* @brief:
* @param:
* @return:
*/
public static function q_load(&$object, $query)
{
$rs=db_query($query);
return $object->collect_dbresults($rs);
}
}
}

?>
Last Updated ( Thursday, 24 January 2008 14:51 )