Framework  3.9
CompositeDataItem Class Reference
+ Inheritance diagram for CompositeDataItem:
+ Collaboration diagram for CompositeDataItem:

Public Member Functions

 CompositeDataItem ()
 
 add ()
 
 cast ($class)
 Cast this object to another class. More...
 
 joinTransaction ($tx)
 Join the DataItem to the specified DataTransaction. More...
 
 getTransaction ()
 Retrieves the current DataTransaction. More...
 
 populate ($line)
 Populates the object using the supplied associative array (field -> value). More...
 
 getFieldList ($alias="")
 Returned a comma-separated list of the fields for this object (applying the assigned filter if there is one). More...
 
 getFieldArray ()
 Return an array of field names for this object filtered by any active filter. More...
 
 getFields ()
 Retrieve the field type list for this object. More...
 
 hasField ($field)
 Returns true if this DataItem contains a field with the specified name and that field is not excluded by a filter. More...
 
 getHiddenFields ()
 Retrieves the list of hidden fields. More...
 
 hasRelation ($relation)
 Returns true if this DataItem contains a relation with the specified name. More...
 
 findSubObject ($field)
 Finds and returns the sub-object that contains the given field. More...
 
 getPrimaryKey ()
 Retrieves the primary key field name. More...
 
 getPrimaryKeyList ()
 Retrieves a list of all the primary keys used for an object as an array. More...
 
 get ($field)
 Retrieve the value for the specified field. More...
 
 set ($field, $value)
 Set the value of the specified field. More...
 
 getType ($field)
 Retrieves the data type of the specified field. More...
 
 getFilter ()
 Returns the filter set on this object. More...
 
 setFilter ($filter)
 Sets the filter on this object. More...
 
 getFieldAliases ()
 Retrieve the list of field aliases. More...
 
 getFieldAnnotations ()
 Retrieve the list of field annotations. More...
 
 load ($id)
 Load the object with the specified primary key. More...
 
 loadFromBase ($id)
 
 save ()
 Store the object in the database. More...
 
 select ()
 Select the object from the database, based on the value of the primary key field. More...
 
 exists ($constraint="")
 Check whether the object exists in the database. More...
 
 update ()
 Update the row in the database that corresponds to this object. More...
 
 insert ()
 Insert a new row in the database to store this object. More...
 
 delete ($constraint="")
 Delete the row in the database that corresponds to this object. More...
 
 deleteAll ()
 Delete all the rows in the database that correspond to this class. More...
 
 distinctValues ($field, $sorted=false, $constraint="")
 Retrieves the distinct values in the database for the specified field across the specified set of records. More...
 
 fromGET ()
 Automatically populate the object based on parameters in the $_GET collection. More...
 
 fromPOST ()
 Automatically populate the object based on parameters in the $_POST collection. More...
 
 fromREQUEST ()
 Automatically populate the object based on parameters in either the $_GET or $_POST collection, depending on the method used to access the page. More...
 
 compare ($to)
 Compare this object to another object. More...
 
 copy ($from)
 Copies values from another object, field by field. More...
 
 toXML ($indent=0, $path=null)
 Generates an XML representation of the object. More...
 
 fromXML ($node)
 Populates the object from the specified XML node. More...
 
 format ($template="", $separator=",")
 
 prettifyFieldName ($field)
 
 prettifyClassName ($plural=false)
 
 relateTo ($target, $field="")
 Link this object to the specified target by setting corresponding field to the value of the target's primary key. More...
 
 query ($constraints="", $page=-1, $size=-1)
 
 indexedQuery ($constraints="", $indexBy="")
 Performs a query against the database, returning an array of CompositeDataItem objects of the specified class, indexed by a particular field. More...
 
 groupedQuery ($constraints="", $indexBy="")
 Performs a query against the database, returning an array of arrays of CompositeDataItem objects of the specified class, grouped by a particular field. More...
 
