/** * Execute a query on the collection after injection of the optional parameters * extracted from the View Uri adapter environment * @param AbstractAdapter $uriAdapter */ public function query(AbstractAdapter $uriAdapter) { $offsetIdentifier = $uriAdapter->getIdentifier('offset'); $sortIdentifier = $uriAdapter->getIdentifier('sort'); $searchIdentifier = $uriAdapter->getIdentifier('search'); // try and restore cached search terms for the current uri but protect collection spawned from properties if (!$this->_collection->getParent() && $this->getParameter('uricache') != false) { $uriAdapter->restoreSearchTerms(); } $env = $uriAdapter->getEnv(); // set query parameters from context if (isset($env[$searchIdentifier]) && is_array($env[$searchIdentifier])) { foreach ($env[$searchIdentifier] as $field => $value) { $field = str_replace("-", ".", $field); if (!is_null($value) && $value != '' && $value != Property::EMPTY_VALUE) { $property = $this->_collection->getDataObject()->getRecursiveProperty($field); if ($property instanceof Property\MetaProperty) { $this->_collection->having($property->getParameter('property'))->{$property->getParameter('searchmode')}($value); } else { if ($property instanceof Property\ObjectProperty) { $this->_collection->having($field)->equals($value); } else { if ($property instanceof Property\DateProperty) { if (is_array($value)) { if (isset($value['from']) && !empty($value['from'])) { $this->_collection->having($field)->greaterOrEquals($value['from']); } if (isset($value['to']) && !empty($value['to'])) { $this->_collection->having($field)->lowerOrEquals($value['to']); } } else { $this->_collection->having($field)->equals($value); } } else { if ($property instanceof Property\IntegerProperty) { $this->_collection->resetConditions($field); $this->_collection->having($field)->equals($value); } else { if ($property instanceof Property\AbstractProperty) { $this->_collection->resetConditions($field); $searchmode = $property->getParameter('searchmode') ? $property->getParameter('searchmode') : 'equals'; $this->_collection->having($field)->{$searchmode}($value); } } } } } $uriAdapter->setArgument($searchIdentifier . '[' . $field . ']', $value); } } } // set query sorting from context if (isset($env[$sortIdentifier]) && is_array($env[$sortIdentifier]) && count($env[$sortIdentifier]) > 0) { $this->_collection->resetSortings(); // reset hard-coded sortings foreach ($env[$sortIdentifier] as $field => $value) { if (($property = $this->_collection->getDataObject()->getRecursiveProperty($field)) !== false) { $this->_collection->setSorting($property, $value); } } } // define offset parameter value from context if (isset($env[$offsetIdentifier])) { $this->setParameter('offset', (int) $env[$offsetIdentifier]); $this->_collection->setBoundaryOffset($env[$offsetIdentifier]); } if ($this->_collection->getParameter('populated') !== true) { // $this->_collection->debug(); die; $this->_collection->find(ObjectModel::DATA); } // bind aliases there because collection coming from a property is already populated $this->bindAliases(); if ($this->getParameter('max') == 0) { $this->setParameter('max', $this->_collection->getMax()); } }