public function getOptionsAttribute() { $return = []; if ($this->type == 'select' || $this->type == 'radio' || $this->type == 'checkbox') { foreach ($this->field_options_active as $item) { $return[$item->name] = $item->label; } } else { if ($this->type == 'relation' || $this->type == 'field') { if ($subnode = \Solunes\Master\App\Node::where('name', str_replace('_', '-', $this->value))->first()) { $submodel = \FuncNode::node_check_model($subnode); if ($this->type == 'relation') { if ($this->value == 'section') { $return = $return + $submodel->where('node_id', $this->parent_id)->get()->lists('name', 'id')->toArray(); } else { $return = $return + $submodel->get()->lists('name', 'id')->toArray(); } } else { $return = $return + $submodel->lists('name', 'id')->toArray(); } } } } return $return; }
public function getModelIndicator($action, $id = NULL) { $model = 'indicator'; $array = []; if ($action == 'edit') { $indicator = \Solunes\Master\App\Indicator::find($id); $indicator_model = \FuncNode::node_check_model($indicator->node); $array['node_name'] = $indicator->node->plural; $array['filter_category'] = 'indicator'; $array['filter_node'] = $indicator->node->name; $array['filter_type'] = 'field'; $array['filter_category_id'] = $id; $filled_items = $indicator_model; $array = \AdminList::filter_node($array, $indicator->node, $indicator_model, $filled_items, 'indicator'); $array = \CustomFunc::custom_indicator($indicator->node, $indicator, $array); if (request()->has('search') && isset($array['filters']) && is_array($array['filters'])) { foreach ($array['filters'] as $field_name => $field) { $filter = \Solunes\Master\App\Filter::find($field['id']); $action_value = []; if ($field['subtype'] == 'date') { if (request()->has('f_' . $field_name . '_from')) { $action_value[request()->input('f_' . $field_name . '_from')] = 'is_greater'; } if (request()->has('f_' . $field_name . '_to')) { $action_value[request()->input('f_' . $field_name . '_to')] = 'is_less'; } } else { if ($field['subtype'] == 'string') { if (request()->has('f_' . $field_name)) { $action_value[request()->input('f_' . $field_name)] = request()->input('f_' . $field_name . '_action'); } } else { if (request()->has('f_' . $field_name) && is_array(request()->input('f_' . $field_name))) { foreach (request()->input('f_' . $field_name) as $subfield_key => $subfield_val) { $action_value[$subfield_val] = 'is'; } } else { if (request()->has('f_' . $field_name)) { $action_value[request()->input('f_' . $field_name)] = 'is'; } } } } $filter->action_value = json_encode($action_value); $filter->save(); } \CustomFunc::update_indicator_values($indicator); } $filled_items = $indicator_model; $array = \AdminList::filter_node($array, $indicator->node, $indicator_model, $filled_items, 'indicator'); $array['items'] = $array['items']->get(); } return AdminItem::get_request($model, $action, $id, $this, [], $array); }
/** * Execute the console command. * * @return mixed */ public function handle() { $this->info('0%: Se comenzó a importar el excel.'); $languages = \Solunes\Master\App\Language::get(); \Excel::load(public_path('seed/import.xls'), function ($reader) use($languages) { foreach ($reader->get() as $sheet) { $sheet_model = $sheet->getTitle(); if ($node = \Solunes\Master\App\Node::where('name', $sheet_model)->first()) { $field_array = []; $field_sub_array = []; $sub_field_insert = []; foreach ($languages as $language) { foreach ($node->fields()->whereNotIn('type', ['child', 'subchild', 'field'])->get() as $field) { if ($language->id > 1) { $field_array[$field->name . '_' . $language->code] = $field; } else { $field_array[$field->name] = $field; } } } foreach ($node->fields()->where('type', 'field')->get() as $field) { $field_sub_array[$field->name] = $field; } $sheet->each(function ($row) use($languages, $node, $field_array, $field_sub_array, $sub_field_insert) { $new_item = false; foreach ($row->all() as $column => $input) { if ($column == 'id' && $input) { $model = \FuncNode::node_check_model($node); if (!($item = $model->where('id', $row->id)->first())) { $item = $model; } $new_item = true; } if ($new_item && isset($field_array[$column])) { $field = $field_array[$column]; if ($column == $field->name) { $language_code = 'es'; } else { $language_code = str_replace($field->name . '_', '', $column); } if ($field->type == 'select' || $field->type == 'radio') { if ($subanswer = $field->field_options()->whereTranslation('label', $input)->first()) { $input = $subanswer->name; } else { $input = NULL; } } else { if ($field->type == 'checkbox') { $subinput = []; foreach (explode(' | ', $input) as $subval) { if ($subanswer = $field->field_options()->whereTranslation('label', $subval)->first()) { $subinput[] = $subanswer->name; } } if (count($subinput) > 0) { $input = json_encode($subinput); } else { $input = NULL; } } } if ($input || $input == '0') { if ($field->type == 'image' || $field->type == 'file') { $action_name = 'upload_' . $field->type; if ($field->multiple) { foreach (explode(' | ', $input) as $subinput) { $input_array[] = \Asset::$action_name(public_path('seed/' . $node->name . '/' . $subinput), $node->name . '-' . $field->name, true); } $input = json_encode($input_array); } else { $input = \Asset::$action_name(public_path('seed/' . $node->name . '/' . $input), $node->name . '-' . $field->name, true); } } $item = \FuncNode::put_data_field($item, $field, $input, $language_code); } } else { if ($new_item && isset($field_sub_array[$column])) { $field = $field_sub_array[$column]; if ($field->multiple) { $array_insert = []; foreach (explode(';', $input) as $value) { if (!is_numeric($value)) { $sub_model = \Solunes\Master\App\Node::where('table_name', $column)->first()->model; array_push($array_insert, $sub_model::where('name', $value)->first()->id); } else { array_push($array_insert, $value); } } } else { if (!is_numeric($input)) { $sub_model = \Solunes\Master\App\Node::where('table_name', $column)->first()->model; $array_insert = $sub_model::where('name', $input)->first()->id; } else { $array_insert = $input; } $array_insert = [$array_insert]; } $sub_field_insert[$column] = $array_insert; } } } if ($new_item) { $item->save(); foreach ($sub_field_insert as $column => $input) { $item->{$column}()->sync($input); } } }); } } }); $this->info('100%: Se agregaron los datos del excel.'); }
public static function node_check_rules($node, $action) { $rules = []; $model = FuncNode::node_check_model($node); if ($node->dynamic) { $rules = $model->rules($node->table_name); if ($rules == NULL) { $rules = []; } } else { if ($action == 'create') { $rules = $model::$rules_create; } else { if ($action == 'edit') { $rules = $model::$rules_edit; } } } return $rules; }