public function getForeignIDFilter(RelationList $on = null)
 {
     if (!$on) {
         return;
     }
     return $on->foreignIDFilter();
 }
 /**
  * Save all the items in this list into the RelationList
  *
  * @param RelationList $list
  */
 public function changeToList(RelationList $list)
 {
     foreach ($this->items as $key => $item) {
         if (is_object($item)) {
             $item->write();
         }
         $list->add($item, $this->extraFields[$key]);
     }
 }
Пример #3
0
 /**
  * Create a new ManyManyList object.
  * 
  * A ManyManyList object represents a list of DataObject records that correspond to a many-many
  * relationship.  In addition to, 
  * 
  * Generation of the appropriate record set is left up to the caller, using the normal
  * {@link DataList} methods.  Addition arguments are used to support {@@link add()}
  * and {@link remove()} methods.
  * 
  * @param string $dataClass The class of the DataObjects that this will list.
  * @param string $joinTable The name of the table whose entries define the content of this many_many relation.
  * @param string $localKey The key in the join table that maps to the dataClass' PK.
  * @param string $foreignKey The key in the join table that maps to joined class' PK.
  * @param string $extraFields A map of field => fieldtype of extra fields on the join table.
  * 
  * @example new ManyManyList('Group','Group_Members', 'GroupID', 'MemberID');
  */
 public function __construct($dataClass, $joinTable, $localKey, $foreignKey, $extraFields = array())
 {
     parent::__construct($dataClass);
     $this->joinTable = $joinTable;
     $this->localKey = $localKey;
     $this->foreignKey = $foreignKey;
     $this->extraFields = $extraFields;
     $baseClass = ClassInfo::baseDataClass($dataClass);
     // Join to the many-many join table
     $this->dataQuery->innerJoin($joinTable, "\"{$joinTable}\".\"{$this->localKey}\" = \"{$baseClass}\".\"ID\"");
     // Query the extra fields from the join table
     if ($extraFields) {
         $this->dataQuery->selectFromTable($joinTable, array_keys($extraFields));
     }
 }
Пример #4
0
 /**
  * Create a DataObject from the given SQL row.
  *
  * @param array $row
  * @return DataObject
  */
 protected function createDataObject($row)
 {
     // remove any composed fields
     $add = array();
     if ($this->_compositeExtraFields) {
         foreach ($this->_compositeExtraFields as $fieldName => $composed) {
             // convert joined extra fields into their composite field types.
             $value = array();
             foreach ($composed as $subField => $subSpec) {
                 if (isset($row[$fieldName . $subSpec])) {
                     $value[$subSpec] = $row[$fieldName . $subSpec];
                     // don't duplicate data in the record
                     unset($row[$fieldName . $subSpec]);
                 }
             }
             $obj = Object::create_from_string($this->extraFields[$fieldName], $fieldName);
             $obj->setValue($value, null, false);
             $add[$fieldName] = $obj;
         }
     }
     $dataObject = parent::createDataObject($row);
     foreach ($add as $fieldName => $obj) {
         $dataObject->{$fieldName} = $obj;
     }
     return $dataObject;
 }
Пример #5
0
 /**
  * Create a new HasManyList object.
  * Generation of the appropriate record set is left up to the caller, using the normal
  * {@link DataList} methods.  Addition arguments are used to support {@@link add()}
  * and {@link remove()} methods.
  *
  * @param string $dataClass The class of the DataObjects that this will list.
  * @param string $foreignKey The name of the foreign key field to set the ID filter against.
  */
 public function __construct($dataClass, $foreignKey)
 {
     parent::__construct($dataClass);
     $this->foreignKey = $foreignKey;
 }