/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { //validate request $this->validate($request, ['name' => 'required|min:5', 'gender' => 'required', 'alignment' => 'required']); $character = new Character(); foreach (\Request::all() as $key => $value) { switch ($key) { case '_token': break; case '_method': break; case 'labels': break; case 'values': break; case 'birthdate': $date = \Carbon\Carbon::parse($value); $character->birthdate = $date->toDateString(); break; default: $character->{$key} = $value; } } $labels = $request->get('labels'); $values = $request->get('values'); //Construct the json array for stats foreach ($labels as $key => $value) { $stats[$value] = $values[$key]; } $character->stats = json_encode($stats); // $content = str_ireplace('\r\n', '<br />', $request->get('notes')); if ($request->has('image')) { foreach ($request->files as $file) { $ext = $file->getClientOriginalExtension(); $name = sha1($file->getClientOriginalName()); $file->move(storage_path() . '/app/uploads/campaign_' . \Session::get('campaign')->id, $name . '.' . $ext); $character->image = \URL::to('/images/' . \Session::get('campaign')->id . '/' . $name . '.' . $ext); } } $character->save(); //Create the relationship with the Campaign $relationship = new Relationship(); $relationship->campaign_id = \Session::get('campaign')->id; $relationship->source_type = 'App\\Campaign'; $relationship->source_id = \Session::get('campaign')->id; $relationship->sibling_type = 'App\\Character'; $relationship->sibling_id = $character->id; $relationship->save(); return redirect(action('CharactersController@index')); }
/** * Update the specified resource in storage. * * @param Request $request * @param int $id * @return Response */ public function update(RelationshipsRequest $request) { $relationship = Relationship::where('id', $request['relationshipID'])->first(); $relationship->name = $request['name']; $relationship->updated_by = \Auth::user()->id; $relationship->save(); \Session::flash('success', $request['name'] . ' has been successfully updated!'); return redirect()->back(); }
/** * Run the database seeds. * * @return void */ public function run() { //Assign th objects to the campaign Relationship::create(['campaign_id' => 1, 'source_type' => 'App\\Campaign', 'source_id' => 1, 'sibling_type' => 'App\\Character', 'sibling_id' => '1']); Relationship::create(['campaign_id' => 1, 'source_type' => 'App\\Campaign', 'source_id' => 1, 'sibling_type' => 'App\\Character', 'sibling_id' => 2]); Relationship::create(['campaign_id' => 1, 'source_type' => 'App\\Campaign', 'source_id' => 1, 'sibling_type' => 'App\\Weapon', 'sibling_id' => 1]); Relationship::create(['campaign_id' => 1, 'source_type' => 'App\\Campaign', 'source_id' => 1, 'sibling_type' => 'App\\Person', 'sibling_id' => 1]); //Relate objects to each other Relationship::create(['campaign_id' => 1, 'source_type' => 'App\\Weapon', 'source_id' => 1, 'sibling_type' => 'App\\Character', 'sibling_id' => '1']); Relationship::create(['campaign_id' => 1, 'source_type' => 'App\\Character', 'source_id' => 1, 'sibling_type' => 'App\\Person', 'sibling_id' => 1]); Relationship::create(['campaign_id' => 1, 'source_type' => 'App\\Character', 'source_id' => 1, 'sibling_type' => 'App\\Character', 'sibling_id' => 2]); }
/** * Bootstrap any application services. * * @return void */ public function boot() { if (\Schema::hasTable('positions')) { $positions = Position::all(); $selectPositions = array(); $selectPositions[0] = "Select / All"; foreach ($positions as $position) { $selectPositions[$position->slug] = $position->name; } \View::share('selectPositions', $selectPositions); } if (\Schema::hasTable('cases_priorities')) { $priorities = CasePriority::all(); $selectPriorities = array(); $selectPriorities[0] = "Select / All"; foreach ($priorities as $priority) { $selectPriorities[$priority->slug] = $priority->name; } \View::share('selectPriorities', $selectPriorities); } if (\Schema::hasTable('titles')) { $titles = Title::all(); $selectTitles = array(); $selectTitles[0] = "Select / All"; foreach ($titles as $title) { $selectTitles[$title->slug] = $title->name; } \View::share('selectTitles', $selectTitles); } if (\Schema::hasTable('languages')) { $languages = Language::all(); $selectLanguages = array(); $selectLanguages[0] = "Select / All"; foreach ($languages as $language) { $selectLanguages[$language->slug] = $language->name; } \View::share('selectLanguages', $selectLanguages); } if (\Schema::hasTable('departments')) { $departments = Department::all(); $selectDepartments = array(); $selectDepartments[0] = "Select / All"; foreach ($departments as $department) { $selectDepartments[$department->slug] = $department->name; } \View::share('selectDepartments', $selectDepartments); } if (\Schema::hasTable('users_roles')) { $roles = UserRole::all(); $selectRoles = array(); $selectRoles[0] = "Select / All"; foreach ($roles as $role) { $selectRoles[$role->slug] = $role->name; } \View::share('selectRoles', $selectRoles); } if (\Schema::hasTable('provinces')) { $provinces = Province::all(); $selectProvinces = array(); $selectProvinces[0] = "Select / All"; foreach ($provinces as $Province) { $selectProvinces[$Province->slug] = $Province->name; } \View::share('selectProvinces', $selectProvinces); } if (\Schema::hasTable('districts')) { $districts = District::all(); $selectDistrict = array(); $selectDistricts[0] = "Select / All"; foreach ($districts as $district) { $selectDistricts[$district->slug] = $district->name; } \View::share('selectDistricts', $selectDistricts); } if (\Schema::hasTable('municipalities')) { $municipalities = Municipality::all(); $selectMunicipalities = array(); $selectMunicipalities[0] = "Select / All"; foreach ($municipalities as $municipality) { $selectMunicipalities[$municipality->slug] = $municipality->name; } \View::share('selectMunicipalities', $selectMunicipalities); } if (\Schema::hasTable('wards')) { $wards = Ward::all(); $selectWards = array(); $selectWards[0] = "Select / All"; foreach ($wards as $ward) { $selectWards[$ward->slug] = $ward->name; } \View::share('selectWards', $selectWards); } if (\Schema::hasTable('categories')) { $categories = Category::all(); $selectCategories = array(); $selectCategories[0] = "Select / All"; foreach ($categories as $category) { $selectCategories[$category->slug] = $category->name; } \View::share('selectCategories', $selectCategories); } if (\Schema::hasTable('sub_categories')) { $subCategories = SubCategory::all(); $selectSubCategories = array(); $selectSubCategories[0] = "Select / All"; foreach ($subCategories as $subCategory) { $selectSubCategories[$subCategory->slug] = $subCategory->name; } \View::share('selectSubCategories', $selectSubCategories); } if (\Schema::hasTable('sub_sub_categories')) { $subSubCategories = SubSubCategory::all(); $selectSubSubCategories = array(); $selectSubSubCategories[0] = "Select / All"; foreach ($subSubCategories as $subSubCategory) { $selectSubSubCategories[$subSubCategory->slug] = $subSubCategory->name; } \View::share('selectSubSubCategories', $selectSubSubCategories); } if (\Schema::hasTable('relationships')) { $relationships = Relationship::all(); $selectRelationships = array(); $selectRelationships[0] = "Select / All"; foreach ($relationships as $relationship) { $selectRelationships[$relationship->id] = $relationship->name; } \View::share('selectRelationships', $selectRelationships); } if (\Schema::hasTable('cases')) { $cases = \DB::table('cases')->join('users', 'cases.reporter', '=', 'users.id')->select(\DB::raw("\n IF(`cases`.`addressbook` = 1,(SELECT CONCAT(`first_name`, ' ', `surname`) FROM `addressbook` WHERE `addressbook`.`id`= `cases`.`reporter`), (SELECT CONCAT(users.`name`, ' ', users.`surname`) FROM `users` WHERE `users`.`id`= `cases`.`reporter`)) as reporterName\n\n "))->get(); $reporters = array(); $reporters[0] = "Select / All"; foreach ($cases as $case) { $reporters[$case->reporterName] = $case->reporterName; } \View::share('selectReporters', $reporters); } View()->composer('master', function ($view) { $view->with('addressBookNumber', addressbook::all()); if (\Auth::check()) { $number = addressbook::where('user', '=', \Auth::user()->id)->get(); $view->with('addressBookNumber', $number); $allUsers = User::where('id', '<>', \Auth::user()->id)->get(); $view->with('loggedInUsers', $allUsers); $noPrivateMessages = Message::where('to', '=', \Auth::user()->id)->where('read', '=', 0)->where('message_type', '=', 0)->get(); $view->with('noPrivateMessages', $noPrivateMessages); $noInboxMessages = Message::where('to', '=', \Auth::user()->id)->where('message_type', '=', 0)->get(); $view->with('noInboxMessages', $noInboxMessages); $noDepartments = Department::all(); $view->with('noDepartments', $noDepartments); $noUsers = User::all(); $view->with('noUsers', $noUsers); $noRoles = UserRole::all(); $view->with('noRoles', $noRoles); $noPositions = Position::all(); $view->with('noPositions', $noPositions); $noRelationships = Relationship::all(); $view->with('noRelationships', $noRelationships); $noProvinces = Province::all(); $view->with('noProvinces', $noProvinces); $noCaseStatuses = CaseStatus::all(); $view->with('noCaseStatuses', $noCaseStatuses); $userRole = UserRole::where('id', '=', \Auth::user()->role)->first(); $view->with('systemRole', $userRole); $noCasesPriorities = CasePriority::all(); $view->with('noCasesPriorities', $noCasesPriorities); } }); }
public function addCampaignMembership() { $relationship = new Relationship(); $relationship->source_type = 'App\\Campaign'; $relationship->source_id = \Session::get('campaign')->id; $relationship->sibling_type = $this->referenceClass; $relationship->sibling_id = $this->id; try { $relationship->save(); } catch (Exception $e) { \Log::error('Could not register ' . $this->referenceClass . ': ' . $this->id . ' with campaign ' . \Session::get('campaign')->id . ': Error message is ' . $e->getMessage()); } }
/** * Bootstrap any application services. * * @return void */ public function boot() { if (\Schema::hasTable('positions')) { $positions = Position::orderBy('name', 'ASC')->get(); $selectPositions = array(); $selectPositions[0] = "Select / All"; foreach ($positions as $position) { $selectPositions[$position->slug] = $position->name; } \View::share('selectPositions', $selectPositions); } if (\Schema::hasTable('departments')) { $departments = Department::orderBy('name', 'ASC')->get(); $selectDepartments = array(); $selectDepartments[0] = "Select / All"; foreach ($departments as $department) { $selectDepartments[$department->slug] = $department->name; } \View::share('selectDepartments', $selectDepartments); } if (\Schema::hasTable('provinces')) { $provinces = Province::all(); $selectProvinces = array(); $selectProvinces[0] = "Select / All"; foreach ($provinces as $Province) { $selectProvinces[$Province->slug] = $Province->name; } \View::share('selectProvinces', $selectProvinces); } if (\Schema::hasTable('districts')) { $districts = District::all(); $selectDistrict = array(); $selectDistricts[0] = "Select / All"; foreach ($districts as $district) { $selectDistricts[$district->slug] = $district->name; } \View::share('selectDistricts', $selectDistricts); } if (\Schema::hasTable('municipalities')) { $municipalities = Municipality::all(); $selectMunicipalities = array(); $selectMunicipalities[0] = "Select / All"; foreach ($municipalities as $municipality) { $selectMunicipalities[$municipality->slug] = $municipality->name; } \View::share('selectMunicipalities', $selectMunicipalities); } if (\Schema::hasTable('categories')) { $categories = Category::all(); $selectCategories = array(); $selectCategories[0] = "Select / All"; foreach ($categories as $category) { $selectCategories[$category->slug] = $category->name; } \View::share('selectCategories', $selectCategories); } if (\Schema::hasTable('sub-categories')) { $subCategories = SubCategory::all(); $selectSubCategories = array(); $selectSubCategories[0] = "Select / All"; foreach ($subCategories as $subCategory) { $selectSubCategories[$subCategory->slug] = $subCategory->name; } \View::share('selectSubCategories', $selectSubCategories); } if (\Schema::hasTable('sub-sub-categories')) { $subSubCategories = SubSubCategory::all(); $selectSubSubCategories = array(); $selectSubSubCategories[0] = "Select / All"; foreach ($subSubCategories as $subSubCategory) { $selectSubSubCategories[$subSubCategory->slug] = $subSubCategory->name; } \View::share('selectSubSubCategories', $selectSubSubCategories); } if (\Schema::hasTable('relationships')) { $relationships = Relationship::all(); $selectRelationships = array(); $selectRelationships[0] = "Select / All"; foreach ($relationships as $relationship) { $selectRelationships[$relationship->id] = $relationship->name; } \View::share('selectRelationships', $selectRelationships); } if (\Schema::hasTable('cases')) { $cases = \DB::table('cases')->join('users', 'cases.reporter', '=', 'users.id')->select(\DB::raw("\n IF(`cases`.`addressbook` = 1,(SELECT CONCAT(`FirstName`, ' ', `Surname`) FROM `addressbook` WHERE `addressbook`.`id`= `cases`.`reporter`), (SELECT CONCAT(users.`name`, ' ', users.`surname`) FROM `users` WHERE `users`.`id`= `cases`.`reporter`)) as reporterName\n\n "))->get(); $reporters = array(); $reporters[0] = "Select / All"; foreach ($cases as $case) { $reporters[$case->reporterName] = $case->reporterName; } \View::share('selectReporters', $reporters); } View()->composer('master', function ($view) { $view->with('addressBookNumber', addressbook::all()); if (\Auth::check()) { $number = addressbook::where('user', '=', \Auth::user()->id)->get(); $view->with('addressBookNumber', $number); $allUsers = User::where('id', '<>', \Auth::user()->id)->get(); $view->with('loggedInUsers', $allUsers); $noPrivateMessages = Message::where('to', '=', \Auth::user()->id)->where('read', '=', 0)->where('online', '=', 0)->get(); $view->with('noPrivateMessages', $noPrivateMessages); $noInboxMessages = Message::where('to', '=', \Auth::user()->id)->where('online', '=', 0)->get(); $view->with('noInboxMessages', $noInboxMessages); } }); }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update(Request $request) { // try { $relationship_debug = "None"; if ($request->ajax()) { DB::beginTransaction(); $Person_id = Input::get('person_id'); // keep the doctor profile $Doctor_id = DB::table('doctors')->where('doctor_id', Input::get('doctor_id'))->update(['doctor_name' => Input::get('doctor_name'), 'doctor_mobile_phone' => Input::get('doctor_mobilephonenumber'), 'doctor_phone' => Input::get('doctor_phonenumber'), 'hospital' => Input::get('hospital_name'), 'doctor_care_date' => Input::get('doctor_care_date'), 'email' => Input::get('doctor_email')]); // insert information record $symptom_checkbox_10 = Input::get('10_symptom_checkbox'); DB::table('disease_1')->where('questions_id', Input::get('question_id'))->update(['symptom_1_1' => Input::get('1_1_symptom'), 'symptom_1_2' => Input::get('1_2_symptom'), 'symptom_1_3' => Input::get('1_3_symptom'), 'symptom_2' => Input::get('2_symptom_age'), 'symptom_3' => Input::get('3_symptom_age'), 'symptom_4_1' => Input::get('4_1_symptom'), 'symptom_4_2' => Input::get('4_2_symptom'), 'symptom_4_3' => Input::get('4_2_symptom'), 'symptom_4_4' => Input::get('4_4_symptom'), 'symptom_5' => Input::get('5_symptom'), 'symptom_5_date' => Input::get('5_2_symptom_add_on_result_date'), 'symptom_5_result' => Input::get('5_2_symptom_add_on_result'), 'symptom_6' => Input::get('6_symptom'), 'symptom_6_date' => Input::get('6_2_symptom_add_on_result_date'), 'symptom_6_result' => Input::get('6_2_symptom_add_on_result'), 'symptom_7_1' => Input::get('7_1_symptom'), 'symptom_7_1_result' => Input::get('7_1_symptom_result'), 'symptom_7_2' => Input::get('7_2_symptom'), 'symptom_7_2_result' => Input::get('7_2_symptom_result'), 'symptom_7_3' => Input::get('7_3_symptom'), 'symptom_7_3_result' => Input::get('7_3_symptom_result'), 'symptom_8' => Input::get('8_1_symptom'), 'symptom_9_male' => Input::get('9_male_number'), 'symptom_9_female' => Input::get('9_female_number'), 'symptom_10_2_male' => Input::get('10_2_male_number'), 'symptom_10_2_female' => Input::get('10_2_female_number'), 'symptom_10_1' => Input::get('10_symptom'), 'symptom_10_1_number' => Input::get('10_symptom_number'), 'symptom_10_1_check' => $symptom_checkbox_10]); $sym_10_name = json_decode(stripslashes(Input::get('vpb_item_name'))); $sym_10_age = json_decode(stripslashes(Input::get('vpb_item_ages'))); $sym_10_citizen_number = json_decode(stripslashes(Input::get('vpb_item_ids'))); $sym_10_roles = json_decode(stripslashes(Input::get('vpb_item_roles'))); if ($symptom_checkbox_10 != "ไม่รู้" || $symptom_checkbox_10 == null || !isset($symptom_checkbox_10)) { $relationship_debug = "เข้ามาเเล้ส"; for ($i = 0; $i < sizeof($sym_10_name); $i++) { $relationship_debug = "เข้ามาเเล้ส 1"; if ($sym_10_name[$i] != ' ' && $sym_10_name[$i] != null) { $name = explode(" ", $sym_10_name[$i]); $user = Persons::firstOrNew(array('person_first_name' => $name[0], 'person_last_name' => $name[1])); $user->person_first_name = $name[0]; $user->person_last_name = $name[1]; $user->person_age = $sym_10_age[$i]; $user->person_citizenID = $sym_10_citizen_number[$i]; $user->person_sex = 'male'; $user->save(); $relative_person_id = $user->person_id; /*$relative_person_id = DB::table('persons')->insertGetId( ['person_first_name' => $name[0], 'person_last_name' => $name[1], 'person_age' => $sym_10_age[$i],'person_citizenID' => $sym_10_citizen_number[$i], 'person_sex' => 'male' ]);*/ $relationship = Relationship::where('person_1_id', '=', $Person_id)->where('person_2_id', '=', $relative_person_id)->first(); if ($relationship->exists) { $relationship_debug = "เข้ามาเเล้ส 2"; $relationship->role_1_id = $this->check_my_role($sym_10_roles[$i], $Person_id); $relationship->role_2_id = $this->check_role($sym_10_roles[$i]); $relationship->relationship_type_id = $this->check_my_relationship($sym_10_roles[$i]); $relationship->save(); } else { $relationship = Relationship::where('person_2_id', '=', $Person_id)->where('person_1_id', '=', $relative_person_id)->first(); if ($relationship->exists) { $relationship_debug = "เข้ามาเเล้ส 3"; $relationship->role_2_id = $this->check_my_role($sym_10_roles[$i], $Person_id); $relationship->role_1_id = $this->check_role($sym_10_roles[$i]); $relationship->relationship_type_id = $this->check_my_relationship($sym_10_roles[$i]); $relationship->save(); } else { $relationship_debug = "เข้ามาเเล้ส 4"; //add data into patient, doctor , and question table $relative_doctor_id = DB::table('doctors')->insertGetId(['doctor_name' => "ไม่ทราบ", 'doctor_mobile_phone' => "ไม่ทราบ", 'doctor_phone' => "ไม่ทราบ", 'hospital' => "ไม่ทราบ", 'doctor_care_date' => "", 'email' => "ไม่ทราบ"]); $relative_patient_id = DB::table('patients')->insertGetId(['doctor_id' => $relative_doctor_id, 'person_id' => $relative_person_id, 'registration_date' => date('Y-m-d')]); //In future, if our system support many disease types , we need to change where on disease_type_name_en to id $relative_disease_types = DB::table('disease_types')->where('disease_type_name_en', StaticArray::$diseases['DMD'])->first(); // register disease type with question table $relative_disease_form_id = DB::table('disease_forms')->insertGetId(['disease_type_id' => $relative_disease_types->disease_type_id]); DB::table('patients_disease_forms')->insert(['patient_id' => $relative_patient_id, 'question_id' => $relative_disease_form_id, 'registration_date' => date('Y-m-d')]); DB::table('disease_1')->insert(['questions_id' => $relative_disease_form_id]); DB::table('relationship')->insert(['person_1_id' => $Person_id, 'person_2_id' => $relative_person_id, 'role_1_id' => $this->check_my_role($sym_10_roles[$i], $Person_id), 'role_2_id' => $this->check_role($sym_10_roles[$i]), 'relationship_type_id' => $this->check_my_relationship($sym_10_roles[$i])]); } } } } } DB::commit(); return response()->json(array('status' => 'Complete', 'message' => 'บันทึกสำเร็จ '), 200); } return response()->json(array('status' => 'Error', 'message' => 'มาได้ยังไง '), 200); } catch (Exception $e) { DB::rollback(); if ($e->getCode() == 23000) { $result['status'] = "Error"; $result['message'] = "Duplicate Record"; return response()->json($result, 200); } else { $result['status'] = 2; $result['message'] = $e->getMessage(); return response()->json($result, 200); } } }
/** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { $patient = Patient::find($id); $dataToSave = $patient->company_id; if ($patient->type === "Carga") { $relation = Relationship::where('burden', $id)->first(); $dataToSave = $relation->incumbent; } return view('patients.edit', compact('patient', 'dataToSave')); }