/** * Check whether $Content object is valid. * * @param Content $content * @throws \Exception * @return void */ public function validate(Content $content) { // Security check. if ($content->getUid() <= 0) { throw new MissingIdentifierException('Missing identifier for Content Object', 1351605542); } }
/** * Process File with action "move". * * @param Content $content * @param string $target * @throws \Exception * @return bool */ public function processMove(Content $content, $target) { $file = ResourceFactory::getInstance()->getFileObject($content->getUid()); if ($this->getMediaModule()->hasFolderTree()) { $targetFolder = $this->getMediaModule()->getCurrentFolder(); if ($targetFolder->getIdentifier() !== $file->getParentFolder()->getIdentifier()) { // Move file $file->moveTo($targetFolder, $file->getName(), 'renameNewFile'); } } else { // Only process if the storage is different. if ((int) $file->getStorage()->getUid() !== (int) $target) { $targetStorage = ResourceFactory::getInstance()->getStorageObject((int) $target); // Retrieve target directory in the new storage. The folder will only be returned if the User has the correct permission. $targetFolder = $this->getMediaModule()->getDefaultFolderInStorage($targetStorage, $file); try { // Move file $file->moveTo($targetFolder, $file->getName(), 'renameNewFile'); } catch (\Exception $e) { $this->errorMessages = $e->getMessage(); } } } return TRUE; }
/** * Fetch the files given an object assuming * * @param $propertyName * @param Content $object * @return File[] */ protected function findByFileReference($propertyName, Content $object) { $fileField = 'uid_local'; $tableName = 'sys_file_reference'; $clause = sprintf('tablenames = "%s" %s AND fieldname = "%s" AND uid_foreign = %s', $object->getDataType(), $this->getWhereClauseForEnabledFields($tableName), GeneralUtility::camelCaseToLowerCaseUnderscored($propertyName), $object->getUid()); $rows = $this->getDatabaseConnection()->exec_SELECTgetRows($fileField, $tableName, $clause); // Build array of Files $files = array(); foreach ($rows as $row) { $files[] = ResourceFactory::getInstance()->getFileObject($row[$fileField]); } return $files; }
/** * @param Content $object * @param string $fieldNameAndPath * @return string */ public function getDataType(Content $object, $fieldNameAndPath) { // Important to notice the field name can contains a path, e.g. metadata.title and must be sanitized. $relationalFieldName = $this->getFieldPathResolver()->stripFieldName($fieldNameAndPath); // ex: metadata.title -> metadata // Handle case when field name leads to a relation. if ($object[$relationalFieldName] instanceof Content) { $resolvedDataType = $object[$relationalFieldName]->getDataType(); } else { $resolvedDataType = $object->getDataType(); } return $resolvedDataType; }
/** * Convert a file representation to File Resource. * * @param Content|int $fileRepresentation * @throws \RuntimeException * @return File */ public function convert($fileRepresentation) { if ($fileRepresentation instanceof Content) { $fileData = $fileRepresentation->toArray(); if (!isset($fileData['storage']) && $fileData['storage'] === NULL) { throw new \RuntimeException('Storage identifier can not be null.', 1379946981); } $fileUid = $fileData['uid']; } else { $fileData = array(); $fileUid = (int) $fileRepresentation; } return ResourceFactory::getInstance()->getFileObject($fileUid, $fileData); }
/** * Tells whether a Content is related to another content. * The $fieldName corresponds to the relational field name * between the first content object and the second. * * @param \Fab\Vidi\Domain\Model\Content $relatedContent * @return boolean */ public function render($relatedContent) { $isChecked = FALSE; // Only computes whether the object is checked if one row is beeing edited. $numberOfObjects = $this->templateVariableContainer->get('numberOfObjects'); if ($numberOfObjects === 1) { /** @var \Fab\Vidi\Domain\Model\Content $content */ $content = $this->templateVariableContainer->get('content'); $fieldName = $this->templateVariableContainer->get('fieldName'); // Build an array of user group uids $relatedContentsIdentifiers = array(); /** @var \Fab\Vidi\Domain\Model\Content $contentObject */ foreach ($content[$fieldName] as $contentObject) { $relatedContentsIdentifiers[] = $contentObject->getUid(); } $isChecked = in_array($relatedContent->getUid(), $relatedContentsIdentifiers); } return $isChecked; }
/** * @param Content $object * @return string */ protected function getEditUri(Content $object) { $hiddenField = Tca::table()->getHiddenField(); $additionalParameters = array($this->getModuleLoader()->getParameterPrefix() => ['controller' => 'Content', 'action' => 'update', 'format' => 'json', 'fieldNameAndPath' => Tca::table()->getHiddenField(), 'matches' => ['uid' => $object->getUid()], 'content' => [$hiddenField => (int) (!$this->object[$hiddenField])]]); return $this->getModuleLoader()->getModuleUrl($additionalParameters); }
/** * Removes an object from this repository. * * @param Content $content * @return boolean */ public function remove($content) { $dataType = $content->getDataType(); $handler = $this->getDataHandlerFactory()->action(ProcessAction::REMOVE)->forType($dataType)->getDataHandler(); $handlerResult = $handler->processRemove($content); $this->errorMessages = $handler->getErrorMessages(); return $handlerResult; }
/** * @param Content $object * @return string */ protected function getImageEditorUri(Content $object) { $urlParameters = array(MediaModule::getParameterPrefix() => array('controller' => 'ImageEditor', 'action' => 'show', 'file' => $object->getUid())); return BackendUtility::getModuleUrl(MediaModule::getSignature(), $urlParameters); }
/** * @param Content $object * @return string */ protected function getEditParameterName(Content $object) { return sprintf('edit[%s][%s]', $object->getDataType(), $object->getUid()); }
/** * @param Content $object * @return string */ protected function getFilePickerUri(Content $object) { $urlParameters = array(MediaModule::getParameterPrefix() => array('controller' => 'Asset', 'action' => 'download', 'file' => $object->getUid())); return BackendUtility::getModuleUrl(MediaModule::getSignature(), $urlParameters); }
/** * Check whether the given object is meant to include files in some fields. * * @param Content $object * @return void */ protected function checkWhetherObjectMayIncludeFiles(Content $object) { if (Tca::grid($object->getDataType())->areFilesIncludedInExport()) { foreach ($object->toFields() as $fieldName) { $fieldType = Tca::table($object->getDataType())->field($fieldName)->getType(); if ($fieldType === FieldType::FILE) { $this->fileTypeProperties[] = GeneralUtility::camelCaseToLowerCaseUnderscored($fieldName); } } } }
/** * Process Content with action "localize". * * @param Content $content * @param int $language * @return bool */ public function processLocalize(Content $content, $language) { $command[$content->getDataType()][$content->getUid()]['localize'] = $language; $dataHandler = $this->getDataHandler(); $dataHandler->start(array(), $command); $dataHandler->process_datamap(); $dataHandler->process_cmdmap(); $this->errorMessages = $dataHandler->errorLog; // Returns TRUE is log does not contain errors. return empty($dataHandler->errorLog); }
/** * @param Content $object * @return string */ protected function getDeleteUri(Content $object) { $additionalParameters = array($this->getModuleLoader()->getParameterPrefix() => array('controller' => 'Content', 'action' => 'delete', 'format' => 'json', 'matches' => array('uid' => $object->getUid()))); return $this->getModuleLoader()->getModuleUrl($additionalParameters); }
/** * Process the value * * @todo implement me as a processor chain to be cleaner implementation wise. Look out at the performance however! * e.g DefaultValueGridProcessor, TextAreaGridProcessor, ... * * @param string $value * @param \Fab\Vidi\Domain\Model\Content $object * @param string $fieldNameAndPath * @return string */ protected function processValue($value, Content $object, $fieldNameAndPath) { // Set default value if $field name correspond to the label of the table $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath); if (Tca::table($object->getDataType())->getLabelField() === $fieldName && empty($value)) { $value = sprintf('[%s]', $this->getLabelService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.no_title', 1)); } // Sanitize the value in case of "select" or "radio button". if (is_scalar($value)) { $fieldType = Tca::table($object->getDataType())->field($fieldNameAndPath)->getType(); if ($fieldType !== FieldType::TEXTAREA) { $value = htmlspecialchars($value); } elseif ($fieldType === FieldType::TEXTAREA && !$this->isClean($value)) { $value = htmlspecialchars($value); // Avoid bad surprise, converts characters to HTML. } elseif ($fieldType === FieldType::TEXTAREA && !$this->hasHtml($value)) { $value = nl2br($value); } } return $value; }
/** * Returns a "table" service instance ("ctrl" part of the TCA). * * @param string|Content $tableNameOrContentObject * @return \Fab\Vidi\Tca\TableService */ public static function table($tableNameOrContentObject = '') { $tableName = $tableNameOrContentObject instanceof Content ? $tableNameOrContentObject->getDataType() : $tableNameOrContentObject; return self::getService($tableName, self::TYPE_TABLE); }
/** * @param string|Content $tableNameOrContentObject * @return $this */ public function of($tableNameOrContentObject) { // Resolve the table name. self::$currentTable = $tableNameOrContentObject instanceof Content ? $tableNameOrContentObject->getDataType() : $tableNameOrContentObject; return $this; }
/** * Returns the title of a content object. * * @param Content $content * @return string */ public function render(Content $content) { $table = Tca::table($content->getDataType()); return $content[$table->getLabelField()]; }