Example #1
0
 /**
  * Execute strainer
  *
  * @param \FrenchFrogs\Table\Table\Table $table
  * @param array ...$params
  * @return $this
  * @throws \Exception
  */
 public function call(\FrenchFrogs\Table\Table\Table $table, ...$params)
 {
     if ($this->hasCallable()) {
         call_user_func_array($this->callable, $params);
     } else {
         // verify that source is a query
         if (!$table->isSourceQueryBuilder()) {
             throw new \Exception('Table source is not an instance of query builder');
         }
         // recuperation des valeurs
         $params = explode('#', $params[0]);
         $e = $this->getElement();
         // from
         if (!empty($params[0])) {
             $from = $e->setValue($params[0])->getFilteredValue();
             $table->getSource()->where($this->getField(), '>=', $from);
         }
         // to
         if (!empty($params[1])) {
             $to = $e->setValue($params[1])->getFilteredValue();
             $to = \Carbon\Carbon::createFromFormat($e->getFormatStore(), $to)->addDay(1)->format($e->getFormatStore());
             $table->getSource()->where($this->getField(), '<', $to);
         }
     }
     return $this;
 }
Example #2
0
 /**
  * Execute strainer
  *
  * @param \FrenchFrogs\Table\Table\Table $table
  * @param array ...$params
  * @return $this
  * @throws \Exception
  */
 public function call(\FrenchFrogs\Table\Table\Table $table, ...$params)
 {
     if ($this->hasCallable()) {
         call_user_func_array($this->callable, $params);
     } else {
         // verify that source is a query
         if (!$table->isSourceQueryBuilder()) {
             throw new \Exception('Table source is not an instance of query builder');
         }
         $table->getSource()->where($this->getField(), 'LIKE', '%' . $params[0] . '%');
     }
     return $this;
 }