public function delete_seek($id) { if (Auth::User()->role == 2) { $training = SeekTraining::find($id); if ($training == null) { return redirect('/'); } else { $training->delete(); return redirect('/'); } } else { return redirect('/'); } }
public function search_statistic($field_id) { $trainings = SeekTraining::all(); $training_array = array(); foreach ($trainings as &$training) { foreach ($training->fields as $field) { if ($field->id == $field_id) { $training->municipalities; $training['region'] = Region::where('id', '=', $training->municipalities[0]->region_id)->get(); $training_array[] = $training; } } } $country_array = array('quantity' => 0); $regions_array = array(); $regions_id_array = array(); foreach ($training_array as $training) { $country_array['quantity'] += $training['quantity']; if (!in_array($training['region'][0]['id'], $regions_id_array)) { $regions_id_array[] = $training['region'][0]['id']; $regions_array[$training['region'][0]['id']] = array('name' => $training['region'][0]['name'], 'quantity' => $training['quantity']); } else { $regions_array[$training['region'][0]['id']]['quantity'] += $training['quantity']; } } $municipalities_array = array(); $municipalities_id_array = array(); foreach ($training_array as $training) { if (!in_array($training['municipalities'][0]['id'], $municipalities_id_array)) { $municipalities_id_array[] = $training['municipalities'][0]['id']; $municipalities_array[$training['municipalities'][0]['id']] = array('name' => $training['municipalities'][0]['name'], 'quantity' => $training['quantity']); } else { $municipalities_array[$training['municipalities'][0]['id']]['quantity'] += $training['quantity']; } } return json_encode(['regions' => $regions_array, 'municipalities' => $municipalities_array, 'country' => $country_array]); }
public function save_seek_announcement(Request $request) { if (!Auth::user() || Auth::user()->role != 2) { return redirect('/'); } $rules = array('term' => 'required', 'field' => 'required', 'region' => 'required'); $messages = array('term.required' => 'სწავლების ფორმა სავალდებულოა', 'field.required' => 'სწავლების სფერო სავალდებულოა', 'region.required' => 'ჩატარების ადგილი სავალდებულოა'); $input = input::all(); $file = Input::file('file'); if (isset($file) && !empty($file)) { $extension = $file->getClientOriginalExtension(); if ($extension != 'pdf') { $rules['pdf'] = 'required'; $messages['pdf.required'] = 'დასაშვებია მხოლოდ pdf გაფართოების ფაილები'; } } $this->validate($request, $rules, $messages); if (isset($file) && !empty($file)) { $file_name = str_random(10) . '.' . $file->getClientOriginalExtension(); $destinationPath = 'training_pdf'; $file->move($destinationPath, $file_name); $input['file'] = $file_name; } $training_to_delete = SeekTraining::find(input::get('id')); $training_to_delete->delete(); $training = SeekTraining::create($input); foreach (input::get('term') as $term) { $training->terms()->attach($term); } $training->fields()->attach(input::get('field')); $training->municipalities()->attach(input::get('municipalities')); $training->save(); return redirect('/'); }
public function get_seek_announcements(Request $request) { $field_search = input::get('field'); $term_search = input::get('term'); $region_search = input::get('region'); $municipalities_search = input::get('municipalities'); if ($field_search == '0' || empty($field_search)) { $fields_all = Field::all(['id']); foreach ($fields_all as $field) { $fields[] = $field->id; } } else { $fields[] = $field_search; } if ($term_search == '0' || empty($term_search)) { $terms_all = Term::all(['id']); foreach ($terms_all as $term) { $terms[] = $term->id; } } else { $terms[] = $term_search; } if ($municipalities_search[0] == '0' || empty($municipalities_search)) { if ($region_search != '0' && !empty($region_search)) { $any_municipality = Region::find($region_search)->get_municipalities()->get(); } else { $any_municipality = Municipality::all(['id']); } foreach ($any_municipality as $instance) { $municipality_id[] = $instance->id; } } else { $municipality_id = $municipalities_search; } $select = DB::select(' SELECT seek_trainings.id, field_seek_training.field_id, municipality_seek_training.municipality_id FROM seek_trainings JOIN field_seek_training ON seek_trainings.id = field_seek_training.seek_training_id JOIN municipality_seek_training ON seek_trainings.id = municipality_seek_training.seek_training_id WHERE field_seek_training.field_id in(' . implode(',', $fields) . ') AND municipality_seek_training.municipality_id in (' . implode(',', $municipality_id) . ') group by seek_trainings.id '); foreach ($select as $instance) { $seek_training_filtered = new \stdClass(); $seek_training_instance = SeekTraining::find($instance->id); $seek_training_field = Field::find($instance->field_id); $seek_training_municipality = Municipality::find($instance->municipality_id); $training_terms = DB::select('SELECT terms.name FROM seek_training_term JOIN terms ON terms.id = seek_training_term.term_id WHERE seek_training_id = ' . $instance->id); $seek_training_terms_array = []; foreach ($training_terms as $term) { $seek_training_terms_array[] = $term->name; } $seek_training_filtered->id = $seek_training_instance->id; $seek_training_filtered->header = $seek_training_instance->name; $seek_training_filtered->description = $seek_training_instance->description; $seek_training_filtered->file = $seek_training_instance->file; $seek_training_filtered->link = $seek_training_instance->link; $seek_training_filtered->per = $seek_training_instance->per; $seek_training_filtered->terms = implode(',', $seek_training_terms_array); $seek_training_filtered->contact = $seek_training_instance->contact; $seek_training_filtered->quantity = $seek_training_instance->quantity; $seek_training_filtered->field = $seek_training_field->name; $seek_training_filtered->municipality = $seek_training_municipality->name; $seek_training_filtered->isAdmin = !(!Auth::user() || Auth::user()->role == 100); $seek_training_filtered_array[] = $seek_training_filtered; unset($seek_training_filtered); unset($seek_training_months_array); unset($seek_training_terms_array); } return response(json_encode($seek_training_filtered_array), 200)->header('Content-Type', 'application/json'); }