/**
  * 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']]);
 }
 /**
  * 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 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 node_field_creation($table_name, $node, $name, $translation, $count, $languages)
 {
     $count++;
     $model = $node->model;
     $type = 'string';
     $value = NULL;
     $trans_name = $name;
     $display_list = 'show';
     $display_item = 'show';
     $multiple = 0;
     $required = 0;
     $preset = 0;
     $new_row = false;
     $permission = NULL;
     $col_type = \DB::select(\DB::raw("SHOW FIELDS FROM " . $table_name . " where Field  = '" . $name . "'"))[0]->Type;
     $extras = [];
     $requests = [];
     $field_options = [];
     if (strpos($name, '_id') !== false) {
         $type = 'relation';
         $trans_name = str_replace('_id', '', $name);
         $value = $trans_name;
         if ($name == 'parent_id') {
             $preset = 1;
             if ($node->parent) {
                 $value = $node->parent->name;
             } else {
                 $value = $node->name;
             }
         }
     } else {
         if ($name == 'image' || $name == 'file' || $name == 'logo' || $name == 'isotype' || strpos($name, 'image') !== false || strpos($name, 'file') !== false) {
             if ($name == 'file' || strpos($name, 'file') !== false) {
                 $type = 'file';
             } else {
                 $type = 'image';
             }
             if ($col_type == 'text') {
                 $multiple = 1;
             }
             array_push($extras, ['type' => 'folder', 'value' => $node->name . '-' . $name]);
         } else {
             if (strpos($name, 'checkbox') !== false) {
                 $type = 'checkbox';
                 array_push($extras, ['type' => 'cols', 'value' => '12']);
             } else {
                 if ($col_type == 'text') {
                     $type = 'text';
                     $new_row = true;
                     array_push($extras, ['type' => 'class', 'value' => 'simple-textarea']);
                     array_push($extras, ['type' => 'cols', 'value' => '12']);
                     array_push($extras, ['type' => 'rows', 'value' => '3']);
                 } else {
                     if ($name == 'password') {
                         $type = 'password';
                     } else {
                         if ($name == 'map') {
                             $type = 'map';
                             array_push($extras, ['type' => 'cols', 'value' => '12']);
                         } else {
                             if ($col_type == 'tinyint(1)' || substr_count($col_type, 'enum') > 0) {
                                 $type = 'select';
                                 if (substr_count($col_type, 'enum') > 0) {
                                     $value_array = substr($col_type, 6, -2);
                                 } else {
                                     if ($col_type == 'tinyint(1)') {
                                         $value_array = "0','1";
                                     }
                                 }
                                 foreach (explode("','", $value_array) as $subvalue) {
                                     array_push($field_options, ['name' => $subvalue]);
                                 }
                             } else {
                                 if ($col_type == 'timestamp' || $col_type == 'date' || $col_type == 'time') {
                                     $type = 'date';
                                     if ($node->type == 'subchild') {
                                         array_push($extras, ['type' => 'class', 'value' => $col_type . '-control']);
                                     } else {
                                         array_push($extras, ['type' => 'class', 'value' => $col_type . 'picker']);
                                     }
                                     if ($name == 'created_at') {
                                         \Solunes\Master\App\Filter::create(['node_id' => $node->id, 'type' => 'field', 'subtype' => 'date', 'parameter' => 'created_at']);
                                     } else {
                                         if ($name == 'deleted_at') {
                                             $node->soft_delete = 1;
                                             $node->save();
                                         }
                                     }
                                 } else {
                                     if (strpos($name, 'array') !== false) {
                                         $type = 'array';
                                         array_push($extras, ['type' => 'rows', 'value' => '2']);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $hidden_names = ['id', 'site_id', 'slug', 'password', 'created_at', 'updated_at', 'deleted_at'];
     if (in_array($name, $hidden_names)) {
         $display_list = 'excel';
         $display_item = 'none';
         if ($name == 'password') {
             $display_item = 'admin';
         }
     } else {
         if ($name == 'section_id') {
             $display_item = 'admin';
             array_push($requests, ['action' => 'where', 'col' => $name, 'value_type' => 'relation', 'value' => 'node_pivot_id']);
         } else {
             if ($count > 6) {
                 $display_list = 'excel';
             }
         }
     }
     if ($node->type != 'field') {
         $rules = \FuncNode::node_check_rules($node, 'create');
         if (array_key_exists($name, $rules) && strpos($rules[$name], 'required') !== false) {
             $required = 1;
         }
     }
     $field = new \Solunes\Master\App\Field();
     $field->parent_id = $node->id;
     $field->name = $name;
     $field->trans_name = $trans_name;
     $field->type = $type;
     $field->order = $count;
     $field->display_list = $display_list;
     $field->display_item = $display_item;
     $field->translation = $translation;
     $field->multiple = $multiple;
     $field->new_row = $new_row;
     $field->value = $value;
     $field->preset = $preset;
     $field->required = $required;
     $field->save();
     \FuncNode::node_generate_request($node, $requests);
     \FuncNode::field_generate_extras($field, $extras);
     \FuncNode::field_generate_options($node, $field, $field_options, $languages);
     return $count;
 }
 public static function filter_node($array, $node, $model, $items, $type = 'admin', $parent_field_join = 'parent_id')
 {
     if ($type == 'custom' || $type == 'indicator') {
         $filters = \Solunes\Master\App\Filter::checkCategory($type)->checkDisplay()->where('category_id', $array['filter_category_id']);
     } else {
         $filters = $node->filters()->checkCategory($type)->checkDisplay();
     }
     $filters = $filters->orderBy('order', 'ASC')->get();
     $custom_check = \CustomFunc::check_custom_filter($type, $node);
     if (count($filters) > 0) {
         $appends = NULL;
         $array['additional_queries'] = [];
         /*foreach(request()->all() as $input_key => $input_val){
               if(stripos($input_key, 'f_') === false){
                   $array['additional_queries'][$input_key] = $input_val;
               }
           }*/
         if (request()->input('search')) {
             $array['search'] = 1;
         }
         $array['filters'] = [];
         $array['filter_string_options'] = ['none' => trans('master::fields.none'), 'is' => trans('master::fields.is'), 'is_not' => trans('master::fields.is_not'), 'is_greater' => trans('master::fields.is_greater'), 'is_less' => trans('master::fields.is_less'), 'where_in' => trans('master::fields.where_in')];
         foreach ($filters as $filter) {
             $field_name = $filter->parameter;
             $array['filters'][$field_name] = ['subtype' => $filter->subtype, 'id' => $filter->id];
             if ($type == 'custom' || $type == 'indicator') {
                 $node = $filter->node;
                 if ($type == 'custom') {
                     $array['filters'][$field_name]['node_name'] = $node->name;
                 }
             }
             if ($custom_check != 'false') {
                 $custom_array = \CustomFunc::custom_filter($custom_check, $array, $items, $appends, $node, $model, $filter, $type, $field_name, $parent_field_join);
                 $array = $custom_array['array'];
                 $appends = $custom_array['appends'];
                 $items = $custom_array['items'];
             } else {
                 if ($filter->type == 'custom') {
                     $custom_array = \CustomFunc::custom_filter_field($array, $items, $appends, $field_name, $custom_data);
                     $array = $custom_array['array'];
                     $appends = $custom_array['appends'];
                     $items = $custom_array['items'];
                 } else {
                     // Calcular Custom Value
                     $custom_array = \AdminList::filter_custom_value($array, $appends, $node, $filter, $type, $field_name);
                     $array = $custom_array['array'];
                     $appends = $custom_array['appends'];
                     $custom_value = $custom_array['custom_value'];
                     $field = $custom_array['field'];
                     // Obtener items segun tipo
                     $custom_array = \AdminList::filter_items_get($items, $node, $model, $filter, $field, $field_name, $custom_value);
                     $items = $custom_array['items'];
                     $date_model = $custom_array['date_model'];
                     // Corregir campos de fecha
                     $array = \AdminList::filter_date_field($array, $date_model, $filter, $field_name);
                 }
             }
         }
         $array['filter_values'] = $appends;
         if ($appends) {
             $appends = 'parameters=' . htmlentities(json_encode($appends));
         }
         $array['appends'] = $appends;
     } else {
         $array['appends'] = NULL;
         $array['filters'] = false;
     }
     $array['items'] = $items;
     return $array;
 }