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); } } }
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; }