- Public Member Functions inherited from AbstractDataItem
 decorate ($name, $value)
 Adds a decoration to the DataItem. More...
 
 getDecoration ($name)
 Retrieve the value of a decoration on the current DataItem. More...
 
 setOption ($opt)
 Set a behavior option flag. More...
 
 clearOptions ($opt)
 Clear the specified behavior option flag. More...
 
 getConnection ()
 Retrieves a connection to the database. More...
 
 getIdentityConstraint ()
 Subclasses can override this function to provide additional identity constraints to be used when querying or updating. More...
 
 getPrimaryKeyValue ()
 Retrieves the primary key value. More...
 
 cacheLookup ($id)
 Populate the object from the local cache if the object is marked as "cacheLocal". More...
 
 quoteFieldValue ($field, $type=null)
 Returns the properly quoted value of the specified field. More...
 
 quoteValue ($val, $type)
 
 formatFieldValue ($field, $template="")
 
 formatFieldForXML ($field)
 Format field for XML output. More...
 
 reformatToSQLDate ($date)
 Reformats the specified date to be in a format used by the database. More...
 
 reformatFromSQLDate ($date)
 
 fromJSON ($json)
 Populate from the supplied JSON object. More...
 

Public Attributes

 $__objects
 
 $__tx = null
 
- Public Attributes inherited from AbstractDataItem
 $filter
 
 $_options = 0
 
 $_tx = null
 Tracks the current database transaction for each DataItem. More...
 
 $_decorations = null
 

Detailed Description

Definition at line 40 of file composite_data_item.inc.

Member Function Documentation

◆ add()

CompositeDataItem::add ( )

Definition at line 50 of file composite_data_item.inc.

51  {
52  $args = func_get_args();
53 
54  foreach($args as $cl)
55  {
56  $obj = new $cl();
57  $pk = $obj->getPrimaryKey();
58 
59  if (count($this->__objects))
60  {
61  $found = false;
62 
63  foreach($this->__objects as $o)
64  {
65  if ($o->hasField($pk))
66  {
67  $found = true;
68  break;
69  }
70  }
71 
72  if (!$found)
73  {
74  throw new DataItemException("$cl does not have a direct foreign key relationship with another class in ".get_class($this));
75  }
76  }
77 
78  $this->__objects[] = $obj;
79  $this->$cl = $obj;
80  }
81  }

◆ cast()

CompositeDataItem::cast (   $class)

Cast this object to another class.

This facility is provided so that it is possible to cast from a CompositeDataItem to one of its constituents to provide support for polymorphism in those cases.

Parameters
string$class
Returns
instance of the specified class, if compatible
Exceptions
DataItemException

Reimplemented from AbstractDataItem.

Definition at line 83 of file composite_data_item.inc.

84  {
85  if ($this->$class) return $this->$class;
86 
87  throw new DataItemException("Cannot cast from ".get_class($this)." to $class");
88  }

◆ compare()

CompositeDataItem::compare (   $to)

Compare this object to another object.

If all the fields match, the method returns true, otherwise false. If a filter is in place on the source object, then only the filtered fields are compared.

Parameters
object$tothe object with which to compare this object

Reimplemented from AbstractDataItem.

Definition at line 601 of file composite_data_item.inc.

602  {
603  if (get_class($to) != get_class($this)) return false;
604  $num = count($this->__objects);
605 
606  for($i = 0; $i < $num; ++$i)
607  {
608  if (!$this->__objects[$i]->compare($to->__objects[$i])) return false;
609  }
610 
611  return true;
612  }
compare($to)
Compare this object to another object.

◆ CompositeDataItem()

CompositeDataItem::CompositeDataItem ( )

Definition at line 45 of file composite_data_item.inc.

46  {
47  $__objects = array();
48  }

◆ copy()

CompositeDataItem::copy (   $from)

Copies values from another object, field by field.

If a filter is in place on the source object, then only the filtered fields are copied.

Parameters
objectfrom the object from which data is to be copied

Reimplemented from AbstractDataItem.

Definition at line 620 of file composite_data_item.inc.

621  {
622  if (get_class($to) != get_class($this)) return false;
623 
624  $num = count($this->__objects);
625 
626  for($i = 0; $i < $num; ++$i)
627  {
628  $this->__objects[$i]->copy($from->__objects[$i]);
629  }
630  }

◆ delete()

CompositeDataItem::delete (   $constraint = "")

