40 require_once realpath(dirname(__FILE__).
"/transaction.inc");
41 require_once realpath(dirname(__FILE__).
"/data_type_renderers/abstract_type_renderer.inc");
57 $args = func_get_args();
58 for($i = 0; $i < count($args); ++$i)
60 $this->fields[$args[$i]] =
true;
66 return (array_key_exists($field, $this->fields));
71 $args = func_get_args();
72 for($i = 0; $i < count($args); ++$i)
74 $this->fields[$args[$i]] =
true;
80 $args = func_get_args();
81 for($i = 0; $i < count($args); ++$i)
83 unset($this->fields[$args[$i]]);
89 $this->
remove($field);
110 $args = func_get_args();
111 for($i = 0; $i < count($args); ++$i)
113 $this->fields[$args[$i]] =
true;
119 return !(array_key_exists($field, $this->fields));
124 $args = func_get_args();
125 for($i = 0; $i < count($args); ++$i)
127 $this->fields[$args[$i]] =
true;
133 $args = func_get_args();
134 for($i = 0; $i < count($args); ++$i)
136 unset($this->fields[$args[$i]]);
147 $this->
remove($field);
151 define(
"SerializeRelations", 1);
152 define(
"SerializeDirectRelations", 2);
153 define(
"ProtectHTML", 4);
175 if (!$this->_decorations)
177 $this->_decorations = array();
180 $this->_decorations[$name] = $value;
189 return $this->_decorations[$name];
200 abstract function cast($class);
208 $this->_options |= $opt;
217 $this->_options |= $opt;
231 return $tx->getConnection();
320 abstract function get($field);
335 abstract function set($field, $value);
394 abstract function exists($constraint =
"");
404 abstract function delete($constraint =
"");
428 if (!$type) $type = $this->
getType($field);
430 $val = $this->
get($field);
446 if ($val ==
"" || !is_numeric($val))
459 $query .= ($val) ? $db->quote($this->reformatToSQLDate($val)) :
"NULL";
464 $this->__timestamp = date(
"Y-m-d H:i:s");
465 $query .= $db->quote($this->__timestamp);
470 $query .= ($val) ?
"1" :
"0";
479 $query .= $db->quote($val);
494 $type = $this->
getType($field);
495 $data = $this->
get($field);
502 $formatter = array($renderer,
"format");
503 $val = call_user_func($formatter, $data, $template);
517 $type = $this->
getType($field);
518 $data = $this->
get($field);
527 $v = str_replace( array(
"<",
">",
"&"), array(
"[_[OPENTAG]_]",
"[_[CLOSETAG]_]",
"[_[AMPERSAND]_]"), $data);
532 $v = htmlentities($data, ENT_COMPAT | ENT_XML1);
543 $v = htmlentities($data, ENT_COMPAT | ENT_XML1);
560 if (preg_match(
"|^(\\d+)[\-/](\\d+)[\-/](\\d{4})$|", $date, $fields))
562 $date = $fields[3].
"-".$fields[1].
"-".$fields[2];
564 else if (preg_match(
"|^(\\d+)/(\\d+)/(\\d{4})\\s+(\\d+:\\d+:\\d+)|", $date, $fields))
566 $date = $fields[3].
"-".$fields[1].
"-".$fields[2].
" ".$fields[4];
575 if (preg_match(
"|^(\\d{4})-(\\d\\d)-(\\d\\d)$|", $date, $fields))
577 $date = $fields[2].
"/".$fields[3].
"/".$fields[1];
579 else if (preg_match(
"|(\\d{4})-(\\d\\d)-(\\d\\d)\\s+(\\d+:\\d+:\\d+)|", $date, $fields))
581 $date = $fields[2].
"/".$fields[3].
"/".$fields[1].
" ".$fields[4];
584 if ($date ==
"00/00/0000") $date =
"";
645 abstract function toXML($indent = 0, $path =
null);
659 if (is_object($json))
662 foreach($fields as $field => $type)
664 $this->
set($field, $json->$field);
669 $obj = json_decode($json,
true);
671 foreach($fields as $field => $type)
673 $this->
set($field, $obj[$field]);
678 abstract function format($template =
"", $separator =
", ");
684 $c = ($this->pretty_class_name) ? $this->pretty_class_name : get_class($this);
685 $c = preg_replace(array(
"/([a-z])([A-Z0-9])/",
Abstract base class for all DataItem implementations.
cacheLookup($id)
Populate the object from the local cache if the object is marked as "cacheLocal".
fromREQUEST()
Automatically populate the object based on parameters in either the $_GET or $_POST collection,...
fromGET()
Automatically populate the object based on parameters in the $_GET collection.
getFields()
Retrieve the field type list for this object.
reformatFromSQLDate($date)
getFieldList($alias="")
Returns a comma-separated list of the fields for this object (applying the assigned filter if there i...
relateTo($target, $field="")
Link this object to the specified target by setting corresponding field to the value of the target's ...
getConnection()
Retrieves a connection to the database.
formatFieldValue($field, $template="")
getPrimaryKeyList()
Retrieves a list of all the primary keys used for an object as an array.
fromPOST()
Automatically populate the object based on parameters in the $_POST collection.
format($template="", $separator=", ")
joinTransaction($tx)
Join the DataItem to the specified DataTransaction.
hasRelation($relation)
Returns true if this DataItem contains a relation with the specified name.
prettifyFieldName($field)
decorate($name, $value)
Adds a decoration to the DataItem.
hasField($field)
Returns true if this DataItem contains a field with the specified name and that field is not excluded...
formatFieldForXML($field)
Format field for XML output.
setFilter($filter)
Sets the filter on this object.
insert()
Insert a new row in the database to store this object.
populate($line)
Populates the object using the supplied associative array (field -> value).
getTransaction()
Retrieves the current DataTransaction.
getType($field)
Retrieves the data type of the specified field.
update()
Update the row in the database that corresponds to this object.
getPrimaryKey()
Retrieves the primary key field name.
prettifyClassName($plural=false)
save()
Store the object in the database.
getFieldArray()
Return an array of field names for this object filtered by any active filter.
fromXML($node)
Populates the object from the specified XML node.
deleteAll()
Delete all the rows in the database that correspond to this class.
getFieldAliases()
Retrieve the list of field aliases.
getIdentityConstraint()
Subclasses can override this function to provide additional identity constraints to be used when quer...
$_tx
Tracks the current database transaction for each DataItem.
compare($to)
Compare this object to another object.
fromJSON($json)
Populate from the supplied JSON object.
toXML($indent=0, $path=null)
Generates an XML representation of the object.
reformatToSQLDate($date)
Reformats the specified date to be in a format used by the database.
cast($class)
Cast this object to another class.
getFieldAnnotations()
Retrieve the list of field annotations.
exists($constraint="")
Check whether the object exists in the database.
distinctValues($field, $sorted=false, $constraint="")
Retrieves the distinct values in the database for the specified field across the specified set of rec...
getFilter()
Returns the filter set on this object.
getDecoration($name)
Retrieve the value of a decoration on the current DataItem.
clearOptions($opt)
Clear the specified behavior option flag.
copy($from)
Copies values from another object, field by field.
getHiddenFields()
Retrieves the list of hidden fields.
select()
Select the object from the database, based on the value of the primary key field.
setOption($opt)
Set a behavior option flag.
quoteFieldValue($field, $type=null)
Returns the properly quoted value of the specified field.
load($id)
Load the object with the specified primary key.
getPrimaryKeyValue()
Retrieves the primary key value.
static getConnection()
Retrieves a reference to the global database connection.
static $dataTypeRendererMap
Used to place a filter on the contents of a DataItem-derived object.
Used to place a filter on the contents of a DataItem-derived object.
trace($msg, $lvl=3, $callStack=null)
Send output to the trace log.
pluralize($text, $count=0)
Takes a singular string and makes it plural.