Пример #1
0
 /**
  * Persists a an object storage. Objects of a 1:n or m:n relation are queued and processed with the parent object. A 1:1 relation
  * gets persisted immediately. Objects which were removed from the property were detached from the parent object. They will not be
  * deleted by default. You have to annotate the property with "@cascade remove" if you want them to be deleted as well.
  *
  * @param Tx_Extbase_Persistence_ObjectStorage $objectStorage The object storage to be persisted.
  * @param Tx_Extbase_DomainObject_DomainObjectInterface $parentObject The parent object. One of the properties holds the object storage.
  * @param string $propertyName The name of the property holding the object storage.
  * @param array $row The row array of the parent object to be persisted. It's passed by reference and gets filled with either a comma separated list of uids (csv) or the number of contained objects. 
  * @return void
  */
 protected function persistObjectStorage(Tx_Extbase_Persistence_ObjectStorage $objectStorage, Tx_Extbase_DomainObject_DomainObjectInterface $parentObject, $propertyName, array &$row)
 {
     $className = get_class($parentObject);
     $columnMap = $this->dataMapper->getDataMap($className)->getColumnMap($propertyName);
     $columnName = $columnMap->getColumnName();
     $propertyMetaData = $this->reflectionService->getClassSchema($className)->getProperty($propertyName);
     foreach ($this->getRemovedChildObjects($parentObject, $propertyName) as $removedObject) {
         if ($columnMap->getTypeOfRelation() === Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_MANY && $propertyMetaData['cascade'] === 'remove') {
             $this->removeObject($removedObject);
         } else {
             $this->detachObjectFromParentObject($removedObject, $parentObject, $propertyName);
         }
     }
     if ($columnMap->getTypeOfRelation() === Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY) {
         $this->deleteAllRelationsFromRelationtable($parentObject, $propertyName);
     }
     $currentUids = array();
     $sortingPosition = 1;
     foreach ($objectStorage as $object) {
         if ($object->_isNew()) {
             $this->insertObject($object);
         }
         $currentUids[] = $object->getUid();
         $this->attachObjectToParentObject($object, $parentObject, $propertyName, $sortingPosition);
         $sortingPosition++;
     }
     if ($columnMap->getParentKeyFieldName() === NULL) {
         $row[$columnMap->getColumnName()] = implode(',', $currentUids);
     } else {
         $row[$columnMap->getColumnName()] = $this->dataMapper->countRelated($parentObject, $propertyName);
     }
 }
Пример #2
0
 /**
  * Counts the elements in the storage array
  *
  * @return int The number of elements in the ObjectStorage
  */
 public function count()
 {
     $columnMap = $this->dataMapper->getDataMap(get_class($this->parentObject))->getColumnMap($this->propertyName);
     $numberOfElements = NULL;
     if ($columnMap->getTypeOfRelation() === Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_MANY) {
         $numberOfElements = $this->dataMapper->countRelated($this->parentObject, $this->propertyName, $this->fieldValue);
     } else {
         $this->initialize();
         $numberOfElements = count($this->storage);
     }
     if (is_null($numberOfElements)) {
         throw new Tx_Extbase_Persistence_Exception('The number of elements could not be determined.', 1252514486);
     }
     return $numberOfElements;
 }