/** * {@inheritdoc} */ public function getData(RequestInterface $request) { $data = new \SplDoublyLinkedList(); $source = array_slice($this->source, $request->getLimit() * ($request->getPage() - 1), $request->getLimit()); foreach ($source as $rowData) { $row = new Row(); foreach ($rowData as $cellData) { $row->appendCell(new Cell($cellData)); } $data[] = $row; } return $data; }
/** * {@inheritdoc} */ public function getCurrent() { if ($this->current === null) { $page = $this->request->getPage(); $total = $this->getTotal(); $this->current = $page > $total ? $total : $page; } return $this->current; }
/** * {@inheritdoc} */ public function getSearch() { if ($this->search === null) { $this->search = []; foreach ($this->request->getSearch() as $name => $string) { $searchBy = $this->schema->getField($name)->getSearchBy(); if (empty($searchBy)) { $this->search[$name] = $string; continue; } $this->search[] = array_fill_keys($searchBy, $string); } } return $this->search; }
/** * Get search * * @return string | null */ public function getSearch() { return $this->request->getSearchFor($this->getName()); }
/** * Validate search * * @param RequestInterface $request * @param array $errors */ protected function validateSearch(RequestInterface $request, array &$errors) { foreach ($request->getSearch() as $field => $value) { if (!$this->schema->hasField($field)) { $errors[] = sprintf('Search cannot be applied to non-existent field "%s"', $field); continue; } if (!$this->schema->getField($field)->isSearchable()) { $errors[] = sprintf('Field "%s" is not searchable', $field); } if (empty($value)) { $errors[] = sprintf('Search string of field "%s" is empty', $value, $field); } } }
/** * Process global search * * @param Criteria $criteria * @param RequestInterface $request */ protected function processGlobalSearch(Criteria $criteria, RequestInterface $request) { $query = $request->getGlobalSearch(); if ($query === null) { return; } $condition = call_user_func_array([Criteria::expr(), 'orX'], array_map(function ($name) use($query) { return Criteria::expr()->contains($name, $query); }, $this->schemaProvider->getSchema()->getGloballySearchableNames())); $criteria->andWhere($condition); }
/** * Get global search string if defined * * @return string | null */ public function getGlobalSearch() { return $this->request->getGlobalSearch(); }