Пример #1
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;
 }
Пример #2
0
 /**
  * Remove related objects
  *
  * @param Tx_Extbase_DomainObject_DomainObjectInterface $object The object to scanned for related objects
  * @return void
  */
 protected function removeRelatedObjects(Tx_Extbase_DomainObject_DomainObjectInterface $object)
 {
     $className = get_class($object);
     $dataMap = $this->dataMapper->getDataMap($className);
     $classSchema = $this->reflectionService->getClassSchema($className);
     $properties = $object->_getProperties();
     foreach ($properties as $propertyName => $propertyValue) {
         $columnMap = $dataMap->getColumnMap($propertyName);
         $propertyMetaData = $classSchema->getProperty($propertyName);
         if ($propertyMetaData['cascade'] === 'remove') {
             if ($columnMap->getTypeOfRelation() === Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_MANY) {
                 foreach ($propertyValue as $containedObject) {
                     $this->removeObject($containedObject);
                 }
             } elseif ($propertyValue instanceof Tx_Extbase_DomainObject_DomainObjectInterface) {
                 $this->removeObject($propertyValue);
             }
         }
     }
 }
 protected function addUnionStatement(&$className, &$tableName, &$propertyPath, array &$sql)
 {
     $explodedPropertyPath = explode('.', $propertyPath, 2);
     $propertyName = $explodedPropertyPath[0];
     $columnName = $this->dataMapper->convertPropertyNameToColumnName($propertyName, $className);
     $tableName = $this->dataMapper->convertClassNameToTableName($className);
     $columnMap = $this->dataMapper->getDataMap($className)->getColumnMap($propertyName);
     $parentKeyFieldName = $columnMap->getParentKeyFieldName();
     $childTableName = $columnMap->getChildTableName();
     if ($columnMap->getTypeOfRelation() === Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_ONE) {
         if (isset($parentKeyFieldName)) {
             $sql['unions'][$childTableName] = 'LEFT JOIN ' . $childTableName . ' ON ' . $tableName . '.uid=' . $childTableName . '.' . $parentKeyFieldName;
         } else {
             $sql['unions'][$childTableName] = 'LEFT JOIN ' . $childTableName . ' ON ' . $tableName . '.' . $columnName . '=' . $childTableName . '.uid';
         }
         $className = $this->dataMapper->getType($className, $propertyName);
     } elseif ($columnMap->getTypeOfRelation() === Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_MANY) {
         if (isset($parentKeyFieldName)) {
             $sql['unions'][$childTableName] = 'LEFT JOIN ' . $childTableName . ' ON ' . $tableName . '.uid=' . $childTableName . '.' . $parentKeyFieldName;
         } else {
             $onStatement = '(' . $tableName . '.' . $columnName . ' LIKE CONCAT(\'%,\',' . $childTableName . '.uid,\',%\')';
             $onStatement .= ' OR ' . $tableName . '.' . $columnName . ' LIKE CONCAT(\'%,\',' . $childTableName . '.uid)';
             $onStatement .= ' OR ' . $tableName . '.' . $columnName . ' LIKE CONCAT(' . $childTableName . '.uid,\',%\'))';
             $sql['unions'][$childTableName] = 'LEFT JOIN ' . $childTableName . ' ON ' . $onStatement;
         }
         $className = $this->dataMapper->getType($className, $propertyName);
     } elseif ($columnMap->getTypeOfRelation() === Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY) {
         $relationTableName = $columnMap->getRelationTableName();
         $sql['unions'][$relationTableName] = 'LEFT JOIN ' . $relationTableName . ' ON ' . $tableName . '.uid=' . $relationTableName . '.uid_local';
         $sql['unions'][$childTableName] = 'LEFT JOIN ' . $childTableName . ' ON ' . $relationTableName . '.uid_foreign=' . $childTableName . '.uid';
         $className = $this->dataMapper->getType($className, $propertyName);
     } else {
         throw new Tx_Extbase_Persistence_Exception('Could not determine type of relation.', 1252502725);
     }
     // TODO check if there is another solution for this
     $sql['keywords']['distinct'] = 'DISTINCT';
     $propertyPath = $explodedPropertyPath[1];
     $tableName = $childTableName;
 }