Delete the row in the database that corresponds to this object.

Reimplemented from AbstractDataItem.

Definition at line 510 of file composite_data_item.inc.

511  {
512  if ($constraint)
513  {
514  throw new DataItemException("CompositeDataItem::delete() does not currently support constraint clauses");
515  }
516 
517  $num = count($this->__objects);
518 
519  for($i = 0; $i < $num; ++$i)
520  {
521  $this->__objects[$i]->delete();
522  }
523  }

◆ deleteAll()

CompositeDataItem::deleteAll ( )

Delete all the rows in the database that correspond to this class.

Reimplemented from AbstractDataItem.

Definition at line 528 of file composite_data_item.inc.

529  {
530  for($i = 0; $i < $num; ++$i)
531  {
532  $this->__objects[$i]->deleteAll();
533  }
534  }

◆ distinctValues()

CompositeDataItem::distinctValues (   $field,
  $sorted = false,
  $constraint = "" 
)

Retrieves the distinct values in the database for the specified field across the specified set of records.

Parameters
string$field
boolean$sorted
string$constraint
Returns
array

Reimplemented from AbstractDataItem.

Definition at line 544 of file composite_data_item.inc.

545  {
546  foreach($this->__objects as $obj)
547  {
548  if ($obj->hasField($field))
549  {
550  return $obj->distinctValues($field, $sorted, $constraint);
551  }
552  }
553 
554  throw new DataItemException("Could not find field '$field' in any component objects");
555  }

◆ exists()

CompositeDataItem::exists (   $constraint = "")

Check whether the object exists in the database.

Reimplemented from AbstractDataItem.

Definition at line 471 of file composite_data_item.inc.

472  {
473  return $this->__objects[0]->exists($constraint);
474  }

◆ findSubObject()

CompositeDataItem::findSubObject (   $field)

Finds and returns the sub-object that contains the given field.

Parameters
string$fieldthe field for which to search

Definition at line 241 of file composite_data_item.inc.

242  {
243  foreach($this->__objects as $obj)
244  {
245  if ($obj->hasField($field)) return $obj;
246  }
247 
248  throw new FakoliException("Cannot locate field '$field' in sub-objects");
249  }

◆ format()

CompositeDataItem::format (   $template = "",
  $separator = "," 
)

Reimplemented from AbstractDataItem.

Definition at line 659 of file composite_data_item.inc.

660  {
661  $matches = array();
662 
663  preg_match_all("/\\{([\\w_]+)\.([^}]+)}/", $template, $matches, PREG_SET_ORDER);
664 
665  foreach($matches as $match)
666  {
667  $class = $match[1];
668  $subtemplate = $match[2];
669 
670  $value = $this->$class->format("{".$subtemplate."}", $separator);
671 
672  $template = str_replace($match[0], $value, $template);
673  }
674 
675  return $template;
676  }

◆ fromGET()

CompositeDataItem::fromGET ( )

Automatically populate the object based on parameters in the $_GET collection.

Reimplemented from AbstractDataItem.

Definition at line 560 of file composite_data_item.inc.

561  {
562  foreach($this->__objects as $obj)
563  {
564  $obj->fromGET();
565  }
566  }

◆ fromPOST()

CompositeDataItem::fromPOST ( )

Automatically populate the object based on parameters in the $_POST collection.

If the key does not exist in $_POST and the type is Boolean, that means that the user unchecked a checkbox and we need to assign 0 to the field.

Reimplemented from AbstractDataItem.

Definition at line 574 of file composite_data_item.inc.

575  {
576  foreach($this->__objects as $obj)
577  {
578  $obj->fromPOST();
579  }
580  }

◆ fromREQUEST()

CompositeDataItem::fromREQUEST ( )

Automatically populate the object based on parameters in either the $_GET or $_POST collection, depending on the method used to access the page.

Reimplemented from AbstractDataItem.

Definition at line 586 of file composite_data_item.inc.

587  {
588  foreach($this->__objects as $obj)
589  {
590  $obj->fromREQUEST();
591  }
592  }

◆ fromXML()

CompositeDataItem::fromXML (   $node)

Populates the object from the specified XML node.

