public function getAllAdvisingAppointments() { $results = $this->db->get_where('AdvisingAppointments', array('AdvisingScheduleID' => $this->advisingScheduleID)); $data_arr = array(); foreach ($results->result_array() as $row) { $appt = new Advising_appointment_model(); $appt->setAdvisingAppointmentID($row['AdvisingAppointmentID']); $appt->setAdvisingScheduleID($row['AdvisingScheduleID']); $appt->setStartTime($row['StartTime']); $appt->setEndTime($row['EndTime']); $results = $this->db->get_where('ScheduledAdvisingAppointments', array('AdvisingAppointmentID' => $row['AdvisingAppointmentID']), 1); if ($results->num_rows() > 0) { $row = $results->row_array(); $appt->setAdvisingAppointmentState($row['AppointmentStateID']); $appt->setStudentUserID($row['StudentUserID']); } array_push($data_arr, $appt); } return $data_arr; }
public function fill() { $User_model = new User_model(); //All this reiteration is temporary until integrated with the website. in which I will use the $_SESSION data $User_model->loadPropertiesFromPrimaryKey($_SESSION['UserID']); $Advising_schedule = new Advising_schedule_model(); $Advising_appointment = new Advising_appointment_model(); $quarter = Academic_quarter_model::getLatestAcademicQuarter(); $quarter = $quarter->getAcademicQuarterID(); if ($User_model->isStudent()) { $getAdvisor = $User_model->getAdvisor(); $getAdvisor = $getAdvisor->getUserID(); $Advising_schedule->loadPropertiesFromAdvisorIDAndAcademicQuarterID($getAdvisor, $quarter); //load the scedule that corresponds to the students advisor and the acedemic quarter $all_Appointments = $Advising_schedule->getAllAdvisingAppointments(); if (!empty($_POST['student_selection'])) { foreach ($all_Appointments as $selected) { if ($selected->getScheduledStudentUserID() == $_SESSION['UserID'] && $selected->isScheduled()) { $_POST['student_selection'] = 0; } } $aptTime = explode("-", $_POST['student_selection']); //separate the start and end times foreach ($all_Appointments as $selected) { if ($selected->getStartTime() == $aptTime[0] && !$selected->isScheduled()) { $Advising_appointment->loadPropertiesFromPrimaryKey($selected->getAdvisingAppointmentID()); //load the specific appointment from the ID $Advising_appointment->setStudentUserID($_SESSION['UserID']); //set the scheduled student user ID $Advising_appointment->setAdvisingAppointmentState(1); $Advising_appointment->update(); //update the advising appointment with above information it is now marked as shceduled } } } elseif (!empty($_POST['My_Schedule'])) { redirect('Appointment_controller/Student_Cancel'); } } else { if ($User_model->isAdvisor()) { $Advising_schedule->loadPropertiesFromAdvisorIDAndAcademicQuarterID($User_model->getUserID(), $quarter); //load the schedule that corresponds to this advisor and this academic quarter $all_Appointments = $Advising_schedule->getAllAdvisingAppointments(); if (!empty($_POST['appointments'])) { foreach ($_POST['appointments'] as $selected) { $aptTime = explode("-", $selected); //separate the start and end times $Advising_appointment->setAdvisingScheduleID($Advising_schedule->getAdvisingScheduleID()); $Advising_appointment->setStartTime($aptTime[0]); //push start time to the database $Advising_appointment->setEndTime($aptTime[1]); //push the end time to the database $Advising_appointment->create(); //create the advising appointment with above information } } if (!empty($_POST['Open'])) { foreach ($_POST['Open'] as $open) { $aptTime = explode("-", $open); //separate the start and end times foreach ($all_Appointments as $selected) { if ($selected->getStartTime() == $aptTime[0]) { $selected->loadPropertiesFromPrimaryKey($selected->getAdvisingAppointmentID()); $selected->delete(); } } } } if (!empty($_POST['student_scheduled'])) { foreach ($_POST['student_scheduled'] as $slot) { $aptTime = explode("-", $slot); //separate the start and end times foreach ($all_Appointments as $selected) { if ($selected->getStartTime() == $aptTime[0]) { $selected->setAdvisingAppointmentID($selected->getAdvisingAppointmentID()); $selected->setAdvisingAppointmentState(4); $selected->update(); //EMAIL THE STUDENT THAT THE APPOINTMENT WAS CANCELED } } } } } } redirect('appointment_controller'); }