/**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     // General
     \Solunes\Master\App\Language::create(['code' => 'es', 'name' => 'Español', 'image' => 'es.png']);
     \Solunes\Master\App\Site::create(['name' => 'Plataforma', 'domain' => 'http://master.dev/', 'root' => '/', 'google_verification' => '', 'analytics' => '']);
     // Nodos
     $node_node = \Solunes\Master\App\Node::create(['name' => 'node', 'folder' => 'system']);
     $node_node_requests = \Solunes\Master\App\Node::create(['name' => 'node-request', 'location' => 'package', 'type' => 'subchild', 'parent_id' => $node_node->id]);
     $node_node_extras = \Solunes\Master\App\Node::create(['name' => 'node-extra', 'type' => 'subchild', 'location' => 'package', 'parent_id' => $node_node->id]);
     $node_filter = \Solunes\Master\App\Node::create(['name' => 'filter', 'folder' => 'system']);
     $node_field = \Solunes\Master\App\Node::create(['name' => 'field', 'type' => 'child', 'location' => 'package', 'parent_id' => $node_node->id]);
     $node_field_extras = \Solunes\Master\App\Node::create(['name' => 'field-extra', 'type' => 'subchild', 'location' => 'package', 'parent_id' => $node_field->id]);
     $node_field_conditional = \Solunes\Master\App\Node::create(['name' => 'field-conditional', 'type' => 'subchild', 'location' => 'package', 'parent_id' => $node_field->id]);
     $node_indicator = \Solunes\Master\App\Node::create(['name' => 'indicator', 'folder' => 'system', 'customized' => 1]);
     $node_indicator_alert = \Solunes\Master\App\Node::create(['name' => 'indicator-alert', 'type' => 'subchild', 'location' => 'package', 'parent_id' => $node_indicator->id]);
     $node_indicator_graph = \Solunes\Master\App\Node::create(['name' => 'indicator-graph', 'type' => 'subchild', 'location' => 'package', 'parent_id' => $node_indicator->id]);
     $node_indicator_value = \Solunes\Master\App\Node::create(['name' => 'indicator-value', 'type' => 'child', 'location' => 'package', 'parent_id' => $node_indicator->id]);
     $node_site = \Solunes\Master\App\Node::create(['name' => 'site', 'folder' => 'global']);
     $node_page = \Solunes\Master\App\Node::create(['name' => 'page', 'folder' => 'global']);
     $node_menu = \Solunes\Master\App\Node::create(['name' => 'menu', 'folder' => 'global']);
     $node_section = \Solunes\Master\App\Node::create(['name' => 'section', 'folder' => 'global']);
     $node_permission = \Solunes\Master\App\Node::create(['name' => 'permission', 'folder' => 'system']);
     $node_role = \Solunes\Master\App\Node::create(['name' => 'role', 'folder' => 'system']);
     $node_permission_role = \Solunes\Master\App\Node::create(['name' => 'permission-role', 'table_name' => 'permission_role', 'location' => 'package', 'type' => 'field', 'model' => '\\Solunes\\Master\\App\\Permission', 'parent_id' => $node_role->id]);
     $node_user = \Solunes\Master\App\Node::create(['name' => 'user', 'location' => 'app', 'folder' => 'global']);
     \Solunes\Master\App\Filter::create(['node_id' => $node_user->id, 'parameter' => 'status']);
     $node_role_user = \Solunes\Master\App\Node::create(['name' => 'role-user', 'table_name' => 'role_user', 'location' => 'package', 'type' => 'field', 'model' => '\\Solunes\\Master\\App\\Role', 'parent_id' => $node_user->id]);
     $node_email = \Solunes\Master\App\Node::create(['name' => 'email', 'folder' => 'global']);
     $node_activity = \Solunes\Master\App\Node::create(['name' => 'activity', 'table_name' => 'activities', 'folder' => 'system']);
     $node_notification = \Solunes\Master\App\Node::create(['name' => 'notification', 'folder' => 'system']);
     $node_inbox = \Solunes\Master\App\Node::create(['name' => 'inbox', 'table_name' => 'inbox', 'folder' => 'system']);
     $node_inbox_users = \Solunes\Master\App\Node::create(['name' => 'inbox-user', 'type' => 'subchild', 'location' => 'package', 'parent_id' => $node_inbox->id]);
     $node_inbox_messages = \Solunes\Master\App\Node::create(['name' => 'inbox-message', 'type' => 'subchild', 'location' => 'package', 'parent_id' => $node_inbox->id]);
     $node_variable = \Solunes\Master\App\Node::create(['name' => 'variable', 'folder' => 'global']);
     $node_image_folder = \Solunes\Master\App\Node::create(['name' => 'image-folder', 'folder' => 'system']);
     $node_image_size = \Solunes\Master\App\Node::create(['name' => 'image-size', 'type' => 'subchild', 'location' => 'package', 'parent_id' => $node_image_folder->id]);
     $node_temp_file = \Solunes\Master\App\Node::create(['name' => 'temp-file', 'folder' => 'system']);
     // Usuarios
     $admin = \Solunes\Master\App\Role::create(['name' => 'admin', 'display_name' => 'Admin']);
     $member = \Solunes\Master\App\Role::create(['name' => 'member', 'display_name' => 'Miembro']);
     $system_perm = \Solunes\Master\App\Permission::create(['name' => 'system', 'display_name' => 'Sistema']);
     $global_perm = \Solunes\Master\App\Permission::create(['name' => 'global', 'display_name' => 'Global']);
     $site_perm = \Solunes\Master\App\Permission::create(['name' => 'site', 'display_name' => 'Site']);
     $form_perm = \Solunes\Master\App\Permission::create(['name' => 'form', 'display_name' => 'Formulario']);
     $dashboard_perm = \Solunes\Master\App\Permission::create(['name' => 'dashboard', 'display_name' => 'Dashboard']);
     $admin->permission_role()->sync([$global_perm->id, $site_perm->id, $form_perm->id, $dashboard_perm->id]);
     // Tamaños de archivos
     \Solunes\Master\App\Variable::create(['name' => 'image_size', 'type' => 'string', 'es' => ['value' => '5']]);
     \Solunes\Master\App\Variable::create(['name' => 'file_size', 'type' => 'string', 'es' => ['value' => '10']]);
     \Solunes\Master\App\Variable::create(['name' => 'image_extension', 'type' => 'string', 'es' => ['value' => 'jpg,jpeg,png,gif']]);
     \Solunes\Master\App\Variable::create(['name' => 'file_extension', 'type' => 'string', 'es' => ['value' => 'doc,docx,xls,xlsx,ppt,pptx,pdf,txt,jpg,jpeg,png,gif']]);
 }
 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);
     }
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     \Solunes\Master\App\ImageSize::truncate();
     \Solunes\Master\App\ImageFolder::truncate();
     \Solunes\Master\App\TempFile::truncate();
     \Solunes\Master\App\VariableTranslation::truncate();
     \Solunes\Master\App\Variable::truncate();
     \Solunes\Master\App\InboxUser::truncate();
     \Solunes\Master\App\InboxMessage::truncate();
     \Solunes\Master\App\Inbox::truncate();
     \Solunes\Master\App\Notification::truncate();
     \Solunes\Master\App\Activity::truncate();
     DB::table('permission_role')->truncate();
     DB::table('role_user')->truncate();
     \Solunes\Master\App\Role::truncate();
     \Solunes\Master\App\Permission::truncate();
     \App\User::truncate();
     \Solunes\Master\App\EmailTranslation::truncate();
     \Solunes\Master\App\Email::truncate();
     \Solunes\Master\App\IndicatorValue::truncate();
     \Solunes\Master\App\IndicatorGraph::truncate();
     \Solunes\Master\App\IndicatorAlert::truncate();
     \Solunes\Master\App\Indicator::truncate();
     \Solunes\Master\App\FieldOptionTranslation::truncate();
     \Solunes\Master\App\FieldOption::truncate();
     \Solunes\Master\App\FieldConditional::truncate();
     \Solunes\Master\App\FieldExtra::truncate();
     \Solunes\Master\App\FieldTranslation::truncate();
     \Solunes\Master\App\Field::truncate();
     \Solunes\Master\App\Section::truncate();
     \Solunes\Master\App\Filter::truncate();
     \Solunes\Master\App\NodeExtra::truncate();
     \Solunes\Master\App\NodeRequest::truncate();
     \Solunes\Master\App\NodeTranslation::truncate();
     \Solunes\Master\App\Node::truncate();
     \Solunes\Master\App\MenuTranslation::truncate();
     \Solunes\Master\App\Menu::truncate();
     \Solunes\Master\App\PageTranslation::truncate();
     \Solunes\Master\App\Page::truncate();
     \Solunes\Master\App\SiteTranslation::truncate();
     \Solunes\Master\App\Site::truncate();
     \Solunes\Master\App\Language::truncate();
     \App\PasswordReminder::truncate();
 }
 /**
  * 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 function getDeleteAllFilters($category, $category_id, $node_id = NULL)
 {
     $filters = \Solunes\Master\App\Filter::checkCategory($category)->checkDisplay();
     if ($category_id == 0) {
         $node = \Solunes\Master\App\Node::where('name', $node_id)->first();
         $filters->where('node_id', $node->id)->delete();
     } else {
         $filters->where('category_id', $category_id)->delete();
     }
     return redirect($this->prev);
 }
 public static function load_nodes_excel($path, $return = '')
 {
     $languages = \Solunes\Master\App\Language::get();
     \Excel::load($path, function ($reader) use($return, $languages) {
         foreach ($reader->get() as $sheet) {
             $sheet_name = $sheet->getTitle();
             $sheet->each(function ($row) use($sheet_name, $return, $languages) {
                 $node = \Solunes\Master\App\Node::where('name', $row->node)->first();
                 if ($sheet_name == 'create-fields') {
                     if ($node) {
                         if ($node->location == 'package') {
                             $lang_folder = 'master::fields.';
                         } else {
                             $lang_folder = 'fields.';
                         }
                         $field = new \Solunes\Master\App\Field();
                         $field->parent_id = $node->id;
                         $field->name = $row->name;
                         $field->trans_name = $row->trans_name;
                         foreach ($languages as $language) {
                             \App::setLocale($language->code);
                             $field->translateOrNew($language->code)->label = trans($lang_folder . $row->trans_name);
                         }
                         \App::setLocale('es');
                         $field->type = $row->type;
                         $field->display_list = $row->display_list;
                         $field->display_item = $row->display_item;
                         $field->multiple = $row->multiple;
                         $field->translation = $row->translation;
                         $field->required = $row->required;
                         $field->order = $row->order;
                         $field->new_row = $row->new_row;
                         $field->preset = $row->preset;
                         $field->message = $row->message;
                         $field->value = $row->value;
                         $field->save();
                     } else {
                         $return .= 'ALERTA: No se encontró el nodo ' . $row->node . '.\\n';
                     }
                 } else {
                     if ($node && ($field = $node->fields()->where('name', $row->field)->first())) {
                         if ($sheet_name == 'edit-fields') {
                             $column = $row->column;
                             $field->{$column} = $row->new_value;
                             $field->save();
                         } else {
                             if ($sheet_name == 'extras') {
                                 if ($extra = $field->field_extras()->where('type', $row->type)->first()) {
                                     $extra->value = $row->new_value;
                                 } else {
                                     $extra = new \Solunes\Master\App\FieldExtra();
                                     $extra->parent_id = $field->id;
                                     $extra->type = $row->type;
                                     $extra->value = $row->new_value;
                                 }
                                 $extra->save();
                             } else {
                                 if ($sheet_name == 'conditionals') {
                                     $conditional = new \Solunes\Master\App\FieldConditional();
                                     $conditional->parent_id = $field->id;
                                     $conditional->trigger_field = $row->trigger_field;
                                     $conditional->trigger_show = $row->trigger_show;
                                     $conditional->trigger_value = $row->trigger_value;
                                     $conditional->save();
                                 }
                             }
                         }
                     } else {
                         $return .= 'ALERTA: No se encontró el campo ' . $row->field . ' o nodo ' . $row->node . '.\\n';
                     }
                 }
             });
         }
     });
     return $return;
 }
 public static function post_request_success($request, $model, $item, $type = 'admin')
 {
     $node = \Solunes\Master\App\Node::where('name', $model)->first();
     if ($type == 'admin') {
         if (\Gate::denies('node-admin', ['item', $type, $node, $request->input('action'), $request->input('id')])) {
             return \Login::redirect_dashboard('no_permission');
         }
     }
     if ($type == 'admin') {
         $display_array = ['none'];
     } else {
         $display_array = ['item_admin', 'none'];
     }
     $total_ponderation = 0;
     $rejected_fields = ['title', 'content', 'child', 'subchild', 'field'];
     foreach ($node->fields()->whereNotIn('type', $rejected_fields)->whereNotIn('display_item', $display_array)->with('field_extras')->get() as $field) {
         $field_name = $field->name;
         $input = NULL;
         if ($request->has($field_name)) {
             $input = $request->input($field_name);
         }
         if ($input && $input != 0 && ($pond = $field->field_extras()->where('type', 'ponderation')->first())) {
             $total_ponderation = $total_ponderation + $pond->value;
         }
         $item = \FuncNode::put_data_field($item, $field, $input);
     }
     if ($total_ponderation > 0) {
         $item->total_ponderation = $total_ponderation;
     }
     $item->save();
     foreach ($node->fields()->whereIn('type', ['subchild', 'field'])->get() as $field) {
         if ($field->type == 'subchild') {
             $subfield_name = str_replace('_', '-', $field->value);
             $sub_node = \Solunes\Master\App\Node::where('name', $subfield_name)->first();
             $sub_node_table = $sub_node->table_name;
             AdminItem::post_subitems($sub_node, $field->name, 'parent_id', $item->id, $sub_node->fields()->where('display_item', '!=', 'none')->whereNotIn('name', ['id', 'parent_id'])->get());
             foreach ($node->fields()->where('child_table', $sub_node_table)->get() as $field_extra) {
                 $field_extra_name = $field_extra->name;
                 if ($field_extra_name == $sub_node_table . '_count') {
                     $subvalue = count($item->{$sub_node_table});
                 } else {
                     $field_extra_name_fixed = str_replace('_total', '', $field_extra_name);
                     $subvalue = 0;
                     foreach ($item->{$sub_node_table} as $sub_item) {
                         $subvalue += $sub_item->{$field_extra_name_fixed};
                     }
                 }
                 $item->{$field_extra_name} = $subvalue;
                 $item->save();
             }
         } else {
             $field_name = $field->name;
             if ($field->multiple) {
                 $item->{$field_name}()->sync($request->input($field_name));
             } else {
                 $item->{$field_name}()->sync([$request->input($field_name)]);
             }
         }
     }
     foreach ($node->indicators as $indicator) {
         $node_model = \FuncNode::node_check_model($node);
         $items = \FuncNode::node_check_model($node);
         $array = \AdminList::filter_node(['filter_category_id' => $indicator->id], $node, $node_model, $items, 'indicator');
         $items = $array['items'];
         if ($indicator->type == 'count') {
             $indicator_value = $items->count();
         } else {
             $indicator_value = $items->count();
         }
         if ($today_indicator = $indicator->indicator_values()->where('date', date('Y-m-d'))->first()) {
         } else {
             $today_indicator = new \Solunes\Master\App\IndicatorValue();
             $today_indicator->parent_id = $indicator->id;
             $today_indicator->date = date('Y-m-d');
         }
         $today_indicator->value = $indicator_value;
         $today_indicator->save();
     }
     \Asset::delete_temp();
     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.');
 }
Ejemplo n.º 9
0
<?php

Route::get('sitemap.xml', function () {
    // create new sitemap object
    $sitemap = App::make("sitemap");
    $sitemap->setCache('laravel.sitemap', 3600);
    if (!$sitemap->isCached()) {
        foreach (\Solunes\Master\App\Language::get() as $lang) {
            \App::setLocale($lang->code);
            foreach (\Solunes\Master\App\Page::get() as $page) {
                if ($page->id == 1) {
                    $priority = '1.0';
                } else {
                    $priority = '0.9';
                }
                $sitemap->add($page->translate($lang->code)->slug, $page->created_at, $priority, 'daily');
            }
            $node_array = \CustomFunc::get_sitemap_array($lang->code);
            if (count($node_array) > 0) {
                foreach ($node_array as $node_key => $node_item) {
                    $node = \Solunes\Master\App\Node::where('name', $node_key)->first();
                    $node_model = $node->model;
                    foreach ($node_model::orderBy('created_at', 'desc')->get() as $post) {
                        $sitemap->add($node_item['url'] . $post->{$node_item}['url_id'], $post->created_at, $node_item['priority'], 'monthly');
                    }
                }
            }
        }
    }
    return $sitemap->render('xml');
});
 public static function get_list($object, $single_model, $extra = [])
 {
     $module = $object->module;
     $node = \Solunes\Master\App\Node::where('name', $single_model)->first();
     $model = \FuncNode::node_check_model($node);
     if (\Gate::denies('node-admin', ['list', $module, $node, 'list'])) {
         return \Login::redirect_dashboard('no_permission');
     }
     $array = ['module' => $module, 'node' => $node, 'model' => $single_model, 'i' => NULL, 'filter_category' => 'admin', 'filter_category_id' => '0', 'filter_type' => 'field', 'filter_node' => $node->name, 'dt' => 'form', 'id' => NULL, 'parent' => NULL, 'action_fields' => ['create', 'edit', 'delete']];
     if ($action_field = $node->node_extras()->where('type', 'action_field')->first()) {
         $array['action_fields'] = json_decode($action_field->value_array, true);
     }
     if (request()->has('parent_id')) {
         $id = request()->input('parent_id');
         $array['id'] = $id;
         $items = $model->whereHas('parent', function ($q) use($id) {
             $q->where('id', $id);
         });
     } else {
         $items = $model->whereNotNull('id');
     }
     if ($node) {
         if ($node->soft_delete == 1 && request()->has('view-trash') && request()->input('view-trash') == 'true') {
             $items->onlyTrashed();
         }
         if ($node->translation) {
             $items->with('translations');
         }
         if ($node->parent) {
             $array['parent'] = $node->parent->name;
         }
         if (request()->has('download-excel')) {
             $display_fields = ['show', 'excel'];
         } else {
             $display_fields = ['show'];
         }
         $array['fields'] = $node->fields()->whereIn('display_list', $display_fields)->where('type', '!=', 'field')->with('translations')->get();
         $relation_fields = $node->fields()->whereIn('display_list', $display_fields)->where('type', 'relation')->get();
         if (count($relation_fields) > 0) {
             foreach ($relation_fields as $relation) {
                 $sub_node = \Solunes\Master\App\Node::where('name', str_replace('_', '-', $relation->value))->first();
                 if ($sub_node->translation) {
                     $items = $items->with([$relation->trans_name, $relation->trans_name . '.translations']);
                 } else {
                     $items = $items->with($relation->trans_name);
                 }
             }
         }
     }
     $array = \AdminList::filter_node($array, $node, $model, $items, 'admin');
     $items = $array['items'];
     $graphs = $node->node_extras()->whereIn('type', ['graph', 'parent_graph'])->get();
     $array = \AdminList::graph_node($array, $node, $model, $items, $graphs);
     $items_relations = $node->fields()->where('name', '!=', 'parent_id')->whereIn('type', ['relation', 'child', 'subchild'])->get();
     if (count($items_relations) > 0) {
         foreach ($items_relations as $item_relation) {
             $items->with($item_relation->trans_name);
         }
     }
     $array['items'] = $items->get();
     if ($node->translation == 1) {
         $array['langs'] = \Solunes\Master\App\Language::get();
     } else {
         $array['langs'] = [];
     }
     if (request()->has('download-excel')) {
         return AdminList::generate_query_excel($array);
     } else {
         return view('master::list.general-list', $array);
     }
 }
Ejemplo n.º 11
0
 public function getChildFieldsAttribute()
 {
     if ($this->type == 'subchild') {
         $return = \Solunes\Master\App\Node::where('name', $this->value)->first()->fields()->where('display_item', '!=', 'none')->whereNotIn('name', ['id', 'parent_id'])->orderBy('order', 'ASC')->orderBy('id', 'ASC')->get();
     } else {
         $return = NULL;
     }
     return $return;
 }