コード例 #1
0
ファイル: MetadataRenderer.php プロジェクト: visol/media
 /**
  * Renders a configurable metadata property of a file in the Grid.
  *
  * @throws \Exception
  * @return string
  */
 public function render()
 {
     if (empty($this->gridRendererConfiguration['property'])) {
         throw new \Exception('Missing property value for Grid Renderer Metadata', 1390391042);
     }
     $file = $this->getFileConverter()->convert($this->object);
     $propertyName = $this->gridRendererConfiguration['property'];
     if ($propertyName === 'uid') {
         $metadata = $file->_getMetaData();
         $result = $metadata['uid'];
         // make an exception here to retrieve the uid of the metadata.
     } else {
         $result = $file->getProperty($propertyName);
     }
     // Avoid bad surprise, converts characters to HTML.
     $fieldType = Tca::table('sys_file_metadata')->field($propertyName)->getType();
     if ($fieldType !== FieldType::TEXTAREA) {
         $result = htmlentities($result);
     } elseif ($fieldType === FieldType::TEXTAREA && !$this->isClean($result)) {
         $result = htmlentities($result);
     } elseif ($fieldType === FieldType::TEXTAREA && !$this->hasHtml($result)) {
         $result = nl2br($result);
     }
     return $result;
 }
コード例 #2
0
ファイル: FacetValidator.php プロジェクト: lorenzulrich/vidi
 /**
  * Check if $facet is valid. If it is not valid, throw an exception.
  *
  * @param mixed $facet
  * @return void
  */
 public function isValid($facet)
 {
     if (!Tca::grid()->hasFacet($facet)) {
         $message = sprintf('Facet "%s" is not allowed. Actually, it was not configured to be displayed in the grid.', $facet);
         $this->addError($message, 1380019719);
     }
 }
コード例 #3
0
 /**
  * Returns whether the field in the context is localizable or not.
  *
  * @return string
  */
 public function render()
 {
     $dataType = $this->templateVariableContainer->get('dataType');
     $fieldName = $this->templateVariableContainer->get('fieldName');
     $isLanguageApplicable = Tca::table($dataType)->hasLanguageSupport() && Tca::table($dataType)->field($fieldName)->isLocalized();
     return $isLanguageApplicable;
 }
コード例 #4
0
 /**
  * Return whether the current field name has a relation to the main content.
  *
  * @return boolean
  */
 public function render()
 {
     $fieldNameAndPath = $this->templateVariableContainer->get('columnName');
     $dataType = $this->getFieldPathResolver()->getDataType($fieldNameAndPath);
     $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath);
     $hasRelation = Tca::table($dataType)->field($fieldName)->hasRelation();
     return $hasRelation;
 }
コード例 #5
0
 /**
  * Return the label field of the foreign table.
  *
  * @param string $fieldName
  * @return string
  */
 protected function getForeignTableLabelField($fieldName)
 {
     // Get TCA table service.
     $table = Tca::table($this->object);
     // Compute the label of the foreign table.
     $relationDataType = $table->field($fieldName)->relationDataType();
     return Tca::table($relationDataType)->getLabelField();
 }
コード例 #6
0
 /**
  * Check if $matches is valid. If it is not valid, throw an exception.
  *
  * @param mixed $matches
  * @return void
  */
 public function isValid($matches)
 {
     foreach ($matches as $fieldName => $value) {
         if (!Tca::table()->hasField($fieldName)) {
             $message = sprintf('Field "%s" is not allowed. Actually, it is not configured in the TCA.', $fieldName);
             $this->addError($message, 1380019718);
         }
     }
 }
コード例 #7
0
 /**
  * Check if $columns is valid. If it is not valid, throw an exception.
  *
  * @param mixed $columns
  * @return void
  */
 public function isValid($columns)
 {
     foreach ($columns as $columnName) {
         if (!Tca::grid()->hasField($columnName)) {
             $message = sprintf('Column "%s" is not allowed. Actually, it was not configured to be displayed in the grid.', $columnName);
             $this->addError($message, 1380019720);
         }
     }
 }
