/** * 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); } }
/** * List action for this controller. * * @return void */ public function indexAction() { $dataType = $this->getModuleLoader()->getDataType(); $selections = $this->selectionRepository->findByDataTypeForCurrentBackendUser($dataType); $this->view->assign('selections', $selections); $columns = Tca::grid()->getFields(); $this->view->assign('columns', $columns); $this->view->assign('numberOfColumns', count($columns)); }
/** * 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); } } }
/** * 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); }
/** * @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; }
/** * 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; }
/** * 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); }
/** * 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; }
/** * 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); }
/** * 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)); } } } }
/** * Check relation for table. * * @param $tableName * @return array */ public function checkRelationForTable($tableName) { $relations = array(); $table = Tca::table($tableName); $missingOppositionRelationMessage = <<<EOF WARNING! Could not define relation precisely. This is not necessarily a problem if the opposite relation is not required in a Grid. But consider adding the opposite TCA configuration if so. EOF; foreach (Tca::grid($tableName)->getFields() as $fieldName => $configuration) { if ($table->hasField($fieldName)) { if ($table->field($fieldName)->hasMany()) { if ($table->field($fieldName)->hasRelationWithCommaSeparatedValues()) { $_relations = $this->checkRelationOf($tableName, $fieldName, 'comma separated values'); $relations = array_merge($relations, $_relations); } elseif ($table->field($fieldName)->hasRelationManyToMany()) { $_relations = $this->checkRelationManyToMany($tableName, $fieldName); $relations = array_merge($relations, $_relations); } elseif ($table->field($fieldName)->hasRelationOneToMany()) { $_relations = $this->checkRelationOf($tableName, $fieldName, 'one-to-many'); $relations = array_merge($relations, $_relations); } else { $relations[] = sprintf('* field: "%s", relation: ?-to-many%s', $fieldName, $missingOppositionRelationMessage); } $relations[] = ''; } elseif ($table->field($fieldName)->hasOne()) { if ($table->field($fieldName)->hasRelationOneToOne()) { $relations[] = sprintf('* one-to-one "%s"', $fieldName); } elseif ($table->field($fieldName)->hasRelationManyToOne()) { $_relations = $this->checkRelationOf($tableName, $fieldName, 'many-to-one'); $relations = array_merge($relations, $_relations); } else { $relations[] = sprintf('* field: "%s", relation: ?-to-one%s', $fieldName, $missingOppositionRelationMessage); } $relations[] = ''; } } } return $relations; }
/** * Remove fields according to Grid configuration. * * @param $fields * @return array */ protected function filterForConfiguration($fields) { $excludedFields = Tca::grid($this->dataType)->getExcludedFields(); foreach ($fields as $key => $field) { if (in_array($field, $excludedFields)) { unset($fields[$key]); } } return $fields; }
/** * Apply criteria specific to jQuery plugin DataTable. * * @param array $queryParts * @param Matcher $matcher * @param string $dataType * @return Matcher $matcher */ protected function parseQuery(array $queryParts, Matcher $matcher, $dataType) { foreach ($queryParts as $queryPart) { $fieldNameAndPath = key($queryPart); $resolvedDataType = $this->getFieldPathResolver()->getDataType($fieldNameAndPath, $dataType); $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $dataType); // Retrieve the value. $value = current($queryPart); if (Tca::grid($resolvedDataType)->hasFacet($fieldName) && Tca::grid($resolvedDataType)->facet($fieldName)->canModifyMatcher()) { $matcher = Tca::grid($resolvedDataType)->facet($fieldName)->modifyMatcher($matcher, $value); } elseif (Tca::table($resolvedDataType)->hasField($fieldName)) { // Check whether the field exists and set it as "equal" or "like". if ($this->isOperatorEquals($fieldNameAndPath, $dataType, $value)) { $matcher->equals($fieldNameAndPath, $value); } else { $matcher->like($fieldNameAndPath, $value); } } elseif ($fieldNameAndPath === 'text') { // Special case if field is "text" which is a pseudo field in this case. // Set the search term which means Vidi will // search in various fields with operator "like". The fields come from key "searchFields" in the TCA. $matcher->setSearchTerm($value); } } return $matcher; }
/** * Returns whether the column is visible. * * @param string $name the column Name * @return bool */ public function render($name) { return Tca::grid()->isVisible($name); }
/** * Apply criteria specific to jQuery plugin DataTable. * * @param Matcher $matcher * @param string $dataType * @return Matcher $matcher */ protected function applyCriteriaFromDataTables(Matcher $matcher, $dataType) { // Special case for Grid in the BE using jQuery DataTables plugin. // Retrieve a possible search term from GP. $query = GeneralUtility::_GP('search'); if (is_array($query)) { if (!empty($query['value'])) { $query = $query['value']; } else { $query = ''; } } if (strlen($query) > 0) { // Parse the json query coming from the Visual Search. $query = rawurldecode($query); $queryParts = json_decode($query, TRUE); if (is_array($queryParts)) { foreach ($queryParts as $term) { $fieldNameAndPath = key($term); $resolvedDataType = $this->getFieldPathResolver()->getDataType($fieldNameAndPath, $dataType); $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $dataType); // Retrieve the value. $value = current($term); if (Tca::grid($resolvedDataType)->hasFacet($fieldName) && Tca::grid($resolvedDataType)->facet($fieldName)->canModifyMatcher()) { $matcher = Tca::grid($resolvedDataType)->facet($fieldName)->modifyMatcher($matcher, $value); } elseif (Tca::table($resolvedDataType)->hasField($fieldName)) { // Check whether the field exists and set it as "equal" or "like". if ($this->isOperatorEquals($fieldNameAndPath, $dataType, $value)) { $matcher->equals($fieldNameAndPath, $value); } else { $matcher->like($fieldNameAndPath, $value); } } elseif ($fieldNameAndPath === 'text') { // Special case if field is "text" which is a pseudo field in this case. // Set the search term which means Vidi will // search in various fields with operator "like". The fields come from key "searchFields" in the TCA. $matcher->setSearchTerm($value); } } } else { $matcher->setSearchTerm($query); } } return $matcher; }
/** * Returns whether the column is excluded from the Grid. * * @param string $name the column Name * @return bool */ public function render($name) { $excludedFields = Tca::grid()->getExcludedFields(); return !in_array($name, $excludedFields); }
/** * Returns whether the column can be hidden or not. * * @param string $name the column Name * @return boolean */ public function render($name) { return Tca::grid()->canBeHidden($name); }
/** * Check relations of current data type in the Grid. * * @return boolean */ protected function isTcaValid() { $dataType = $this->getModuleLoader()->getDataType(); $table = Tca::table($dataType); foreach (Tca::grid($dataType)->getFields() as $fieldName => $configuration) { if ($table->hasField($fieldName) && $table->field($fieldName)->hasMany()) { if ($table->field($fieldName)->hasRelationManyToMany()) { $foreignTable = $table->field($fieldName)->getForeignTable(); $manyToManyTable = $table->field($fieldName)->getManyToManyTable(); $foreignField = $table->field($fieldName)->getForeignField(); if (!$foreignField) { $this->invalidFields[] = $fieldName; } elseif (!$foreignTable) { $this->invalidFields[] = $fieldName; } elseif (!$manyToManyTable) { $this->invalidFields[] = $fieldName; } } } } return empty($this->invalidFields); }
/** * Returns a column title. * * @return string */ public function render() { $columnName = $this->templateVariableContainer->get('columnName'); return Tca::grid()->getLabel($columnName); }
/** * 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); } } } }
/** * Return whether the field given by the context is editable. * * @return boolean */ protected function isEditable() { $fieldNameAndPath = $this->getFieldNameAndPath(); $dataType = $this->getDataType(); $fieldName = $this->getFieldName(); return Tca::grid()->isEditable($fieldNameAndPath) && Tca::table($dataType)->hasField($fieldName) && Tca::table($dataType)->field($fieldName)->hasNoRelation(); // relation are editable through Renderers only. }
/** * Returns a possible column header. * * @param string $name the column Name * @return boolean */ public function render($name) { return Tca::grid()->getHeader($name); }