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; }
public function __construct(LaravelApplication $app, Guard $auth) { $this->app = $app; $this->auth = $auth; $this->helper = $this->app->make('skvn.crud'); $this->cmsHelper = $this->app->make('skvn.cms'); $this->request = $this->app['request']; $this->view = $this->app['view']; $this->view->share('cmsHelper', $this->cmsHelper); $this->view->share('config', $this->app['config']->get('crud_common')); $this->view->share('avail_controls', Form::getAvailControls()); }
public function getControls(CrudModel $model = null, $forView = true) { $controls = []; if (is_null($model)) { $model = CrudModel::createInstance($this->config['model']); } foreach ($this->config['fields'] as $field) { $control = Form::createControl($model, $model->getField($field)); if ($forView) { $id = $model->exists ? $model->getKey() : -1; $control->setField($this->name . '[' . $id . '][' . $control->config['name'] . ']'); $control->config['required'] = false; } $controls[] = $control; } return $controls; }
public function getColumDbTypeByEditType($type) { $control = Form::getControlByType($type); return $control instanceof WizardableField ? $control->wizardDbType() : 'unknown'; }
public function formatted($col, $args = []) { $rel = $this->crudRelations->resolveReference($col); if ($rel !== false) { try { $relObj = $this->{$rel['rel']}; if (!is_object($relObj)) { return ''; } $value = $relObj->{$rel['attr']}; } catch (\Exception $e) { return '(not found)' . $e->getMessage() . ':' . $e->getFile() . ':' . $e->getLine(); } } elseif ($this->__isset($col)) { $field = $this->getField($col); if (!empty($field['type'])) { $control = Form::createControl($this, $field); $value = $control->getOutputValue(); } else { $value = $this->{$col}; } } else { return; } if (!empty($args['formatter'])) { $formatter = 'crudFormatValue' . Str::camel($args['formatter']); if (method_exists($this, $formatter)) { $value = $this->{$formatter}($value, $args); } } return $value; }
protected function registerControls() { foreach ($this->app['config']->get('crud_common')['form_controls'] as $class) { Form\Form::registerControl($class); } }
/** * Get an array of available filter field types. * * @return array */ public function getAvailableFilterTypes() { $types = []; foreach (Form::getAvailControls() as $control) { if ($control instanceof WizardableField) { if ($control instanceof FormControlFilterable) { $types[$control->controlType()] = $control->wizardCaption(); } } } return $types; }