public function boot(GateContract $gate) { parent::boot($gate); $gate->before(function ($user, $ability) { if ($user->isSuperAdmin()) { return true; } }); $gate->define('dashboard', function ($user) { return $user->isAdmin(); }); $gate->define('node-admin', function ($user, $type, $module, $node, $action, $id = NULL) { $custom_check = \CustomFunc::check_permission($type, $module, $node, $action, $id); if ($custom_check != 'none') { if ($custom_check == 'true') { $return = true; } else { $return = false; } } else { $return = false; if ($node->permission) { if ($user->hasPermission($node->permission)) { $return = true; } } else { $return = true; } } return $return; }); }
public function showPage($slug) { if ($page_translation = \App\PageTranslation::findBySlug($slug)) { $page = $page_translation->page; if ($page->type != 'blank' && $page->type != 'external' && $page_translation->locale != \App::getLocale()) { return redirect('change-locale/' . $page_translation->locale . '/' . $page_translation->slug); } $array = ['page' => $page, 'i' => NULL, 'dt' => false]; if ($page->type == 'blank' || $page->type == 'external') { return abort(404); } $slug = $page_translation->slug; if ($slug == 'postulacion-a' || $slug == 'postulacion-b') { if (!\Auth::check()) { return redirect()->guest('auth/login'); } if (request()->has('postulation_a') && $slug == 'postulacion-a') { if (!\Auth::user()->registry_a()->whereHas('postulation_a', function ($query) { $query->where('id', request()->input('postulation_a')); $query->where('status', 'holding'); })->first()) { return redirect('postulaciones')->with(['message_error' => 'No tiene acceso para editar este formulario.']); } } else { if (request()->has('postulation_b') && $slug == 'postulacion-b') { if (!\Auth::user()->registry_b()->whereHas('postulation_b', function ($query) { $query->where('id', request()->input('postulation_b')); $query->where('status', 'holding'); })->first()) { return redirect('postulaciones')->with(['message_error' => 'No tiene acceso para editar este formulario.']); } } else { return redirect('postulaciones')->with(['message_error' => 'Hubo un error al realizar su consulta.']); } } } foreach ($page->nodes as $node) { $array = \Segment::get_node_array($array, $node, $page); } $array = array_merge($array, \CustomFunc::get_page_array($page)); if ($page->type == 'customized') { if ($page->customized_name == 'home') { $array['social_networks'] = \App\SocialNetwork::get(); } else { if ($page->customized_name == 'postulaciones') { $array['registry_a'] = \Auth::user()->registry_a; $array['registry_b'] = \Auth::user()->registry_b; } } return view('content.' . $page->customized_name, $array); } else { return view('content.page', $array); } } else { return abort(404); } }
/** * Execute the console command. * * @return mixed */ public function handle() { if (\App::environment('local')) { $time_start = microtime(true); $this->info('0%: Seed iniciado.'); $this->callSilent('empty:storage'); $this->info('20%: Storage limpiado correctamente.'); $this->callSilent('db:seed', ['--class' => 'DatabaseTruncateSeeder']); $this->callSilent('db:seed', ['--class' => '\\Solunes\\Master\\Database\\Seeds\\DatabaseTruncateSeeder']); $this->callSilent('db:seed', ['--class' => '\\Solunes\\Master\\Database\\Seeds\\DatabaseMasterSeeder']); $this->callSilent('db:seed', ['--class' => 'DatabaseMasterSeeder']); $this->info('50%: Base de datos llenada correctamente.'); $this->callSilent('generate-nodes'); $this->info('70%: Campos de nodos creados correctamente.'); $this->info('80%: ' . \CustomFunc::before_seed_actions()); $this->callSilent('import-excel'); $this->info('95%: Campos de nodos creados correctamente.'); $this->info('99%: ' . \CustomFunc::after_seed_actions()); $this->info('100%: Seed finalizado.'); $this->info('Total execution time in seconds: ' . (microtime(true) - $time_start)); } else { $this->info('Solo se puede realizar esta tarea en modo local.'); } }
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 static function form_input($i, $data_type, $field, $extras, $array_parameters = []) { $name = $field['name']; $type = $field['type']; if ($type == 'date') { $type = 'string'; } else { if ($type == 'relation') { $type = 'select'; } else { if ($type == 'field' && $field['multiple'] == false) { $type = 'radio'; } else { if ($type == 'field' && $field['multiple'] == true) { $type = 'checkbox'; } } } } $subinput = false; $fixed_name = str_replace('[]', '', $name); $required = false; if (isset($field['required'])) { $required = $field['required']; } $parameters = []; if ($type == 'select' || $type == 'checkbox' || $type == 'radio') { $parameters['options'] = $field['options']; if ($type == 'select' && !$required) { $parameters['options'] = ['' => ' '] + $parameters['options']; } } // CLASS $class = 'form-control input-lg" '; if (array_key_exists('class', $extras)) { $class .= $extras['class']; } // FIELD CLASS $field_class = 'flex-item '; if (array_key_exists('field_class', $extras)) { $field_class .= $extras['field_class']; } if ($type == 'title') { $field_class .= ' title'; } $parameters['field_class'] = $field_class; // COL $col = 6; if (array_key_exists('cols', $extras)) { $col = $extras['cols']; } // PARAMETERS ARRAY $array = ['class' => $class, 'id' => $name]; if ($array_parameters) { $array = $array + $array_parameters; } // LABEL if (array_key_exists('label', $extras)) { $label = $extras['label']; } else { if (isset($field['final_label'])) { $label = $field['final_label']; } else { $label = trans('fields.' . str_replace('_id', '', $fixed_name)); } } if ($required == true) { $label .= ' (*)'; } if (isset($field['tooltip']) && $field['tooltip']) { if ($data_type == 'view') { //$label .= '<div class="tooltip-mini">'.trans('tooltips.'.$fixed_name).'</div>'; } else { $label .= ' <a href="#" class="help" title="' . trans('tooltips.' . $fixed_name) . '"><i class="fa fa-question-circle"></i></a>'; } } if (isset($field['filter'])) { $label .= ' <a href="' . url('admin/delete-filter/' . $field['filter']) . '" onclick="return confirm(\'' . trans('admin.delete_confirmation') . '\');">( X )</a>'; } if (isset($field['message']) && $field['message']) { $label .= '<div class="field-message">' . $field['message'] . '</div>'; } // VALUE $value = NULL; if ($i && ($i->{$fixed_name} || $i->{$fixed_name} === 0)) { $value = $i->{$fixed_name}; } else { if (request()->has($fixed_name)) { $value = request()->input($fixed_name); } else { if (array_key_exists('value', $extras)) { $value = $extras['value']; } } } if ($type == 'password') { $value = NULL; } else { if (($type == 'array' || $type == 'checkbox') && $value && is_string($value)) { $value = json_decode($value, true); } } // SUBINPUT if (array_key_exists('subtype', $extras)) { $subinput = $extras['subtype']; $array['rel'] = $extras['subinput'] . '_' . $name; $fixed_name = $extras['subinput'] . '_' . $name; $name = $extras['subinput'] . '_' . $name . '[' . $extras['subcount'] . ']'; if ($type == 'string' || $type == 'text') { $array['class'] = $array['class'] . ' text-control'; } else { if ($type == 'hidden') { $array['class'] = $array['class'] . ' hidden-control'; } } } // FILAS if (array_key_exists('rows', $extras)) { $array['rows'] = $extras['rows']; } // IMAGENES if ($type == 'file' || $type == 'image') { $array['class'] = $array['class'] . ' fileupload'; $array['data-type'] = $type; $array['data-folder'] = $extras['folder']; $parameters['folder'] = $extras['folder']; $parameters['i'] = $i; if (!$value) { $value = request()->old($fixed_name); } if ($field['multiple']) { $array['data-multiple'] = '1'; $array['multiple'] = true; } else { $array['data-multiple'] = '0'; } } // CAMPOS PREDEFINIDOS if (isset($field['preset']) && $field['preset'] == true || $data_type == 'view' || $extras && array_key_exists('disabled', $extras)) { $array['disabled'] = true; } // PLACEHOLDER if ($extras && isset($extras['placeholder'])) { $array['placeholder'] = $extras['placeholder']; } // CUSTOM FIELD CORRECTIONS $array = \CustomFunc::custom_field($array, $parameters, $type); // RESPONSE if ($subinput == 'multiple') { $response = Field::form_input_builder($name, $type, $parameters, $array, $value, $data_type); if (\Session::has('errors') && \Session::get('errors')->default->first($name)) { $response .= '<div class="error">' . \Session::get('errors')->default->first($name) . '</div>'; } } else { if ($type == 'checkbox' || $type == 'radio' || $type == 'score') { $response = Field::form_checkbox_builder($name, $type, $parameters, $label, $col, $i, $value, $data_type); } else { if ($type == 'hidden') { $response = Field::form_input_builder($name, $type, $parameters, $array, $value, $data_type); } else { $response = Field::form_field_builder($name, $type, $parameters, $array, $label, $col, $i, $value, $data_type); } } } return $response; }
public static function get_request($single_model, $action, $id, $data, $options = [], $additional_vars = NULL) { $node = \Solunes\Master\App\Node::where('name', $single_model)->first(); $model = \FuncNode::node_check_model($node); if (\Gate::denies('node-admin', ['item', $data->module, $node, $action, $id])) { return \Login::redirect_dashboard('no_permission'); } if ($action == 'delete' || $action == 'restore') { if ($node->soft_delete == 1) { $item = $model->withTrashed()->where('id', $id)->first(); } else { $item = $model->find($id); } if ($item) { if ($node->soft_delete == 0 && $action == 'delete') { $file_fields = $node->fields()->whereIn('type', ['image', 'file'])->get(); \Asset::delete_saved_files($file_fields, $item); if (count($node->children) > 0) { foreach ($node->children as $child) { $child_name = $child->table_name; $file_fields = $child->fields()->whereIn('type', ['image', 'file'])->get(); if (is_object($item->{$child_name}) && count($item->{$child_name}) > 0) { foreach ($item->{$child_name} as $item_child) { \Asset::delete_saved_files($file_fields, $item_child); } } else { \Asset::delete_saved_files($file_fields, $item->{$child_name}); } } } } $item->{$action}(); return redirect($data->prev)->with('message_success', trans('admin.' . $action . '_success')); } else { return redirect($data->prev)->with('message_fail', trans('admin.' . $action . '_fail')); } } else { $variables = \AdminItem::get_request_variables($data->module, $node, $model, $single_model, $action, $id, $options, $additional_vars); $view = 'master::item.model'; if ($variables['preset_field'] === true) { if ($node->name == 'indicator') { if (\View::exists('includes.select-parent-indicator')) { $view = 'includes.select-parent-indicator'; } else { $view = 'master::includes.select-parent-indicator'; } } else { $view = 'master::includes.select-parent'; } } else { if ($node->customized) { $custom_location = 'item.'; if ($node->name == 'indicator') { $custom_location = 'master::' . $custom_location; } $view = $custom_location . $single_model; } } if (request()->has('download-pdf')) { $variables['pdf'] = true; $variables['dt'] = 'view'; $variables['header_title'] = \CustomFunc::custom_pdf_header($node, $id); $variables['title'] = 'Formulario de ' . $node->singular; $variables['site'] = \Solunes\Master\App\Site::find(1); $pdf = \PDF::loadView($view, $variables); $header = \View::make('pdf.header', $variables); return $pdf->setPaper('letter')->setOption('header-html', $header->render())->stream($node->singular . '_' . date('Y-m-d') . '.pdf'); } else { return view($view, $variables); } } }
<?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_node_items($sub_array, $node, $admin = false) { $model = $node->model; if ($admin === true) { if (request()->has($node->table_name)) { $action = 'edit'; $id = request()->input($node->table_name); } else { $action = 'create'; $id = NULL; } $sub_array = \AdminItem::get_request_variables('process', $node, $model, $node->name, $action, $id, []); } else { $items = $model::whereNotNull('id'); $sub_array = \AdminList::filter_node([], $node, $model, $items, 'site'); $items = $sub_array['items']; $children = $node->children()->where('type', '!=', 'field')->get(); if (count($children) > 0) { foreach ($children as $child) { $items = $items->with($child->table_name); if ($child->name == 'location') { $items = $items->with('locations.parent.member', 'locations.parent.project_sector'); } } } $node_requests = $node->node_requests; if (count($node_requests) > 0) { $paginate = 0; foreach ($node_requests as $req) { $req_action = $req->action; $req_col = $req->col; $req_value = $req->value; if ($req_action == 'customRequest') { $items = \CustomFunc::custom_node_request($node, $items, $req_col, $req_value); } else { if ($req->value_type == 'relation') { if ($req_value == 'node_pivot_id') { $req_value = $node->pivot->id; } } else { if ($req_action == 'whereIn' || $req_action == 'with' || $req_action == 'has') { $req_value = explode(';', $req_value); } } } if ($req_action == 'whereNot') { $items = $items->where($req_col, '!=', $req_value); } else { if ($req_action == 'where' || $req_action == 'whereIn' || $req_action == 'orderBy') { $items = $items->{$req_action}($req_col, $req_value); } else { if ($req_action == 'with' || $req_action == 'has') { $items = $items->{$req_action}($req_value); } else { if ($req_action == 'whereNull' || $req_action == 'whereNotNull') { $items = $items->{$req_action}($req_col); } } } } if ($req_action == 'paginate') { $paginate = $req_value; } } if ($paginate > 0) { $sub_array['items'] = $items->paginate($paginate); } else { $sub_array['items'] = $items->get(); } } else { $sub_array['items'] = $items->get(); } } return $sub_array; }
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; }