Parameters
DOMNode$node

Reimplemented from AbstractDataItem.

Definition at line 654 of file composite_data_item.inc.

655  {
656  //TODO: Implement this
657  }

◆ get()

CompositeDataItem::get (   $field)

Retrieve the value for the specified field.

Parameters
string$fieldthe field to retrieve
Returns
mixed the value of that field

Reimplemented from AbstractDataItem.

Definition at line 282 of file composite_data_item.inc.

283  {
284  foreach($this->__objects as $obj)
285  {
286  if ($obj->hasField($field)) return $obj->get($field);
287  }
288 
289  return null;
290  }

◆ getFieldAliases()

CompositeDataItem::getFieldAliases ( )

Retrieve the list of field aliases.

Returns
array the alias list for this object

Reimplemented from AbstractDataItem.

Definition at line 344 of file composite_data_item.inc.

345  {
346  $aliases = array();
347 
348  // Create a composite field list from the inside out.
349  $num = count($this->__objects);
350  for($i = $num - 1; $i >= 0; --$i)
351  {
352  $of = $this->__objects[$i]->getFieldAliases();
353  if ($of)
354  {
355  $aliases = array_merge($aliases, $of);
356  }
357  }
358 
359  return $aliases;
360  }

◆ getFieldAnnotations()

CompositeDataItem::getFieldAnnotations ( )

Retrieve the list of field annotations.

Returns
array the annotation list for this object

Reimplemented from AbstractDataItem.

Definition at line 366 of file composite_data_item.inc.

367  {
368  $aliases = array();
369 
370  // Create a composite field list from the inside out.
371  $num = count($this->__objects);
372  for($i = $num - 1; $i >= 0; --$i)
373  {
374  $of = $this->__objects[$i]->getFieldAnnotations();
375  if ($of)
376  {
377  $aliases = array_merge($aliases, $of);
378  }
379  }
380 
381  return $aliases;
382  }

◆ getFieldArray()

CompositeDataItem::getFieldArray ( )

Return an array of field names for this object filtered by any active filter.

Returns
array

Reimplemented from AbstractDataItem.

Definition at line 158 of file composite_data_item.inc.

159  {
160  $fields[] = array();
161 
162  // Create a composite field list from the inside out.
163  $num = count($this->__objects);
164  for($i = $num - 1; $i >= 0; --$i)
165  {
166  $of = $this->__objects[$i]->getFields();
167  $fields = array_merge($fields, $of);
168  }
169 
170  return array_keys($fields);
171  }

◆ getFieldList()

CompositeDataItem::getFieldList (   $alias = "")

Returned a comma-separated list of the fields for this object (applying the assigned filter if there is one).

Reimplemented from AbstractDataItem.

Definition at line 139 of file composite_data_item.inc.

140  {
141  $fields[] = array();
142 
143  // Create a composite field list from the inside out.
144  $num = count($this->__objects);
145  for($i = $num - 1; $i >= 0; ++$i)
146  {
147  $of = $this->__objects[$i]->getFields();
148  $fields = array_merge($fields, $of);
149  }
150 
151  return implode(", ", array_keys($fields));
152  }

◆ getFields()

CompositeDataItem::getFields ( )

Retrieve the field type list for this object.

Reimplemented from AbstractDataItem.

Definition at line 176 of file composite_data_item.inc.

177  {
178  $fields = array();
179  // Create a composite field list from the inside out.
180  $num = count($this->__objects);
181  for($i = $num - 1; $i >= 0; --$i)
182  {
183  $of = $this->__objects[$i]->getFields();
184  $fields = array_merge($fields, $of);
185  }
186 
187  return $fields;
188  }

◆ getFilter()

CompositeDataItem::getFilter ( )

Returns the filter set on this object.

Reimplemented from AbstractDataItem.

Definition at line 323 of file composite_data_item.inc.

324  {
325  return $this->__objects[0]->getFilter();
326  }

◆ getHiddenFields()

CompositeDataItem::getHiddenFields ( )

Retrieves the list of hidden fields.

These will be automatically hidden in any AutoForm.

Returns
array of names of hidden fields.

Reimplemented from AbstractDataItem.