コード例 #8
0
 /**
  * Returns the json serialization of the search fields.
  *
  * @return boolean
  */
 public function render()
 {
     $facets = array();
     foreach (Tca::grid()->getFacets() as $facet) {
         /** @var FacetInterface $facet */
         $name = $facet->getName();
         $facets[$name] = $facet->getLabel();
     }
     return json_encode($facets);
 }
コード例 #9
0
 /**
  * Returns an order object.
  *
  * @return Order
  */
 public function getOrder()
 {
     // Default ordering
     $order = Tca::table($this->dataType)->getDefaultOrderings();
     if (!empty($this->settings['sorting'])) {
         $direction = empty($this->settings['direction']) ? 'ASC' : $this->settings['direction'];
         $order = array($this->settings['sorting'] => $direction);
     }
     return GeneralUtility::makeInstance(Order::class, $order);
 }
コード例 #10
0
ファイル: ConfigurationWarning.php プロジェクト: visol/media
 /**
  * @return boolean
  */
 protected function configureStorage()
 {
     $tableName = 'sys_file_storage';
     $fields = array('maximum_dimension_original_image', 'extension_allowed_file_type_1', 'extension_allowed_file_type_2', 'extension_allowed_file_type_3', 'extension_allowed_file_type_4', 'extension_allowed_file_type_5');
     $values = array();
     foreach ($fields as $field) {
         $values[$field] = Tca::table($tableName)->field($field)->getDefaultValue();
     }
     $storage = $this->getMediaModule()->getCurrentStorage();
     $this->getDatabaseConnection()->exec_UPDATEquery($tableName, 'uid = ' . $storage->getUid(), $values);
 }
コード例 #11
0
 /**
  * @return array
  */
 protected function getExcludedFieldsFromTca()
 {
     $tca = Tca::grid()->getTca();
     $excludedFields = array();
     if (!empty($tca['excluded_fields'])) {
         $excludedFields = GeneralUtility::trimExplode(',', $tca['excluded_fields'], TRUE);
     } elseif (!empty($tca['export']['excluded_fields'])) {
         // only for export for legacy reason.
         $excludedFields = GeneralUtility::trimExplode(',', $tca['export']['excluded_fields'], TRUE);
     }
     return $excludedFields;
 }
コード例 #12
0
ファイル: StandardFacet.php プロジェクト: BergischMedia/vidi
 /**
  * @return string
  */
 public function getLabel()
 {
     if ($this->label === $this->name) {
         $label = Tca::table($this->dataType)->field($this->getName())->getLabel();
     } else {
         $label = LocalizationUtility::translate($this->label, '');
         if (empty($label)) {
             $label = $this->label;
         }
     }
     return $label;
 }
コード例 #13
0
 /**
  * Tell whether the field looks ok to be displayed within the Grid.
  *
  * @param string $fieldNameAndPath
  * @return boolean
  */
 protected function isAllowed($fieldNameAndPath)
 {
     $dataType = $this->getFieldPathResolver()->getDataType($fieldNameAndPath);
     $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath);
     $isAllowed = FALSE;
     if (Tca::grid()->hasRenderers($fieldNameAndPath)) {
         $isAllowed = TRUE;
     } elseif (Tca::table()->field($fieldNameAndPath)->isSystem() || Tca::table($dataType)->hasField($fieldName)) {
         $isAllowed = TRUE;
     }
     return $isAllowed;
 }
コード例 #14
0
 /**
  * Render a representation of the relation on the GUI.
  *
  * @return string
  */
 public function render()
 {
     $template = '<div style="text-align: right" class="pull-right invisible"><a href="%s" class="btn-edit-relation" data-field-label="%s">%s</a></div>';
     // Initialize url parameters array.
     $urlParameters = array($this->getModuleLoader()->getParameterPrefix() => array('controller' => 'Content', 'action' => 'edit', 'matches' => array('uid' => $this->object->getUid()), 'fieldNameAndPath' => $this->getFieldName()));
     $fieldLabel = Tca::table()->field($this->getFieldName())->getLabel();
     if ($fieldLabel) {
         $fieldLabel = str_replace(':', '', $fieldLabel);
         // sanitize label
     }
     $result = sprintf($template, $this->getModuleLoader()->getModuleUrl($urlParameters), $fieldLabel, $this->getIconFactory()->getIcon('actions-edit-add', Icon::SIZE_SMALL));
     return $result;
 }
