public function select_schedule() { $doctor = Doctor::find(Input::get('doctor_id')); if (!isset($doctor)) { // .. } $schedules = $doctor->schedules()->with('periods')->get(); if (!isset($schedules)) { // .. } $schedules_map = array(); foreach ($schedules as $schedule) { if (!array_key_exists($schedule->date, $schedules_map)) { $schedules_map[$schedule->date] = array(); } $schedules_map[$schedule->date][$schedule->period] = array('id' => $schedule->id, 'status' => false); foreach ($schedule->periods as $period) { if ($period->current < $period->total) { $schedules_map[$schedule->date][$schedule->period]['status'] = true; break; } } } $schedules_all = array(); $date_from = 0; $date_to = 7; $current_date = date_create(); for ($i = $date_from; $i < $date_to; ++$i) { $schedules_all[$i] = array('date' => date_format(date_create('@' . strtotime('+' . $i . ' day')), 'Y-m-d')); } return View::make('register.select_schedule', array('doctor' => array('name' => $doctor->name, 'photo' => $doctor->photo, 'title' => $doctor->title, 'department' => $doctor->department->name, 'hospital' => $doctor->department->hospital->name), 'schedules' => $schedules_all, 'schedules_map' => $schedules_map)); }
protected function can_be_registered($doctor_id) { $periods = Doctor::find($doctor_id)->schedules()->with('periods')->get(); foreach ($periods as $period) { if ($period->current < $period->total) { return true; } } return false; }
public function update($id) { $data = array("first_name" => Input::get("first_name"), "last_name" => Input::get("last_name"), "email" => Input::get("email"), "phone" => Input::get("phone"), "picture" => Input::file("picture"), "specialty_id" => Input::get("specialty_id"), "dating_duration" => Input::get("dating_duration")); $rules = array("first_name" => 'required|min:1|max:255', "last_name" => 'required|min:1|max:100', "email" => 'required|min:1', "phone" => 'required|min:1|max:100', "specialty_id" => 'required|min:3|max:255', "dating_duration" => 'required|min:1|max:3', "picture" => 'mimes:jpeg,gif,png'); $messages = array('required' => 'El campo :attribute es obligatorio.', 'min' => 'El campo :attribute no puede tener menos de :min carácteres.', 'email' => 'El campo :attribute debe ser un email válido.', 'max' => 'El campo :attribute no puede tener más de :max carácteres.', 'numeric' => 'El campo :attribute debe contener solo numeros', 'mimes' => 'El formato de la imagen logo debe ser jpg, git, png'); $validation = Validator::make(Input::all(), $rules, $messages); //si la validación falla redirigimos al formulario de registro con los errores //y con los campos que nos habia llenado el usuario if ($validation->fails()) { return Redirect::to('/doctor/profile')->withErrors($validation)->withInput(); } else { $doctor = Doctor::find($id); $agenda = Agenda::where('doctor_id', $doctor->id)->first(); $agenda->dating_duration = Input::get("dating_duration"); $agenda->save(); $espes = explode(',', Input::get("specialty_id")); $espeuok = ''; foreach ($espes as $espe) { $very = Specialty::where('name_es', $espe)->first(); if ($very) { $espeuok = $espeuok . ',' . $very->id; } } $doctor->specialty_id = $espeuok; $doctor->save(); $user = User::find($doctor->user_id); $user->first_name = $data['first_name']; $user->last_name = $data['last_name']; $user->save(); $profile = Profile::where('user_id', $doctor->user_id)->first(); if (Input::file('picture') != NULL) { //agrega imagen de logo $file_logo = Input::file('picture'); $ext = Input::file('picture')->getClientOriginalExtension(); $nameIMG = date('YmdHis'); $logo = $nameIMG . '.' . $ext; $logo = 'assets/doctor/images/profile_pic/profile_' . $logo; $profile->picture = $logo; } $profile->phone = Input::get("phone"); $profile->save(); if ($profile) { if (Input::file('picture') != NULL) { $file_logo->move("assets/doctor/images/profile_pic/", $logo); } return Redirect::to('/doctor/profile')->withFlash_message("Guardado Exitosamente"); } else { return Redirect::to('/doctor/profile')->withErrors("Error")->withInput(); } } }
public function get_user_comments() { // disgusting // 怎么改进 $comments_per_page = Input::get('comments_per_page', 10); /* $records = User::find( Session::get( 'user.id' ) ) ->register_accounts()->records() ->with( 'comment' )->with( 'doctor' )->paginate( $comments_per_page ); $comments = array(); foreach ( $records as $record ){ $comment = $record->comment; $doctor = $record->doctor; $comments[] = array( 'id' => $comment->id, 'content' => $comment->content, 'created_at' => $comment->created_at, 'doctor' => array( 'id' => $doctor->id, 'name' => $doctor->name, 'photo' => $doctor->photo, 'title' => $doctor->title, 'department' => $doctor->department->name, 'hospital' => $doctor->department->hospital->name ) ); } */ $comments = Comment::select('comments.id', 'comments.content', 'comments.created_at', 'register_records.doctor_id')->join('register_records', 'comments.record_id', '=', 'register_records.id')->join('register_accounts', 'register_records.account_id', '=', 'register_accounts.id')->join('users', 'register_accounts.user_id', '=', 'users.id')->where('users.id', Session::get('user.id'))->paginate((int) $comments_per_page); if (!isset($comments)) { return Response::json(array('error_code' => 1, 'message' => '无评价记录')); } foreach ($comments as $comment) { $doctor = Doctor::find($comment['doctor_id']); // $comment['created_at'] = date_timestamp_get( date_create( $comment['created_at'] ) ); $comment['doctor'] = array('id' => $doctor->id, 'name' => $doctor->name, 'photo' => $doctor->photo, 'title' => $doctor->title, 'specialty' => strip_tags($doctor->specialty), 'department' => $doctor->department->name, 'hospital' => $doctor->department->hospital->name); unset($comment['doctor_id']); } return Response::json(array('error_code' => 0, 'total' => $comments->count(), 'comments' => $comments->getItems())); }
/** * Show the form for creating a new resource. * GET /edit/create * * @return Response */ public function DoctorSave() { $rules = ['field_id' => 'required', 'field_name' => 'required', 'field_dob' => 'required', 'field_gender' => 'required', 'field_specialty' => 'required', 'field_workingHours' => 'required', 'availabilty' => 'required']; $data = Input::all(); $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { return Redirect::back()->withErrors($validator); } else { $doctor = Doctor::find($data['field_id']); $doctor->name = Input::get('field_name'); $doctor->dob = Input::get('field_dob'); $doctor->gender = Input::get('field_gender'); $doctor->specialty = Input::get('field_specialty'); $doctor->working_hourse = Input::get('field_workingHours'); $doctor->unavailability = Input::get('availabilty'); if ($doctor->save()) { return Redirect::route('doctors_list')->with('success', 'Update Successfull'); } else { return Redirect::back()->withErrors("Something went wrong, please try again"); } } }
public function get_schedules() { $doctor = Doctor::find(Input::get('doctor_id')); if (!isset($doctor)) { return Response::json(array('error_code' => 1, 'message' => '不存在该医生')); } $schedules = $doctor->schedules()->with('periods')->get(); if (!isset($schedules)) { return Response::json(array('error_code' => 2, 'message' => '没有排班')); } $result = array(); $current_date = date_create(); $latest = (int) Input::get('latest'); $default_latest = 7; $latest = $latest >= isset($latest) ? $latest : $default_latest; foreach ($schedules as $schedule) { $sd = date_create($schedule->date); $diff = date_diff($current_date, $sd); if ($diff->d >= 0 && $diff->d < $latest) { $result[] = array('id' => $schedule->id, 'date' => $schedule->date, 'period' => $schedule->period, 'is_full' => $this->is_full($schedule)); } } return Response::json(array('error_code' => 0, 'schedules' => $result)); }
public function upload_portrait() { if (!Input::hasFile('portrait')) { return Response::json(array('error_code' => 2, 'message' => '无文件上传')); } if (!Input::file('portrait')->isValid()) { return Response::json(array('error_code' => 3, 'message' => '文件无效')); } $portrait = Input::file('portrait'); $file_size = $portrait->getSize(); if ($file_size > 2 * 1024 * 1024) { return Response::json(array('error_code' => 4, 'message' => '文件过大')); } $file_ext = $portrait->getClientOriginalExtension(); $user_id = Session::get('user.id'); $doctor = Doctor::find(Session::get('doctor.id')); try { $photo_path = '/images/upload/'; $photo_full_name = uniqid($user_id . time()) . '.' . $file_ext; $previous_photo = public_path() . $doctor->photo; $doctor->photo = $photo_path . $photo_full_name; DB::transaction(function () use($doctor) { $doctor->save(); }); // Save and delete previous photo if (File::exists($previous_photo)) { File::delete($previous_photo); } Session::put('doctor.photo', $doctor->photo); $portrait->move(public_path() . $photo_path, $photo_full_name); } catch (Exception $e) { return Response::json(array('error_code' => 1, 'message' => '保存失败')); } return Response::json(array('error_code' => 0, 'message' => '保存成功', 'path' => $doctor->photo, 'size' => $file_size)); }
public function getDoctorStatus() { if (Request::ajax()) { $doctor = Doctor::find(Input::get("id")); if ($doctor->state == 1) { $doctor->state = 0; } else { $doctor->state = 1; } $doctor->save(); if ($doctor) { return Response::json(array('success' => true)); } else { return Response::json(array('success' => false)); } } }
public function delete($id) { $doctor = Doctor::find($id); $doctor->delete(); return Redirect::to('doctors&cols'); }