Definition at line 207 of file composite_data_item.inc.

208  {
209  $hiddenFields = array();
210 
211  foreach($this->__objects as $obj)
212  {
213  $hidden = $obj->getHiddenFields();
214  if ($hidden) array_merge($hiddenFields, $hidden);
215  }
216 
217  return $hiddenFields;
218  }

◆ getPrimaryKey()

CompositeDataItem::getPrimaryKey ( )

Retrieves the primary key field name.

Reimplemented from AbstractDataItem.

Definition at line 254 of file composite_data_item.inc.

255  {
256  // Primary key field for the composite object is the primary key field of the outermost object.
257 
258  return $this->__objects[0]->getPrimaryKey();
259  }

◆ getPrimaryKeyList()

CompositeDataItem::getPrimaryKeyList ( )

Retrieves a list of all the primary keys used for an object as an array.

Returns
array all the primary keys for this object's constituent parts

Reimplemented from AbstractDataItem.

Definition at line 265 of file composite_data_item.inc.

266  {
267  $pk = array();
268 
269  foreach($this->__objects as $obj)
270  {
271  $pk = array_merge($pk, $obj->getPrimaryKeyList());
272  }
273 
274  return $pk;
275  }

◆ getTransaction()

CompositeDataItem::getTransaction ( )

Retrieves the current DataTransaction.

Reimplemented from AbstractDataItem.

Definition at line 107 of file composite_data_item.inc.

108  {
109  return $this->__tx;
110  }

◆ getType()

CompositeDataItem::getType (   $field)

Retrieves the data type of the specified field.

Parameters
$fieldthe field in question
Returns
string the data type of the specified field

Reimplemented from AbstractDataItem.

Definition at line 310 of file composite_data_item.inc.

311  {
312  foreach($this->__objects as $obj)
313  {
314  if ($obj->hasField($field)) return $obj->getType($field);
315  }
316 
317  return null;
318  }

◆ groupedQuery()

CompositeDataItem::groupedQuery (   $constraints = "",
  $indexBy = "" 
)

Performs a query against the database, returning an array of arrays of CompositeDataItem objects of the specified class, grouped by a particular field.

If the indexing field has unique values, indexedQuery() might be more appropriate.

Parameters
string$constraintsoptional constraint clause to apply to the query in the form "WHERE ... [ORDER BY ...]"
string$fieldoptional the name of the field by which to group the results

Definition at line 837 of file composite_data_item.inc.

838  {
839  $field = "";
840  $idxClass = "";
841 
842  if ($indexBy != "")
843  {
844  list($idxClass, $field) = explode(".", $indexBy);
845  }
846  else
847  {
848  $idxClass = $this->class[0];
849  $obj = new $class;
850  $field = $obj->primary_key;
851  }
852 
853  trace("InnerJoin::groupedQuery(): Group by $idxClass $field", 3);
854 
855  $query = $this->generateQuery($constraints);
856 
857  try
858  {
860  $result = $db->prepare($query);
861  $result->execute();
862 
863  $items = array();
864 
865  while($line = $result->fetch())
866  {
867  $item = new JoinResult($this->tag);
868 
869  for($i = 0; $i < count($this->classes); ++$i)
870  {
871  $class = $this->classes[$i];
872  $item->$class = new $class; //Hack to work around PHP's stupid implementation of get_class()
873  $item->$class->populate($line);
874  }
875 
876  $idx = $item->$idxClass->$field;
877  $items[$idx][] = $item;
878  }
879 
880  unset($result);
881 
882  return $items;
883  }
884  catch(PDOException $e)
885  {
886  die("InnerJoin::groupedQuery() failed - ".$e->getMessage());
887  }
888  }
static getConnection()
Retrieves a reference to the global database connection.
JoinResult is an empty placeholder class.
Definition: join.inc:46
trace($msg, $lvl=3, $callStack=null)
Send output to the trace log.
Definition: functions.inc:1010

◆ hasField()

CompositeDataItem::hasField (   $field)

Returns true if this DataItem contains a field with the specified name and that field is not excluded by a filter.

Parameters
string$field
Returns
true if this field is present and not filtered, false otherwise.

