/** * Gets files uploaded through field name $name * * @param Tx_Extbase_DomainObject_DomainObjectInterface $domainObject * @param string $propertyName Index name of the files in $_FILES * @param string $objectType Optional class name to use for uploaded file resources * @return Tx_Tool_Resource_FileResourceObjectStorage * @api */ public function getUploadedFiles(Tx_Extbase_DomainObject_DomainObjectInterface &$domainObject, $propertyName, $objectType = NULL) { if ($objectType === NULL) { $objectType = 'Tx_Tool_Resource_FileResource'; } $namespace = $this->domainService->getPluginNamespace($domainObject); $fileObjectStorage = $this->objectManager->create('Tx_Tool_Resource_FileResourceObjectStorage'); $postFiles = Tx_Extbase_Reflection_ObjectAccess::getProperty($_FILES[$namespace]['tmp_name'], $propertyName); if (is_array($postFiles) === FALSE) { $filename = $postFiles; $targetFilename = Tx_Extbase_Reflection_ObjectAccess::getProperty($_FILES[$namespace]['name'], $propertyName); if ($targetFilename && $targetFilename != '') { $object = $this->objectManager->create($objectType, $filename); $object->setTargetFilename($targetFilename); $fileObjectStorage->attach($object); return $fileObjectStorage; } } $numFiles = count($postFiles); for ($i = 0; $i < $numFiles; $i++) { $filename = Tx_Extbase_Reflection_ObjectAccess::getProperty($_FILES[$namespace]['tmp_name'], $propertyName . '.' . $i); $targetFilename = Tx_Extbase_Reflection_ObjectAccess::getProperty($_FILES[$namespace]['name'], $propertyName . '.' . $i); if ($targetFilename && $targetFilename != '') { if (is_file($filename)) { $object = $this->objectManager->get($objectType, $filename); $object->setTargetFilename($targetFilename); $fileObjectStorage->attach($object); } } } return $fileObjectStorage; }
/** * Define the source parent of this FileResourceObjectStorage - enables automatic * detection of $objectType and $basePath based on $propertyName and TCA. * * @param Tx_Extbase_DomainObject_AbstractDomainObject $associatedDomainObject * @param string $propertyName Name of the property in which this object is contained */ public function setAssociatedDomainObject(Tx_Extbase_DomainObject_AbstractDomainObject $associatedDomainObject, $propertyName) { $annotationValues = $this->domainService->getAnnotationValuesByProperty($associatedDomainObject, $propertyName, 'file'); // use collected data to set necessary precursor variables $this->objectType = array_pop($annotationValues); $this->associatedDomainObject = $associatedDomainObject; $this->associatedPropertyName = $propertyName; $this->basePath = $this->domainService->getUploadFolder($associatedDomainObject, $propertyName); }