예제 #1
0
 /**
  * Transform collection data. Used for searches.
  *
  * @param ColumnConfiguration[] $columnConfiguration
  * @param $searchFunc
  */
 private function transformCollectionData($columnConfiguration, $searchFunc)
 {
     $this->collection->transform(function ($data) use($columnConfiguration, $searchFunc) {
         $entry = [];
         // for each column call the callback
         foreach ($columnConfiguration as $i => $col) {
             $func = $col->getCallable();
             $entry[$col->getName()] = $func($data);
             if ($this->queryConfiguration->hasSearchColumn($col->getName())) {
                 // column search exists, so check if the column matches the search
                 if (!$this->columnSearchFunction[$col->getName()]($entry, $this->queryConfiguration->searchColumns()[$col->getName()])) {
                     // did not match, so return an empty array, the row will be removed later
                     return [];
                 }
             }
         }
         // also do search right away
         if ($this->queryConfiguration->isGlobalSearch()) {
             if (!$searchFunc($entry, $this->queryConfiguration->searchValue(), $this->columnConfiguration)) {
                 $entry = [];
             }
         }
         return $entry;
     });
 }
예제 #2
0
 /**
  * When a global query is being performed (ie, a query against a single column)
  *
  * @return QueryBuilder
  * @throws DatatableException
  */
 private function compileColumnQuery()
 {
     $searchColumns = $this->queryConfiguration->searchColumns();
     foreach ($searchColumns as $i => $col) {
         $column = $this->getColumnFromName($col->columnName());
         if (!isset($column)) {
             continue;
         }
         $this->createQueryForColumn($column, $col->searchValue());
     }
 }