您可以做的是提供一個新的模型和存儲庫,您可以在其中編寫查詢。例如。如果您的新模型包含將被映射的屬性num
。我不確定TCA
這個案件的需要。但請確保您提供uid
作爲屬性,並且它是唯一的。
型號:
<?php
namespace Vendor\ExtKey\Domain\Model;
/**
* @author Daniel Siepmann <[email protected]>
*/
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 <[email protected]>
*/
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;
';
}
}
您查詢將返回不同的結果。 –
你是什麼意思? – sinini
我的意思是你已經擁有'表中的所有不同類型的$值,並且有多少存在查詢。 –