Example #1
0
File: Filter.php Project: skvn/crud
 public function addFilter($name, $field = null)
 {
     $col = $this->model->getField($name);
     if (!$col) {
         return;
     }
     if ($col['type'] == 'date') {
         $col['type'] = 'date_range';
     }
     $control = Form::getControlByType($col['type']);
     if (!$control instanceof FormControlFilterable) {
         return;
     }
     $col['required'] = false;
     $col['name'] = $name;
     $col['field'] = $field ?? $name;
     if ($col['type'] == 'select') {
         $col['multiple'] = true;
     }
     if (isset($this->defaults[$name])) {
         $col['default'] = is_array($this->defaults[$name]) ? implode(',', $this->defaults[$name]) : $this->defaults[$name];
     }
     $filter = Form::createControl($this->model, $col);
     if (!empty($field) && $field != $name) {
         $filter->setFilterColumnName($field);
     }
     $this->filters[] = $filter;
     return $this;
 }
Example #2
0
 public function getColumDbTypeByEditType($type)
 {
     $control = Form::getControlByType($type);
     return $control instanceof WizardableField ? $control->wizardDbType() : 'unknown';
 }