コード例 #15
0
 /**
  * Suggest values for all configured facets in the Grid.
  * Output a json list of key / values.
  *
  * @return string
  */
 public function autoSuggestsAction()
 {
     $suggestions = array();
     foreach (Tca::grid()->getFacets() as $facet) {
         /** @var FacetInterface $facet */
         $name = $facet->getName();
         $suggestions[$name] = $this->getFacetSuggestionService()->getSuggestions($name);
     }
     # Json header is not automatically sent in the BE...
     $this->response->setHeader('Content-Type', 'application/json');
     $this->response->sendHeaders();
     return json_encode($suggestions);
 }
コード例 #16
0
 /**
  * Retrieve possible suggestions for a field name
  *
  * @param string $fieldNameAndPath
  * @return array
  */
 public function getSuggestions($fieldNameAndPath)
 {
     $values = array();
     $dataType = $this->getFieldPathResolver()->getDataType($fieldNameAndPath);
     $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath);
     if (Tca::grid()->facet($fieldNameAndPath)->hasSuggestions()) {
         $values = Tca::grid()->facet($fieldNameAndPath)->getSuggestions();
     } else {
         if (Tca::table($dataType)->hasField($fieldName)) {
             if (Tca::table($dataType)->field($fieldName)->hasRelation()) {
                 // Fetch the adequate repository
                 $foreignTable = Tca::table($dataType)->field($fieldName)->getForeignTable();
                 $contentRepository = ContentRepositoryFactory::getInstance($foreignTable);
                 $table = Tca::table($foreignTable);
                 // Initialize the matcher object.
                 $matcher = MatcherObjectFactory::getInstance()->getMatcher(array(), $foreignTable);
                 $numberOfValues = $contentRepository->countBy($matcher);
                 if ($numberOfValues <= $this->getLimit()) {
                     $contents = $contentRepository->findBy($matcher);
                     foreach ($contents as $content) {
                         $values[] = array($content->getUid() => $content[$table->getLabelField()]);
                     }
                 }
             } elseif (!Tca::table($dataType)->field($fieldName)->isTextArea()) {
                 // We don't want suggestion if field is text area.
                 // Fetch the adequate repository
                 /** @var \Fab\Vidi\Domain\Repository\ContentRepository $contentRepository */
                 $contentRepository = ContentRepositoryFactory::getInstance($dataType);
                 // Initialize some objects related to the query
                 $matcher = MatcherObjectFactory::getInstance()->getMatcher(array(), $dataType);
                 // Count the number of objects.
                 $numberOfValues = $contentRepository->countDistinctValues($fieldName, $matcher);
                 // Only returns suggestion if there are not too many for the browser.
                 if ($numberOfValues <= $this->getLimit()) {
                     // Query the repository.
                     $contents = $contentRepository->findDistinctValues($fieldName, $matcher);
                     foreach ($contents as $content) {
                         $value = $content[$fieldName];
                         $label = $content[$fieldName];
                         if (Tca::table($dataType)->field($fieldName)->isSelect()) {
                             $label = Tca::table($dataType)->field($fieldName)->getLabelForItem($value);
                         }
                         $values[] = $label;
                     }
                 }
             }
         }
     }
     return $values;
 }
