/** * Convert this object to an array containing the resolved values. * * @param bool $resolveRelations * @return array * @throws \Exception */ public function toValues($resolveRelations = TRUE) { $result['uid'] = $this->uid; $propertiesAndValues = json_decode(json_encode($this), TRUE); foreach ($propertiesAndValues as $propertyName => $value) { $fieldName = Property::name($propertyName)->of($this)->toFieldName(); $result[$fieldName] = $value; if ($resolveRelations) { $field = Tca::table($this->dataType)->field($fieldName); $resolvedValue = ''; if ($field->getType() === FieldType::FILE) { if ($field->hasMany()) { $files = FileReferenceService::getInstance()->findReferencedBy($propertyName, $this); $resolvedValue = array(); foreach ($files as $file) { $resolvedValue[] = $file->getIdentifier(); } } else { $files = FileReferenceService::getInstance()->findReferencedBy($propertyName, $this); if (!empty($files)) { $resolvedValue = current($files)->getIdentifier(); } } // Reset value $result[$fieldName] = $resolvedValue; } elseif (Tca::table($this->dataType)->field($fieldName)->hasRelation()) { $objects = $this[$fieldName]; if (is_array($objects)) { $resolvedValue = array(); foreach ($objects as $object) { /** @var $object Content */ $labelField = Tca::table($object->getDataType())->getLabelField(); $resolvedValue[] = $object[$labelField]; } } elseif ($objects instanceof Content) { $labelField = Tca::table($objects->getDataType())->getLabelField(); $resolvedValue = $objects[$labelField]; } // Reset value $result[$fieldName] = $resolvedValue; } } } return $result; }
/** * Fetch the files given an object. * * @param \Fab\Vidi\Domain\Model\Content $object * @return void */ protected function collectFiles(Content $object) { foreach ($this->fileTypeProperties as $property) { $files = FileReferenceService::getInstance()->findReferencedBy($property, $object); foreach ($files as $file) { $this->collectedFiles[$file->getUid()] = $file; } } }