Reimplemented from AbstractDataItem.

Definition at line 197 of file composite_data_item.inc.

198  {
199  foreach($this->__objects as $obj)
200  {
201  if ($obj->hasField($field)) return true;
202  }
203 
204  return false;
205  }

◆ hasRelation()

CompositeDataItem::hasRelation (   $relation)

Returns true if this DataItem contains a relation with the specified name.

Parameters
string$relation
Returns
true if this relation is present and not filtered, false otherwise.

Reimplemented from AbstractDataItem.

Definition at line 226 of file composite_data_item.inc.

227  {
228  foreach($this->__objects as $obj)
229  {
230  if ($obj->hasRelation($relation)) return true;
231  }
232 
233  return false;
234  }

◆ indexedQuery()

CompositeDataItem::indexedQuery (   $constraints = "",
  $indexBy = "" 
)

Performs a query against the database, returning an array of CompositeDataItem objects of the specified class, indexed by a particular field.

If more than one item is found that matches the same value of the indexing field, the results entry is promoted to an array automatically. However, in cases where this is common, using groupedQuery() might simplify your calling code.

Parameters
string$constraintsoptional constraint clause to apply to the query in the form "WHERE ... [ORDER BY ...]"
string$fieldoptional the name of the field by which to index the results (See InclusionFilter and ExclusionFilter)

Definition at line 768 of file composite_data_item.inc.

769  {
770  $field = "";
771  $idxClass = "";
772 
773  if ($indexBy != "")
774  {
775  list($idxClass, $field) = explode(".", $indexBy);
776  }
777  else
778  {
779  $idxClass = $this->class[0];
780  $obj = new $class;
781  $field = $obj->primary_key;
782  }
783 
784  $query = $this->generateQuery($constraints);
785 
786  try
787  {
789  $result = $db->prepare($query);
790  $result->execute();
791 
792  $items = array();
793 
794  while($line = $result->fetch())
795  {
796  $item = new JoinResult($this->tag);
797 
798  for($i = 0; $i < count($this->classes); ++$i)
799  {
800  $class = $this->classes[$i];
801  $item->$class = new $class; //Hack to work around PHP's stupid implementation of get_class()
802  $item->$class->populate($line);
803  }
804 
805  $idx = $item->$idxClass->$field;
806  if (array_key_exists($idx, $items))
807  {
808  // Implicitly promote to array if there is a collision
809  if (!is_array($items[$idx]))
810  {
811  $items[$idx] = array($items[$idx]);
812  }
813  $items[$idx][] = $item;
814  }
815  else
816  {
817  $items[$idx] = $item;
818  }
819  }
820 
821  unset($result);
822 
823  return $items;
824  }
825  catch(PDOException $e)
826  {
827  die("InnerJoin::indexedQuery() failed - ".$e->getMessage());
828  }
829  }

◆ insert()

CompositeDataItem::insert ( )

Insert a new row in the database to store this object.

Reimplemented from AbstractDataItem.

Definition at line 490 of file composite_data_item.inc.

491  {
492  // Insert and chain primary/foreign keys, from the inside out
493 
494  $num = count($this->__objects);
495 
496  for($i = $num - 1; $i >= 0; --$i)
497  {
498  $this->__objects[$i]->insert();
499  if ($i > 0)
500  {
501  $pk = $this->__objects[$i]->getPrimaryKey();
502  $this->__objects[$i - 1]->set($pk, $this->__objects[$i]->get($pk));
503  }
504  }
505  }

◆ joinTransaction()

CompositeDataItem::joinTransaction (   $tx)

Join the DataItem to the specified DataTransaction.

Parameters
DataTransaction$txthe transaction to join

Reimplemented from AbstractDataItem.

Definition at line 94 of file composite_data_item.inc.

95  {
96  foreach($this->__objects as $obj)
97  {
98  $obj->joinTransaction($tx);
99  }
100 
101  $this->__tx = $tx;
102  }

◆ load()

CompositeDataItem::load (   $id)

Load the object with the specified primary key.

Parameters
intid the primary key value to instantiate from

Reimplemented from AbstractDataItem.

Definition at line 389 of file composite_data_item.inc.