コード例 #17
0
 /**
  * Returns an order object.
  *
  * @param string $dataType
  * @return \Fab\Vidi\Persistence\Order
  */
 public function getOrder($dataType = '')
 {
     // Default ordering
     $order = Tca::table($dataType)->getDefaultOrderings();
     // Retrieve a possible id of the column from the request
     $orderings = GeneralUtility::_GP('order');
     if (is_array($orderings) && isset($orderings[0])) {
         $columnPosition = $orderings[0]['column'];
         $direction = $orderings[0]['dir'];
         if ($columnPosition > 0) {
             $field = Tca::grid()->getFieldNameByPosition($columnPosition);
             $order = array($field => strtoupper($direction));
         }
     }
     return GeneralUtility::makeInstance('Fab\\Vidi\\Persistence\\Order', $order);
 }
コード例 #18
0
 /**
  * Returns a value from the TCA Table service according to a key.
  *
  * @param string $key
  * @param string $dataType
  * @return string
  */
 public function render($key, $dataType = '')
 {
     $result = Tca::table($dataType)->getTca();
     // Explode segment and loop around.
     $keys = explode('|', $key);
     foreach ($keys as $key) {
         if (!empty($result[$key])) {
             $result = $result[$key];
         } else {
             // not found value
             $result = FALSE;
             break;
         }
     }
     return $result;
 }
コード例 #19
0
 /**
  * @param Content $object
  * @param string $propertyName
  * @return File[]
  */
 public function findReferencedBy($propertyName, Content $object)
 {
     if (!isset(self::$instances[$object->getUid()][$propertyName])) {
         // Initialize instances value
         if (!isset(self::$instances[$object->getUid()])) {
             self::$instances[$object->getUid()] = array();
         }
         $fieldName = GeneralUtility::camelCaseToLowerCaseUnderscored($propertyName);
         $field = Tca::table($object->getDataType())->field($fieldName);
         if ($field->getForeignTable() === 'sys_file_reference') {
             $files = $this->findByFileReference($propertyName, $object);
             self::$instances[$object->getUid()][$propertyName] = $files;
         } else {
             // @todo the standard way of handling file references is by "sys_file_reference". Let see if there is other use cases...
         }
     }
     return self::$instances[$object->getUid()][$propertyName];
 }
コード例 #20
0
 /**
  * @param \Fab\Vidi\Domain\Model\Content $object
  * @param $fieldNameAndPath
  * @param array $contentData
  * @param string $savingBehavior
  * @return array
  */
 protected function appendOrRemoveRelations(Content $object, $fieldNameAndPath, array $contentData, $savingBehavior)
 {
     foreach ($contentData as $fieldName => $values) {
         $resolvedObject = $this->getContentObjectResolver()->getObject($object, $fieldNameAndPath);
         if (Tca::table($resolvedObject)->field($fieldName)->hasMany()) {
             // TRUE means CSV values must be converted to array.
             if (!is_array($values)) {
                 $values = GeneralUtility::trimExplode(',', $values);
             }
             $relatedValues = $this->getRelatedValues($object, $fieldNameAndPath, $fieldName);
             foreach ($values as $value) {
                 $appendOrRemove = $savingBehavior . 'Relations';
                 $relatedValues = $this->{$appendOrRemove}($value, $relatedValues);
             }
             $contentData[$fieldName] = $relatedValues;
         }
     }
     return $contentData;
 }
コード例 #21
0
 /**
  * Check TCA configuration for relations used in grid.
  *
  * @param string $table the table name. If not defined check for every table.
  * @return void
  */
 public function analyseRelationsCommand($table = '')
 {
     foreach ($GLOBALS['TCA'] as $tableName => $TCA) {
         if ($table != '' && $table !== $tableName) {
             continue;
         }
         $fields = Tca::grid($tableName)->getFields();
         if (!empty($fields)) {
             $relations = $this->getGridAnalyserService()->checkRelationForTable($tableName);
             if (!empty($relations)) {
                 $this->outputLine();
                 $this->outputLine('--------------------------------------------------------------------');
                 $this->outputLine();
                 $this->outputLine(sprintf('Relations for "%s"', $tableName));
                 $this->outputLine();
                 $this->outputLine(implode("\n", $relations));
             }
         }
     }
 }
