public function __construct($name, $type, Form $parent, array $options) { /** @var Model $model */ $model = $options['model']; $primary = $options['primary']; $show = $options['show']; $none_selected_item = isset($options['none_selected_item']) ? $options['none_selected_item'] : true; /** Detect I18N */ $locale = Session::get('cms.locale', \Config::get('app.locale', 'en')); $is_i18n = method_exists($model, 'saveI18N'); $query = $is_i18n ? $model::I18N($locale) : $model::query(); /** END **/ if (key_exists('filter', $options) && count($options['filter']) > 0) { foreach ($options['filter'] as $key => $item) { $query->where($key, $item['condition'], $item['value']); } } /** Parse to key-name format {$table}.{$field} */ $keyName = strpos($options['primary'], '.') ? $options['primary'] : (new $model())->getTable() . "." . $options['primary']; $data = $query->select($keyName, $show)->get()->toArray(); /** Fill model data to choice array */ $options['choices'] = []; if ($none_selected_item) { $options['choices'] = [null => '']; } $options['choices'] = $options['choices'] + array_pluck($data, $show, $primary); /** END */ $options['selected'] = array_get($options, 'value', null); parent::__construct($name, $type, $parent, $options); }
/** * TwoSelectBox constructor. * * @param $name * @param $type * @param Form $parent * @param array $options */ public function __construct($name, $type, Form $parent, array $options) { $options['attr']['extend'] = true; $options['attr']['multiple'] = true; $options['btnSelect'] = array_merge(['class' => 'btn', 'id' => 'btnSelect'], isset($options['btnSelect']) ? $options['btnSelect'] : []); $options['btnUnSelect'] = array_merge(['class' => 'btn', 'id' => 'btnUnSelect'], isset($options['btnUnSelect']) ? $options['btnUnSelect'] : []); $options['container_id'] = Str::studly(Str::slug($name, '_')) . "TwoSelectBoxContainer"; /** Load data from model */ /** @var Model $model */ $model = $options['model']; $primary = $options['primary']; $show = $options['show']; /** Detect I18N */ $locale = \Config::get('app.locale'); $is_i18n = method_exists($model, 'saveI18N'); $query = $is_i18n ? $model::I18N($locale) : $model::query(); /** END **/ if (key_exists('filter', $options) && count($options['filter']) > 0) { foreach ($options['filter'] as $key => $item) { $query->where($key, $item['condition'], $item['value']); } } /** Parse to key-name format {$table}.{$field} */ $keyName = strpos($options['primary'], '.') ? $options['primary'] : (new $model())->getTable() . "." . $options['primary']; $data = $query->select($keyName, $show)->get()->toArray(); /** Fill model data to choice array */ $options['choices'] = array_pluck($data, $show, $primary); /** END */ $options['selected'] = array_get($options, 'value', []); /** END */ $options['selected'] = (array) (isset($options['selected']) ? $options['selected'] : []); parent::__construct($name, $type, $parent, $options); }
/** * TwoSelectBox constructor. * * @param $name * @param $type * @param Form $parent * @param array $options */ public function __construct($name, $type, Form $parent, array $options) { $options['attr']['extend'] = false; $options['attr']['multiple'] = false; $options['selected'] = (array) (isset($options['selected']) ? $options['selected'] : []); $options['btnSelect'] = array_merge(['class' => 'btn', 'id' => 'btnSelect'], isset($options['btnSelect']) ? $options['btnSelect'] : []); $options['btnUnSelect'] = array_merge(['class' => 'btn', 'id' => 'btnUnSelect'], isset($options['btnUnSelect']) ? $options['btnUnSelect'] : []); $options['container_id'] = Str::studly(Str::slug($name, '_')) . "TwoSelectBoxContainer"; parent::__construct($name, $type, $parent, $options); }
public function __construct($name, $type, Form $parent, array $options) { $options['selected'] = array_get($options, 'value', null); if (key_exists('choices', $options) && !empty($options['choices'])) { $locale = Session::get('cms.locale', Config::get('app.locale', 'en')); foreach ($options['choices'] as $key => $optionName) { $options['choices'][$key] = trans($optionName, [], "messages", $locale); } } parent::__construct($name, $type, $parent, $options); }