Esempio n. 1
0
 /**
  * {@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;
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function getCurrent()
 {
     if ($this->current === null) {
         $page = $this->request->getPage();
         $total = $this->getTotal();
         $this->current = $page > $total ? $total : $page;
     }
     return $this->current;
 }
Esempio n. 3
0
 /**
  * {@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;
 }
Esempio n. 4
0
 /**
  * Get search
  * 
  * @return string | null
  */
 public function getSearch()
 {
     return $this->request->getSearchFor($this->getName());
 }
Esempio n. 5
0
 /**
  * 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);
 }
Esempio n. 7
0
 /**
  * Get global search string if defined
  * 
  * @return string | null
  */
 public function getGlobalSearch()
 {
     return $this->request->getGlobalSearch();
 }