コード例 #22
0
 /**
  * Render a representation of the relation on the GUI.
  *
  * @return string
  */
 public function render()
 {
     $numberOfObjects = count($this->object[$this->fieldName]);
     if ($numberOfObjects > 1) {
         $label = 'LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:items';
         if (isset($this->gridRendererConfiguration['labelPlural'])) {
             $label = $this->gridRendererConfiguration['labelPlural'];
         }
     } else {
         $label = 'LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:item';
         if (isset($this->gridRendererConfiguration['labelSingular'])) {
             $label = $this->gridRendererConfiguration['labelSingular'];
         }
     }
     $template = '<a href="%s&returnUrl=%s&search=%s&query=%s:%s">%s %s<span class="invisible" style="padding-left: 5px">%s</span></a>';
     $foreignField = Tca::table($this->object)->field($this->fieldName)->getForeignField();
     $search = json_encode(array(array($foreignField => $this->object->getUid())));
     $moduleTarget = empty($this->gridRendererConfiguration['targetModule']) ? '' : $this->gridRendererConfiguration['targetModule'];
     return sprintf($template, BackendUtility::getModuleUrl($moduleTarget), rawurlencode(BackendUtility::getModuleUrl($this->gridRendererConfiguration['sourceModule'])), rawurlencode($search), rawurlencode($foreignField), rawurlencode($this->object->getUid()), htmlspecialchars($numberOfObjects), htmlspecialchars(LocalizationUtility::translate($label, '')), $this->getIconFactory()->getIcon('extensions-vidi-go', Icon::SIZE_SMALL));
 }
コード例 #23
0
ファイル: ModuleService.php プロジェクト: BergischMedia/vidi
 /**
  * Fetch all modules displayed given a pid.
  *
  * @param int $pid
  * @return array
  */
 public function getModulesForPid($pid = NULL)
 {
     if (!isset($this->storage[$pid])) {
         $modules = array();
         foreach ($GLOBALS['TCA'] as $dataType => $configuration) {
             if (Tca::table($dataType)->isNotHidden()) {
                 $clause = 'pid = ' . $pid;
                 $clause .= BackendUtility::deleteClause($dataType);
                 $record = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('uid', $dataType, $clause);
                 if (!empty($record)) {
                     $moduleName = 'Vidi' . GeneralUtility::underscoredToUpperCamelCase($dataType) . 'M1';
                     $title = Tca::table($dataType)->getTitle();
                     $modules[$moduleName] = $title;
                 }
             }
         }
         $this->storage[$pid] = $modules;
     }
     return $this->storage[$pid];
 }
コード例 #24
0
 /**
  * Returns a localized record according to a Content object and a language identifier.
  * Notice! This method does not overlay anything but simply returns the raw localized record.
  *
  * @param Content $object
  * @param int $language
  * @return Content
  */
 public function getLocalizedContent(Content $object, $language)
 {
     // We want to cache data per Content object. Retrieve the Object hash.
     $objectHash = spl_object_hash($object);
     // Initialize the storage
     if (empty($this->localizedRecordStorage[$objectHash])) {
         $this->localizedRecordStorage[$objectHash] = array();
     }
     if (empty($this->localizedRecordStorage[$objectHash][$language])) {
         $clause = sprintf('%s = %s AND %s = %s', Tca::table($object)->getLanguageParentField(), $object->getUid(), Tca::table($object)->getLanguageField(), $language);
         $clause .= BackendUtility::deleteClause($object->getDataType());
         $localizedRecord = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('*', $object->getDataType(), $clause);
         if ($localizedRecord) {
             $localizedContent = GeneralUtility::makeInstance('Fab\\Vidi\\Domain\\Model\\Content', $object->getDataType(), $localizedRecord);
             $this->localizedRecordStorage[$objectHash][$language] = $localizedContent;
         } else {
             $this->localizedRecordStorage[$objectHash][$language] = array();
             // We want an array at least, even if empty.
         }
     }
     return $this->localizedRecordStorage[$objectHash][$language];
 }
