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;
 }
Ejemplo n.º 2
0
 public static function form_checkbox_builder($name, $type, $parameters, $label, $col, $i, $value, $data_type)
 {
     $array = [];
     if ($data_type == 'view') {
         $array = ['disabled' => true];
     }
     if ($type == 'score' || $type == 'main_score') {
         $option_array = ['1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5'];
     } else {
         $option_array = $parameters['options'];
     }
     $response = '<div id="field_' . $name . '" class="col-sm-' . $col . ' ' . $parameters['field_class'] . '">';
     $response .= '<label for="' . $name . '" class="control-label">' . $label . '</label>';
     if ($type == 'checkbox') {
         $response .= '<div class="mt-checkbox-inline">';
     } else {
         $response .= '<div class="mt-radio-inline">';
     }
     foreach ($option_array as $key => $option) {
         $array['class'] = 'field_' . $name . ' option_' . $key;
         if ($type == 'radio' || $type == 'score' || $type == 'main_score') {
             $response .= '<label class="mt-radio">' . $option . ' ' . Form::radio($name, $key, AdminItem::make_radio_value($key, $value), $array);
         } else {
             if ($type == 'checkbox') {
                 $response .= '<label class="mt-checkbox">' . $option . ' ' . Form::checkbox($name . '[]', $key, AdminItem::make_checkbox_value($key, $value), $array);
             }
         }
         $response .= '<span></span></label>';
     }
     if (\Session::has('errors') && \Session::get('errors')->default->first($name)) {
         $response .= '<div class="error col-sm-12">' . \Session::get('errors')->default->first($name) . '</div>';
     }
     if ($data_type == 'editor') {
         $response .= \Field::generate_editor_fields($name);
     }
     $response .= '</div></div>';
     return $response;
 }
Ejemplo n.º 3
0
 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;
 }