public function persistTableQueries($entity, Entity $metadata = null, Reader $reader = null, $local_id = null)
{
/** @var $metadata Entity */
list($metadata, $reader, $local_id) = $this->buildPrerequisites($entity, $metadata, $reader, $local_id);
foreach ($metadata->getSortables() as $sortable) {
$key = $this->getKeyScheme()->getTableSortKey($metadata->getTableName(), $sortable->getName());
// Test conditions
$pass = true;
foreach ($sortable->getConditions() as $condition) {
if ($condition->getColumn()) {
if (!$condition->test($reader->getPropertyValue($condition->getColumn()))) {
$pass = false;
break;
}
} elseif ($condition->getMethod()) {
if (!$condition->test($reader->getMethodValue($condition->getMethod()))) {
$pass = false;
break;
}
}
}
if ($pass) {
// Conditions met, add the index
$this->getDriver()->addSortedIndex($key, $reader->getPropertyValue($sortable->getColumn()), $local_id);
} else {
// Conditions failed, remove the index
$this->getDriver()->removeSortedIndex($key, $local_id);
}
}
return $this;
}