コード例 #25
0
 /**
  * Process Content with action "update".
  *
  * @param Content $content
  * @throws \Exception
  * @return bool
  */
 public function processUpdate(Content $content)
 {
     $values = array();
     // Check the field to be updated exists
     foreach ($content->toArray() as $fieldName => $value) {
         if (!Tca::table($content->getDataType())->hasField($fieldName)) {
             $message = sprintf('It looks field "%s" does not exist for data type "%s"', $fieldName, $content->getDataType());
             throw new \Exception($message, 1390668497);
         }
         // Flatten value if array given which is required for the DataHandler.
         if (is_array($value)) {
             $value = implode(',', $value);
         }
         $values[$fieldName] = $value;
     }
     $data[$content->getDataType()][$content->getUid()] = $values;
     $dataHandler = $this->getDataHandler();
     $dataHandler->start($data, array());
     $dataHandler->process_datamap();
     $this->errorMessages = $dataHandler->errorLog;
     // Returns TRUE is log does not contain errors.
     return empty($dataHandler->errorLog);
 }
コード例 #26
0
 /**
  * Returns whether the column is visible.
  *
  * @param string $name the column Name
  * @return bool
  */
 public function render($name)
 {
     return Tca::grid()->isVisible($name);
 }
コード例 #27
0
 /**
  * Retrieve Content objects from the Clipboard then "move" them according to the target.
  *
  * @param string $target
  * @return string
  */
 public function moveClipboardAction($target)
 {
     // Retrieve matcher object from clipboard.
     $matcher = $this->getClipboardService()->getMatcher();
     // Fetch objects via the Content Service.
     $contentService = $this->getContentService()->findBy($matcher);
     // Compute the label field name of the table.
     $tableTitleField = Tca::table()->getLabelField();
     // Get result object for storing data along the processing.
     $result = $this->getJsonResult();
     $result->setNumberOfObjects($contentService->getNumberOfObjects());
     foreach ($contentService->getObjects() as $object) {
         // Store the first object, so that the "action" message can be more explicit when deleting only one record.
         if ($contentService->getNumberOfObjects() === 1) {
             $tableTitleValue = $object[$tableTitleField];
             $processedObjectData = array('uid' => $object->getUid(), 'name' => $tableTitleValue);
             $result->setProcessedObject($processedObjectData);
         }
         // Work out the object.
         ContentRepositoryFactory::getInstance()->move($object, $target);
         // Get the possible error messages and store them.
         $errorMessages = ContentRepositoryFactory::getInstance()->getErrorMessages();
         $result->addErrorMessages($errorMessages);
     }
     // Flush Clipboard if told so.
     if (GeneralUtility::_GP('flushClipboard')) {
         $this->getClipboardService()->flush();
     }
     // Set the result and render the JSON view.
     $this->getJsonView()->setResult($result);
     return $this->getJsonView()->render();
 }
コード例 #28
0
ファイル: PidCheck.php プロジェクト: BergischMedia/vidi
 /**
  * Check if pid is 0 and given table is allowed on root level.
  *
  * @return void
  */
 protected function validateRootLevel()
 {
     if ($this->configuredPid > 0) {
         return;
     }
     $isRootLevel = (bool) Tca::table()->get('rootLevel');
     if (!$isRootLevel) {
         $this->errors[] = sprintf('You are not allowed to use page id "0" unless you set $GLOBALS[\'TCA\'][\'%1$s\'][\'ctrl\'][\'rootLevel\'] = 1;', $this->dataType);
     }
 }
コード例 #29
0
 /**
  * Tell whether the operator should be equals instead of like for a search, e.g. if the value is numerical.
  *
  * @param string $fieldName
  * @param string $dataType
  * @param string $value
  * @return bool
  */
 protected function isOperatorEquals($fieldName, $dataType, $value)
 {
     return Tca::table($dataType)->field($fieldName)->hasRelation() && MathUtility::canBeInterpretedAsInteger($value) || Tca::table($dataType)->field($fieldName)->isNumerical();
 }
コード例 #30
0
 /**
  * @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);
 }