/**
  * 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();
 }
 public function handle($menu)
 {
     if ($page = $menu->page) {
         foreach (\Solunes\Master\App\Language::get() as $language) {
             \App::setLocale($language->code);
             $menu->translateOrNew($language->code)->name = $page->name;
         }
     }
     // Definir Order
     if (!$menu->order) {
         if ($menu_group = \Solunes\Master\App\Menu::where('type', $menu->type)->where("level", $menu->level)->orderBy("order", "DESC")->first()) {
             $order = $menu_group->order;
         } else {
             $order = 0;
         }
         $order = $order + 1;
         $menu->order = $order;
     }
 }
 public static function node_menu_creation($node, $languages)
 {
     $menu_array = \Solunes\Master\App\Menu::where('menu_type', 'admin')->where('level', 1)->lists('id');
     if ($node->folder) {
         if ($menu_parent = \Solunes\Master\App\MenuTranslation::whereIn('menu_id', $menu_array)->where('name', trans('admin.' . $node->folder))->first()) {
             $menu_parent = $menu_parent->menu;
         } else {
             $menu_parent = \Solunes\Master\App\Menu::create(['type' => 'blank', 'menu_type' => 'admin', 'permission' => $node->folder, 'icon' => 'th-list']);
             foreach ($languages as $language) {
                 \App::setLocale($language->code);
                 $menu_parent->translateOrNew($language->code)->name = trans('admin.' . $node->folder);
             }
             \App::setLocale('es');
             $menu_parent->save();
         }
         $menu = \Solunes\Master\App\Menu::create(['menu_type' => 'admin', 'permission' => $node->permission, 'parent_id' => $menu_parent->id, 'level' => 2, 'icon' => 'th-list']);
         foreach ($languages as $language) {
             \App::setLocale($language->code);
             $menu->translateOrNew($language->code)->name = $node->plural;
             $menu->translateOrNew($language->code)->link = 'admin/model-list/' . $node->name;
         }
         \App::setLocale('es');
         $menu->save();
     }
 }
 /**
  * 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.');
 }
 /**
  * Run the request filter.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure                  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if (auth()->check() && auth()->user()->isSuperAdmin()) {
         $user_permissions = \Solunes\Master\App\Permission::lists('name');
     } else {
         if (auth()->check()) {
             $user_permissions = auth()->user()->getPermission();
         } else {
             $user_permissions = [];
         }
     }
     if ($request->segment(1) == 'auth') {
         Menu::make('main', function ($menu) {
             $login = $menu->add('Ingresar', 'auth/login');
             $login->prepend('<span class="title"><i class="fa fa-user"></i>');
             $login->append('</span>');
         });
     } else {
         $menu_options = \Solunes\Master\App\Menu::where('site_id', 1)->menuQuery('admin', 1)->get();
         Menu::make('main', function ($menu) use($request, $menu_options, $user_permissions) {
             foreach ($menu_options as $menu_option) {
                 if (!$menu_option->permission || auth()->check() && $user_permissions->contains($menu_option->permission)) {
                     $first_level = $menu->add($menu_option->name, $menu_option->real_link);
                     $first_level->prepend('<span class="title">');
                     if ($menu_option->icon) {
                         $first_level->prepend('<i class="fa fa-' . $menu_option->icon . '"></i>');
                     }
                     $first_level->append('</span>');
                     if (count($menu_option->children) > 0) {
                         $first_level->append('<span class="arrow"></span>');
                         $first_level->attribute(['class' => 'nav-link nav-toggle']);
                         foreach ($menu_option->children as $menu_children) {
                             if (!$menu_children->permission || auth()->check() && $user_permissions->contains($menu_children->permission)) {
                                 $second_level = $first_level->add($menu_children->name, $menu_children->real_link);
                                 if ($menu_children->icon) {
                                     $second_level->prepend('<i class="fa fa-' . $menu_children->icon . '"></i>');
                                 }
                                 if (count($menu_children->children) > 0) {
                                     $second_level->append('<span class="arrow"></span>');
                                     $second_level->attribute(['class' => 'nav-link nav-toggle']);
                                     foreach ($menu_children->children as $menu_children2) {
                                         $third_level = $second_level->add($menu_children2->name, $menu_children2->real_link);
                                         $third_level->attribute(['class' => 'nav-link']);
                                         if ($menu_children2->icon) {
                                             $third_level->prepend('<i class="fa fa-' . $menu_children2->icon . '"></i>');
                                         }
                                     }
                                 } else {
                                     $second_level->attribute(['class' => 'nav-link']);
                                 }
                             }
                         }
                     } else {
                         $first_level->attribute(['class' => 'nav-link']);
                     }
                 }
             }
         });
     }
     return $next($request);
 }