390  {
391  // Load from the outside in, chaining on the
392  // primary key/foreign key relationship at each level
393 
394  $num = count($this->__objects);
395 
396  for($i = 0; $i < $num; ++$i)
397  {
398  $this->__objects[$i]->load($id);
399 
400  if ($i == $num - 1) continue;
401 
402  $id = $this->__objects[$i]->get($this->__objects[$i+1]->getPrimaryKey());
403  }
404  }
getPrimaryKey()
Retrieves the primary key field name.

◆ loadFromBase()

CompositeDataItem::loadFromBase (   $id)

Definition at line 406 of file composite_data_item.inc.

407  {
408  $num = count($this->__objects);
409 
410  $this->__objects[$num - 1]->load($id);
411 
412  for($i = $num - 2; $i >= 0; --$i)
413  {
414  trace("BOOGER!", 3);
415  $pk = $this->__objects[$i+1]->getPrimaryKey();
416  $cl = get_class($this->__objects[$i]);
417  $obj = querySingle($cl, "WHERE $pk=".$this->__objects[$i+1]->get($pk));
418  $this->__objects[$i] = $obj;
419  $this->$cl = $obj;
420  }
421  }
querySingle($class)
Performs a query against the database and returns a matching singleton object.
Definition: data_item.inc:1810

◆ populate()

CompositeDataItem::populate (   $line)

Populates the object using the supplied associative array (field -> value).

Only values that match the definition of the sub-classed object will be copied. Fields that have been excluded by the use of an InclusionFilter or ExclusionFilter will also not be populated.

Parameters
array$linethe array of values to populate the object with.

Reimplemented from AbstractDataItem.

Definition at line 120 of file composite_data_item.inc.

121  {
122  // Load all component objects from the outside in.
123 
124  $this->__objects[0]->populate($line);
125  $num = count($this->__objects);
126 
127  for($i = 1; $i < num; ++$i)
128  {
129  $pk = $this->__objects[$i];
130  $key = $obj->get($pk);
131  $obj->load($key);
132  }
133  }

◆ prettifyClassName()

CompositeDataItem::prettifyClassName (   $plural = false)

Reimplemented from AbstractDataItem.

Definition at line 690 of file composite_data_item.inc.

691  {
692  $c = ($this->pretty_class_name) ? $this->pretty_class_name : get_class($this);
693  $c = preg_replace(array("/([a-z])([A-Z0-9])/",
694  "/_/"),
695  array("$1 $2",
696  " "),
697  $c);
698  $c = ucwords($c);
699 
700  if ($plural)
701  {
702  pluralize($c);
703  }
704 
705  return $c;
706  }
pluralize($text, $count=0)
Takes a singular string and makes it plural.
Definition: functions.inc:1428

◆ prettifyFieldName()

CompositeDataItem::prettifyFieldName (   $field)

Reimplemented from AbstractDataItem.

Definition at line 679 of file composite_data_item.inc.

680  {
681  foreach($this->__objects as $obj)
682  {
683  if ($obj->hasField($field)) return $obj->prettifyFieldName($field);
684  }
685 
686  return $field;
687  }

◆ query()

CompositeDataItem::query (   $constraints = "",
  $page = -1,
  $size = -1 
)

Definition at line 731 of file composite_data_item.inc.

732  {
733  $join = new InnerJoin();
734  foreach($this->__objects as $obj)
735  {
736  $join->add(get_class($obj));
737  }
738 
739  $joinResults = $join->query($constraints, $page, $size);
740 
741  $results = array();
742 
743  foreach($joinResults as $result)
744  {
745  $obj = clone($this);
746  foreach($obj->__objects as $target)
747  {
748  $cl = get_class($target);
749  $target->copy($result->$cl);
750  }
751 
752  $results[] = $obj;
753  }
754 
755  return $results;
756  }
This class is used to programmatically perform inner join queries across multiple objects.
Definition: join.inc:648

◆ relateTo()

CompositeDataItem::relateTo (   $target,
  $field = "" 
)

Link this object to the specified target by setting corresponding field to the value of the target's primary key.

