Ejemplo n.º 1
0
 /**
  * Search for books
  *
  * @param string $terms
  * @param array $advancedQueries @see self::$advancedQueryOptions for more information
  * @param array $options @see self::$optionSettings for more information
  *
  * @return \App\Models\Book[]
  */
 public function search($terms, array $advancedQueries = [], $options = [])
 {
     if (!$this->areAdvancedQueriesValid($advancedQueries)) {
         return false;
     }
     $this->setDefaultOptions($options);
     $query = $this->book->order($options['orderBy'], $options['order'])->page($options['page'], $options['limit']);
     if ($terms) {
         $query->searchFor($terms);
     }
     foreach ($advancedQueries as $key => $value) {
         $method = $this->advanceQuerySettings[$key]['method'];
         if ($key === 'range') {
             list($from, $to) = $value;
             $this->book->{$method}($from, $to);
         } else {
             $this->book->{$method}($value);
         }
     }
     return $query->get();
 }
 private function queryAdvanced(array $queries = [])
 {
     $this->book->order($this->defaultOptions['orderBy'], $this->defaultOptions['order'])->page($this->defaultOptions['page'], $this->defaultOptions['limit']);
     $queriesList = ['q' => 'searchFor', 'title' => 'searchTitle', 'author' => 'searchAuthor', 'isbn' => 'searchIsbn', 'date' => 'searchDate', 'range' => 'searchDateRange', 'rate' => 'searchRate'];
     foreach ($queries as $key => $value) {
         if ($key === 'range') {
             list($from, $to) = $value;
             $this->book->{$queriesList[$key]}($from, $to);
         } else {
             $this->book->{$queriesList[$key]}($value);
         }
     }
     return $this->book->get()->toArray();
 }