Framework  3.9
PivotItem Class Reference

PivotItems are dynamically constructed DataItems that map the results of PivotQueries. More...

+ Inheritance diagram for PivotItem:
+ Collaboration diagram for PivotItem:

Public Member Functions

 __construct ($fields, $baseClass, $primaryKey, $fieldAliases=array())
 Creates a new PivotItem. More...
 
 __call ($method, $args)
 Provide a relation pseudo-method that traverses back to the object at the base of the pivot. More...
 
 getTotal ()
 
- Public Member Functions inherited from DataItem
 DataItem ()
 Constructor. More...
 
 __sleep ()
 
 fireEvent ($event)
 Fires the specified event to all registered handlers. More...
 
 joinTransaction ($tx)
 Join the DataItem to the specified DataTransaction. More...
 
 getTransaction ()
 Retrieves the current DataTransaction. More...
 
 cast ($class)
 Cast this object to another class. More...
 
 disablePrimaryKey ()
 
 enablePrimaryKey ()
 
 getHiddenFields ()
 Retrieves the list of hidden fields. More...
 
 populate ($line, $alias=false)
 Populates the object using the supplied associative array (field -> value). More...
 
 getFields ()
 Retrieve the field type list for this object. More...
 
 overrideFieldType ($field, $type)
 Override the type for the specified field. 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...
 
 hasField ($field)
 Returns true if this DataItem contains a field with the specified name and that field is not excluded by a filter. More...
 
 hasRelation ($relation)
 Returns true if this DataItem contains a relation with the specified name. 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...
 
 pack ()
 The pack() method is called prior to persisting a DataItem to storage. More...
 
 unpack ()
 The unpack() method is called after populating a DataItem. More...
 
 load ($id)
 Load the object with the specified primary key. More...
 
 old ()
 Retrieves the currently stored state of the DataItem from the database and returns it as a new object. More...
 
 loadComposite ()
 Creates an outer CompositeDataItem from its base component. More...
 
 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...
 
 updateExplicit ($updates, $params=null)
 Executes an explicit update command against the database. 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...
 
 tableExists ()
 Check if the table for this class exists in the database. More...
 
 duplicate ()
 Persists a duplicate of the DataItem to the database under a new primary key. 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...
 
 fromDataSet ($params)
 Automatically populate the object based on a custom set of parameters (such as a filtered $_POST collection) More...
 
 compare ($to)
 Compare this object to another object. More...
 
 copy ($from)
 Copies values from another object, field by field. More...
 
 cloneFrom ($from)
 Copies values from another object, field by field, excluding the primary key. More...
 
 cacheLookup ($id)
 Populate the object from the local cache if the object is marked as "cacheLocal". More...
 
 getRelated ($class, $field="")
 Returns a single item related by the specified foreign key. More...
 
 getRelatedList ($class, $field="", $orderBy="")
 Returns a list of items that are related to this item. More...
 
 crossReference ($class, $xref, $orderBy="", $pkField="", $xrefField="")
 Returns a list of items related to this item via a cross-reference table. More...
 
 queryValue ($func)
 Query the database to calculate an aggregate value. 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...
 
 toJSON ()
 
 format ($template="", $separator=", ")
 Substitute values for field names in a string, with the fields formatted using their type's default format or according to the formatting template sting passed in. More...
 
 formatField ($template)
 
 formatThroughRelation ($template, $separator=", ")
 
 prettifyFieldName ($field)
 
 relateTo ($target, $field="")
 Link this object to the specified target by setting corresponding field to the value of the target's primary key. 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...
 
 populate ($line)
 Populates the object using the supplied associative array (field -> value). More...
 
 getPrimaryKeyValue ()
 Retrieves the primary key value. 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...
 
 prettifyClassName ($plural=false)
 

Public Attributes

 $fields = array()
 
 $fieldAliases = array()
 
 $relations = array()
 
 $baseClass
 
- Public Attributes inherited from DataItem
 $_tx = null
 
 $_pkDisabled = false
 
- Public Attributes inherited from AbstractDataItem
 $filter
 
 $_options = 0
 
 $_tx = null
 Tracks the current database transaction for each DataItem. More...
 
 $_decorations = null
 

Additional Inherited Members

- Static Public Member Functions inherited from DataItem
static registerEventHandler ($class, $event, $handler)
 Register an event handler for a specific event and DataItem class. More...
 
- Static Public Attributes inherited from DataItem
static $_eventMap = array()
 
static $dataTypeRendererMap
 

Detailed Description

PivotItems are dynamically constructed DataItems that map the results of PivotQueries.

They can be used interchangeably with standard DataItems (for instance, in DataListViews, PagedLists, etc). PivotItems are automatically provided with a relation back to the class at the base of the pivot.

Author
Andy Green

Definition at line 567 of file pivot.inc.

Constructor & Destructor Documentation

◆ __construct()

PivotItem::__construct (   $fields,
  $baseClass,
  $primaryKey,
  $fieldAliases = array() 
)

Creates a new PivotItem.

Parameters
array$fieldsthe field map for the PivotItem
string$baseClassthe base class from the pivot
unknown$primaryKeythe primary key field (usually the primary key of the base class)
unknown$fieldAliasesthe field aliases map for the PivotItem

Definition at line 582 of file pivot.inc.

583  {
584  $this->fields = $fields;
585  $this->primary_key = $primaryKey;
586  $this->baseClass = $baseClass;
587  $this->fieldAliases = $fieldAliases;
588 
589  $this->relations = array($baseClass => $baseClass);
590  parent::__construct();
591  }
$fieldAliases
Definition: pivot.inc:570
$baseClass
Definition: pivot.inc:573

Member Function Documentation

◆ __call()

PivotItem::__call (   $method,
  $args 
)

Provide a relation pseudo-method that traverses back to the object at the base of the pivot.

Definition at line 597 of file pivot.inc.

598  {
599  // Provide a relation traversal pseudo-method that
600  // allows traversal back to the base object for the
601  // pivot
602 
603  if ($this->baseClass == $method)
604  {
605  return $this->getRelated($this->baseClass);
606  }
607  }
getRelated($class, $field="")
Returns a single item related by the specified foreign key.
Definition: data_item.inc:1210

◆ getTotal()

PivotItem::getTotal ( )

Definition at line 609 of file pivot.inc.

610  {
611  $total = 0.0;
612 
613  foreach($this->fields as $field => $type)
614  {
615  if ($field != $this->primary_key)
616  {
617  $total += $this->get($field);
618  }
619  }
620 
621  return $total;
622  }

Member Data Documentation

◆ $baseClass

PivotItem::$baseClass

Definition at line 573 of file pivot.inc.

◆ $fieldAliases

PivotItem::$fieldAliases = array()

Definition at line 570 of file pivot.inc.

◆ $fields

PivotItem::$fields = array()

Definition at line 569 of file pivot.inc.

◆ $relations

PivotItem::$relations = array()

Definition at line 571 of file pivot.inc.


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