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