Parameters
DataItem$targetthe DataItem to which the relationship will be created
string$fieldthe field to set for the relationship. If not specified, the primary key of the target object is used for the foreign key field name.

Reimplemented from AbstractDataItem.

Definition at line 716 of file composite_data_item.inc.

717  {
718  if ($field == "") $field = $target->getPrimaryKey();
719 
720  foreach($this->__objects as $obj)
721  {
722  if ($obj->hasField($field))
723  {
724  $obj->relateTo($target, $field);
725  return;
726  }
727  }
728  }

◆ save()

CompositeDataItem::save ( )

Store the object in the database.

Reimplemented from AbstractDataItem.

Definition at line 426 of file composite_data_item.inc.

427  {
428  // Save from the inside out, chaining on the
429  // primary key/foreign key relationship at each level
430  $num = count($this->__objects);
431 
432  for($i = $num - 1; $i >= 0; --$i)
433  {
434  if ($this->__objects[$i]->hasField("composite_class"))
435  {
436  $this->__objects[$i]->set("composite_class", get_class($this));
437  }
438 
439  $this->__objects[$i]->save();
440  if ($i != 0)
441  {
442  $pk = $this->__objects[$i]->getPrimaryKey();
443  $this->__objects[$i - 1]->set($pk, $this->__objects[$i]->get($pk));
444  }
445  }
446  }
hasField($field)
Returns true if this DataItem contains a field with the specified name and that field is not excluded...

◆ select()

CompositeDataItem::select ( )

Select the object from the database, based on the value of the primary key field.

Reimplemented from AbstractDataItem.

Definition at line 451 of file composite_data_item.inc.

452  {
453  // Select from the outside in, chaining on the
454  // primary key/foreign key relationship at each level
455 
456  $this->__objects[0]->select();
457 
458  $num = count($this->__objects);
459 
460  for($i = 1; $i < $num; $i)
461  {
462  $pk = $this->__objects[$i]->getPrimaryKey();
463  $this->__objects[$i]->set($pk, $this->__objects[$i - 1]->get($pk));
464  $this->__objects[$i]->select();
465  }
466  }

◆ set()

CompositeDataItem::set (   $field,
  $value 
)

Set the value of the specified field.

Parameters
$fieldthe field to set
$valuethe value to which the field is to be set

Reimplemented from AbstractDataItem.

Definition at line 297 of file composite_data_item.inc.

298  {
299  foreach($this->__objects as $obj)
300  {
301  if ($obj->hasField($field)) $obj->set($field, $value);
302  }
303  }

◆ setFilter()

CompositeDataItem::setFilter (   $filter)

Sets the filter on this object.

Parameters
$filterthe filter

Reimplemented from AbstractDataItem.

Definition at line 332 of file composite_data_item.inc.

333  {
334  foreach($this->__objects as $obj)
335  {
336  $obj->setFilter($filter);
337  }
338  }

◆ toXML()

CompositeDataItem::toXML (   $indent = 0,
  $path = null 
)

Generates an XML representation of the object.

Filters are honored when determining which fields are included in the XML. Empty fields are not output (note that a string field with value "" is not considered empty).

Reimplemented from AbstractDataItem.

Definition at line 637 of file composite_data_item.inc.

638  {
639  $xml = str_repeat(" ", $indent) . "<" . get_class($this) . ">\n";
640  foreach ($this as $field => $val)
641  {
642  if (is_object($val))
643  {
644  $xml .= $val->toXML($indent + 1);
645  }
646  }
647 
648  $xml .= str_repeat(" ", $indent) . "</" . get_class($this) . ">\n";
649 
650  return $xml;
651  }

◆ update()

CompositeDataItem::update ( )

Update the row in the database that corresponds to this object.

Reimplemented from AbstractDataItem.

Definition at line 479 of file composite_data_item.inc.

480  {
481  foreach($this->__objects as $obj)
482  {
483  $obj->update();
484  }
485  }

Member Data Documentation

◆ $__objects

CompositeDataItem::$__objects

Definition at line 42 of file composite_data_item.inc.

◆ $__tx

CompositeDataItem::$__tx = null

Definition at line 43 of file composite_data_item.inc.


The documentation for this class was generated from the following file: