/** * @param \Elastica_Index $index * @param string $type * @param Naturwerk\Find\Parameters $parameter */ public function __construct($index, $type, Parameters $parameters) { $this->index = $index; $this->type = $type; $this->parameters = $parameters; // resort and activate columns if (count($parameters->getColumns()) > 0) { $columns = array(); foreach ($this->columns as $i => $column) { $index = array_search($column->getName(), $parameters->getColumns()); if ($index === false) { $column->setActive(false); $columns[999 + $i] = $column; } else { $column->setActive(true); $columns[$index] = $column; } } ksort($columns); $this->columns = $columns; } // set default sort $this->sort = $this->parameters->getSort(); $active = array(); foreach ($this->columns as $column) { if ($column->isActive()) { $active[] = $column->getName(); } } if (count($this->sort) == 0 || !in_array(key($this->sort), $active)) { $column = reset($this->columns); $this->sort = array($column->getName() => 'asc'); } }