public function getSearchAction() { $this->layout = 'ajax'; $doctor_id = $this->input->get('user_id'); $date = $this->input->get('date'); // if ($this->input->get('date')) { // if (strtotime($this->input->get('date')) <= strtotime(date("Y-0n-j"))) // $date = date("Y-0n-j"); // else // $date = $this->input->get('date'); // } $model_period = new \modules\clinic\models\Clinic_doctors(); $model_period->_select = 'period_average '; $model_period->clinic_doctor_id = $doctor_id; $period_time = $model_period->get(); $average_time = $period_time->period_average; /////////////////////get day//////////////////////////////////////// $timestamp = strtotime($date); $day = date("l", $timestamp); $model_date = new \modules\clinic\models\Clinic_schedules(); $model_date->_select = 'from_time , to_time '; $model_date->clinic_doctor_id = $doctor_id; $model_date->status = 'on'; $model_date->day = $day; $period = $model_date->get(); if (!$period) { return json_encode(['result' => 0]); } $from = $period[0]->from_time; $to = $period[0]->to_time; $time = $model_date->get_time($from, $to, $average_time, $doctor_id); $final = $model_date->get_searchResult($date, $time, $doctor_id); if (strtotime($date) < strtotime(date("Y-0n-j"))) { foreach ($final as $key => $value) { if (!$final[$key]->status) { $final[$key]->status = 'old'; } } } return json_encode(['result' => $final]); }
public function get_scheduleAction($id) { $this->language->load("clinic_reservations"); $userInfo = $this->permissions->checkUserCredentials(); $model_id = new \modules\clinic\models\Clinic_doctors(); $model_id->_select = 'user_id'; $model_id->clinic_doctor_id = $id; $resuser_id = $model_id->get(); $user_id = $resuser_id->user_id; $model = new \modules\users\models\Users(); $model->_select = 'user_id , fullname'; $model->status = 'active'; $model->user_id = $user_id; ////////////////////////////Clinic Schedule Exceptions////////////////// // $model_Expcetion = new \modules\clinic\models\Clinic_schedule_exceptions(); ////////////////////////////doctors////////////////////////////////// $model_doctors = new \modules\clinic\models\Clinic_doctors(); $model_doctors->_select = 'clinic_doctor_id, period_average'; $model_doctors->user_id = $user_id; $res = $model_doctors->get(); $period = $res[0]->period_average; $doctor_id = $res[0]->clinic_doctor_id; ////////////////////////////doctors////////////////////////////////// $model_type = new \modules\clinic\models\Clinic_doctor_reservation_types(); $model_type->_select = 'clinic_doctor_reservation_type_id, title , price'; $model_type->clinic_doctor_id = $id; $type_result = $model_type->get(); /////////////////////////////Clinic Schedules/////////////////////////// $model_schedule = new \modules\clinic\models\Clinic_schedules(); $model_schedule->_select = 'clinic_doctor_id, day , from_time , to_time '; $model_schedule->clinic_doctor_id = $doctor_id; $model_schedule->status = 'on'; $time = $model_schedule->get(); if (!$time) { return $this->render('clinic_reservations/clinic_schedule', ['items' => $model->get()]); } $from = $time[0]->from_time; $to = $time[0]->to_time; foreach ($time as $key => $value) { if (strtotime($from) > strtotime($time[$key]->from_time)) { $from = $time[$key]->from_time; } if (strtotime($to) < strtotime($time[$key]->to_time)) { $to = $time[$key]->to_time; } } $result = $model_schedule->get(); $time = $model_schedule->get_time($from, $to, $period, $doctor_id); if ($this->input->get('date')) { if (strtotime($this->input->get('date')) <= strtotime(date("Y-0n-j"))) { $date_new = $model_schedule->get_newDate(NULL, $doctor_id); } else { $date_new = $model_schedule->get_newDate($this->input->get('date'), $doctor_id); } } else { $date_new = $model_schedule->get_newDate(NULL, $doctor_id); } $reserved = $model_schedule->get_schedule($date_new, $time, $doctor_id); $exceptions = $model_schedule->exceptions($doctor_id); $model_schedule->pre($reserved, $result, $date_new); $final = $model_schedule->Final_Array($reserved, $exceptions); return $this->render('clinic_reservations/clinic_schedule', ['dates' => $date_new, 'items' => $model->get(), 'item_schedule' => $result, 'finals' => $final, 'time' => $time, 'reserved' => $reserved, 'user' => $userInfo, 'type' => $type_result, 'doctor_id' => $doctor_id]); }