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 postUpload(Request $request) { $error = false; if ($request->hasFile('file') && $request->has('type') && $request->has('folder')) { $type = $request->input('type'); $folder = $request->input('folder'); $file = $request->file('file'); if ($type == 'image') { $filesize = \FuncNode::check_var('image_size'); $file_array = explode(',', \FuncNode::check_var('image_extension')); $error_size = 'La imagen debe tener un tamaño menor a ' . $filesize . ' MB.'; $error_ext = 'Debe ingresar una imagen valida.'; } else { $filesize = \FuncNode::check_var('file_size'); $file_array = explode(',', \FuncNode::check_var('file_extension')); $error_size = 'El archivo debe tener un tamaño menor a ' . $filesize . ' MB.'; $error_ext = 'Debe ingresar un archivo en un formato valido.'; } $file_size = $file->getClientSize(); $file_name = (string) $file->getClientOriginalName(); $file_ext = (string) $file->getClientOriginalExtension(); if ($file_size > $filesize * 1000000) { $error = $file_name . ': ' . $error_size; } else { if (!in_array($file_ext, $file_array)) { $error = $file_name . ': ' . $error_ext; } } } else { if (!$request->hasFile('file')) { $error = 'Debe ingresar un archivo válido.'; } else { if (!$request->has('type')) { $error = 'Debe ingresar un tipo de archivo.'; } else { if (!$request->has('folder')) { $error = 'Debe ingresar un folder válido.'; } } } } if ($error === false) { if ($type == 'image') { $new_file = Asset::upload_image($file, $folder); $get_file = Asset::get_image_path($folder, 'normal', $new_file); $get_thumb = Asset::get_image_path($folder, 'mini', $new_file); } else { $new_file = Asset::upload_file($file, $folder); $get_file = Asset::get_file($folder, $new_file); $get_thumb = $get_file; } \Solunes\Master\App\TempFile::create(['type' => $type, 'folder' => $folder, 'file' => $new_file]); $response = ['files' => [['name' => $new_file, 'url' => $get_file, 'thumbUrl' => $get_thumb]]]; $error_code = 200; } else { $response = ['error' => $error]; $error_code = 400; } return response()->json($response)->setStatusCode($error_code); }
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); }
public function handle($event) { $event_model = '\\' . get_class($event); // Revisar que tenga una sesión y sea un modelo del sitio web. if ($event && request()->segment(1) != 'artisan' && ($node = \Solunes\Master\App\Node::where('type', '!=', 'subchild')->whereNotIn('name', ['menu', 'user', 'activity', 'notification'])->where('model', $event_model)->first())) { try { $event_string = (string) json_encode($event); $event_decoded = json_decode($event_string); } catch (Exception $e) { return false; } if (\Auth::check()) { $now = new \DateTime(); $user = \Auth::user(); $user->last_activity = $now; $user->save(); $user_id = $user->id; $username = '******'; } else { $user_id = NULL; if (strpos(php_sapi_name(), 'cli') !== false) { $username = '******'; } else { $username = '******'; } } // CREAR ACTIVIDAD if ($event->wasRecentlyCreated == 1) { $action = 'node_created'; } else { $action = 'node_edited'; } $message = ''; if ($node->location == 'package') { $lang_folder = 'master::fields.'; } else { $lang_folder = 'fields.'; } if (count($event_decoded) > 0) { foreach ($event_decoded as $key => $i) { if (is_string($i) && is_string($key) && strpos($key, '_id') === false && $key != 'id' && $key != 'created_at' && $key != 'updated_at') { $message .= '<strong>' . trans($lang_folder . $key) . ':</strong> ' . strip_tags($i) . '<br>'; } } } \FuncNode::make_activity($node->id, $event->id, $user_id, $username, $action, $message); } }
/** * 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 put_data_field($item, $field, $input, $lang_code = 'es') { $field_name = $field->name; if (is_array($input)) { $final_input = json_encode($input); if ($field->type == 'image' || $field->type == 'file') { \Solunes\Master\App\TempFile::where('type', $field->type)->whereIn('file', $input)->delete(); } } else { if ($input && ($field->type == 'image' || $field->type == 'file')) { \Solunes\Master\App\TempFile::where('type', $field->type)->where('file', $input)->delete(); } $final_input = $input; } if (is_string($final_input) && trim($final_input) === '') { $final_input = NULL; } $item = \FuncNode::put_in_database($item, $field, $field_name, $final_input, $lang_code); return $item; }
/** * Execute the console command. * * @return mixed */ public function handle() { $this->info('0%: Generador de Nodos iniciado.'); $this->info('20%: Las tablas fueron limpiadas.'); $nodes = \Solunes\Master\App\Node::get(); $total_count = 0; \App::setLocale('es'); $languages = \Solunes\Master\App\Language::get(); $menu_dashboard = \Solunes\Master\App\Menu::create(['menu_type' => 'admin', 'permission' => 'dashboard', 'icon' => 'dashboard']); foreach ($languages as $language) { \App::setLocale($language->code); $menu_dashboard->translateOrNew($language->code)->name = trans('master::admin.dashboard'); $menu_dashboard->translateOrNew($language->code)->link = 'admin'; } \App::setLocale('es'); $menu_dashboard->save(); foreach ($nodes as $node) { if ($node->location == 'package') { $lang_folder = 'master::model.'; } else { $lang_folder = 'model.'; } foreach ($languages as $language) { \App::setLocale($language->code); $node->translateOrNew($language->code)->singular = trans_choice($lang_folder . $node->name, 1); $node->translateOrNew($language->code)->plural = trans_choice($lang_folder . $node->name, 0); } \App::setLocale('es'); $node->save(); $table_name = $node->table_name; $columns = \Schema::getColumnListing($table_name); if ($node->type == 'field') { $count = 0; foreach ($columns as $col) { $count = \FuncNode::node_field_creation($table_name, $node, $col, 0, $count, $languages); } $total_count += $count; } else { $model = $node->model; $initiated_model = new $model(); // CREAR MENU \FuncNode::node_menu_creation($node, $languages); // MENU CREADO, CREAR COLUMNAS $count = 0; foreach ($columns as $col) { if ($col != 'site_id') { $count = \FuncNode::node_field_creation($table_name, $node, $col, 0, $count, $languages); } } // REVISAR SI TIENE TRADUCCION Y SI SE DEBEN CREAR ESOS CAMPOS TAMBIEN if (property_exists($model, 'translatedAttributes')) { $node->translation = 1; $node->save(); foreach ($initiated_model->translatedAttributes as $col) { if ($col != 'site_id') { $count = \FuncNode::node_field_creation(str_replace('-', '_', $node->name) . '_translation', $node, $col, 1, $count, $languages); } } } // AGREGAR PARENT A DONDE CORRESPONDE if (count($node->children) > 0) { foreach ($node->children as $child) { $count++; $multiple = false; if ($child->type == 'field') { $child_value = str_replace($node->name . '-', '', $child->name); $child_value = str_replace('-' . $node->name, '', $child_value); } else { $child_value = $child->name; } if ($child->type == 'subchild') { $multiple = true; } $field = new \Solunes\Master\App\Field(); $field->parent_id = $node->id; $field->name = $child->table_name; $field->trans_name = str_replace($node->name . '-', '', $child->table_name); $field->type = $child->type; $field->order = $count; $field->multiple = $multiple; $field->value = $child_value; $field->save(); } } $total_count += $count; } $node->load('fields'); foreach ($node->fields as $field) { $saved = false; if (!$field->label) { if ($node->location == 'package') { $lang_folder = 'master::fields.'; } else { $lang_folder = 'fields.'; } foreach ($languages as $language) { \App::setLocale($language->code); $field->translateOrNew($language->code)->label = trans($lang_folder . $field->trans_name); } \App::setLocale('es'); $saved = true; } if ($saved === true) { $field->save(); } } } $this->info('95%: Se importara el excel de nodes para corregir los campos.'); $this->info(\FuncNode::load_nodes_excel(base_path(config('solunes.vendor_path') . '/src/nodes.xlsx'))); $this->info(\FuncNode::load_nodes_excel(public_path('seed/nodes.xlsx'))); $this->info('100%: Se crearon ' . $total_count . ' campos.'); }