您可以做的是提供一个新的模型和存储库,您可以在其中编写查询。例如,如果您的新模型包含num
将被映射的属性。
我不确定是否需要TCA
这种情况。但请确保您uid
作为财产提供并且它是独一无二的。
模型:
<?php
namespace Vendor\ExtKey\Domain\Model;
/**
* @author Daniel Siepmann <d.siepmann@web-vision.de>
*/
class FilterOption extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
{
/**
* @var string
*/
protected $title;
/**
* @var float
*/
protected $value;
/**
* @var float
*/
protected $min;
/**
* @var float
*/
protected $max;
/**
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* @return float
*/
public function getValue()
{
return $this->value;
}
/**
* @return float
*/
public function getMin()
{
return $this->min;
}
/**
* @return float
*/
public function getMax()
{
return $this->max;
}
}
存储库:
<?php
namespace Vendor\ExtKey\Domain\Repository;
/**
*
* @author Daniel Siepmann <d.siepmann@web-vision.de>
*/
class FilterOptionRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
{
/**
* Will find all options to filter for for a specific property.
*
* @param string $property The name of the property.
*
* @return NULL|[]
*/
public function findFilterOptionForProperty($property)
{
if (in_array($property, [ 'house_types' ])) {
return $this->findMmOptions($property);
}
return $this->findNumericOptions($property);
}
/**
* Will find all options to filter for for a specific property.
*
* @param string $property The name of the property.
*
* @return NULL|[]
*/
protected function findNumericOptions($property)
{
return $this->createQuery()
->statement($this->getNumericStatement($property))
->execute();
}
/**
* Get SQL statement to fetch filter options from persistence,
* for the given property if it's values are numeric.
*
* @param string $property The property to fetch.
*
* @return string The statement
*/
protected function getNumericStatement($property)
{
// We have to fake UID, otherwise extbase will reuse previous
// objects with same uid.
$uidBase = rand(ord($property), getrandmax());
// Return statement for single column.
return '
SELECT "' . $property . '" AS title, ' . $property . ' AS value,
(SELECT min(' . $property . ') FROM tx_realty_objects WHERE ' . $this->getAdditionalWhereClause() . ') AS min,
(SELECT max(' . $property . ') FROM tx_realty_objects WHERE ' . $this->getAdditionalWhereClause() . ') AS max,
@rownum := @rownum + ' . $uidBase . ' AS uid
FROM tx_realty_objects,
(SELECT @rownum:=' . $uidBase . ') x
WHERE ' . $this->getAdditionalWhereClause() . '
GROUP BY ' . $property . '
ORDER BY value;
';
}
}