Project

General

Profile

Feature #64197 ยป foreign_default_sortby.patch

JAKOTA Design Group GmbH, 2023-02-28 17:54

View differences:

Classes/Persistence/Generic/Mapper/ColumnMap.php
*/
private $childTableName;
/**
* todo: Check if this property should support null. If not, set default value.
* The name of the field the results from the child's table are sorted by default
*
* @see https://docs.typo3.org/m/typo3/reference-tca/main/en-us/ColumnsConfig/Type/Inline/Properties/ForeignDefaultSortby.html
* @var string|null
*/
private $childDefaultSortByFieldName;
/**
* todo: Check if this property should support null. If not, set default value.
* The name of the field the results from the child's table are sorted by
......
return $this->childTableName;
}
/**
* @param string|null $childDefaultSortByFieldName
*/
public function setChildDefaultSortByFieldName(?string $childDefaultSortByFieldName): void
{
$this->childDefaultSortByFieldName = $childDefaultSortByFieldName;
}
/**
* @return string|null
*/
public function getChildDefaultSortByFieldName(): ?string
{
return $this->childDefaultSortByFieldName;
}
/**
* @param string|null $childSortByFieldName
*/
Classes/Persistence/Generic/Mapper/DataMapFactory.php
}
// todo: don't update column map if value(s) isn't/aren't set.
$columnMap->setChildSortByFieldName($columnConfiguration['foreign_sortby'] ?? null);
$columnMap->setChildDefaultSortByFieldName($columnConfiguration['foreign_default_sortby'] ?? null);
$columnMap->setParentKeyFieldName($columnConfiguration['foreign_field'] ?? null);
$columnMap->setParentTableFieldName($columnConfiguration['foreign_table_field'] ?? null);
if (isset($columnConfiguration['foreign_match_fields']) && is_array($columnConfiguration['foreign_match_fields'])) {
......
}
// todo: don't update column map if value(s) isn't/aren't set.
$columnMap->setChildSortByFieldName($columnConfiguration['foreign_sortby'] ?? null);
$columnMap->setChildDefaultSortByFieldName($columnConfiguration['foreign_default_sortby'] ?? null);
$columnMap->setParentKeyFieldName($columnConfiguration['foreign_field'] ?? null);
$columnMap->setParentTableFieldName($columnConfiguration['foreign_table_field'] ?? null);
if (isset($columnConfiguration['foreign_match_fields']) && is_array($columnConfiguration['foreign_match_fields'])) {
Classes/Persistence/Generic/Mapper/DataMapper.php
$query->getQuerySettings()->setLanguageAspect($languageAspect);
if ($columnMap->getTypeOfRelation() === ColumnMap::RELATION_HAS_MANY) {
if ($columnMap->getChildSortByFieldName() !== null) {
$query->setOrderings([$columnMap->getChildSortByFieldName() => QueryInterface::ORDER_ASCENDING]);
if ($columnMap->getChildSortByFieldName() !== null || $columnMap->getChildDefaultSortByFieldName() !== null) {
$query->setOrderings($this->getOrderingsForColumnMap($columnMap));
}
} elseif ($columnMap->getTypeOfRelation() === ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY) {
$query->setSource($this->getSource($parentObject, $propertyName));
if ($columnMap->getChildSortByFieldName() !== null) {
$query->setOrderings([$columnMap->getChildSortByFieldName() => QueryInterface::ORDER_ASCENDING]);
if ($columnMap->getChildSortByFieldName() !== null || $columnMap->getChildDefaultSortByFieldName() !== null) {
$query->setOrderings($this->getOrderingsForColumnMap($columnMap));
}
}
$query->matching($this->getConstraint($query, $parentObject, $propertyName, $fieldValue, (array)$columnMap->getRelationTableMatchFields()));
return $query;
}
/**
* Get orderings array for extbase query by columnMap
*
* @param ColumnMap $columnMap
* @return array
*/
protected function getOrderingsForColumnMap(ColumnMap $columnMap): array
{
$configuration = GeneralUtility::trimExplode(' ', $columnMap->getChildSortByFieldName() ?? $columnMap->getChildDefaultSortByFieldName());
$fields = GeneralUtility::trimExplode(',', $configuration[0]);
// default direction is ascending
$direction = QueryInterface::ORDER_ASCENDING;
$directionValues = [QueryInterface::ORDER_ASCENDING, QueryInterface::ORDER_DESCENDING];
if (array_key_exists(1, $configuration) && in_array(strtoupper($configuration[1]), $directionValues, true)) {
$direction = strtoupper($configuration[1]);
}
$orderings = [];
foreach ($fields as $field) {
$orderings[$field] = $direction;
}
return $orderings;
}
/**
* Builds and returns the constraint for multi value properties.
*
    (1-1/1)