public static function addCourses($id, $coursesIds, $termId) { self::validateCoursesId($coursesIds); Term::validateId($termId); Tutor_has_course_has_termFetcher::insertMany($id, $coursesIds, $termId); }
public static function getTutors($courseId, $termId) { self::validateId($courseId); Term::validateId($termId); return CourseFetcher::retrieveTutors($courseId, $termId); }
/** * @param $termId * @return array * @throws Exception * @throws PHPExcel_Exception */ private static function exportAppointments($termId) { Term::validateId($termId); require_once ROOT_PATH . 'plugins/PHPExcel_1.8.0_doc/Classes/PHPExcel.php'; date_default_timezone_set('Europe/Athens'); $allAppointments = AppointmentFetcher::retrieveForTerm($termId); $appointmentsHaveStudents = AppointmentHasStudentFetcher::retrieveForTerm($termId); $primaryFocusOfConferences = PrimaryFocusOfConferenceFetcher::retrieveForTerm($termId); $termData = TermFetcher::retrieveSingle($termId); $termStart = new DateTime($termData[TermFetcher::DB_COLUMN_START_DATE]); $termEnd = new DateTime($termData[TermFetcher::DB_COLUMN_END_DATE]); $termName = $termData[TermFetcher::DB_COLUMN_NAME]; $objPHPExcel = new PHPExcel(); $objPHPExcel->getProperties()->setCreator(App::getName())->setLastModifiedBy(App::getName())->setTitle(self::TITLE_VISIT_LOG . " - " . $termName)->setSubject("Appointments")->setDescription("List of appointments for {$termName}.")->setKeywords("office sass appointments php")->setCategory("Appointments"); $sheetIndex = 0; for ($workingDateTime = $termStart; $workingDateTime <= $termEnd; $workingDateTime->modify('+1 week')) { $curWeek = $workingDateTime->format('W'); $appointmentsWeekly = self::getAppointments($allAppointments, $curWeek); $startWeekDate = self::getWorkingDates($workingDateTime->format('Y'), $workingDateTime->format('W')); $endWeekDate = self::getWorkingDates($workingDateTime->format('Y'), $workingDateTime->format('W'), false); $periodTime = date("d M", strtotime($startWeekDate)) . "-" . date("d M, o", strtotime('-1 day', strtotime($endWeekDate))); $objPHPExcel->createSheet($sheetIndex); $objPHPExcel->setActiveSheetIndex($sheetIndex)->setCellValue('A1', 'Day')->setCellValue('B1', 'Date')->setCellValue('C1', 'Month')->setCellValue('D1', 'Year')->setCellValue('E1', 'Time')->setCellValue('F1', 'LF Lname')->setCellValue('G1', 'Stud Lname')->setCellValue('H1', 'Stud Fname')->setCellValue('I1', 'Stud ID')->setCellValue('J1', 'Major')->setCellValue('K1', 'Mobile')->setCellValue('L1', 'e-mail')->setCellValue('M1', 'Course Code')->setCellValue('N1', 'Course Instructor')->setCellValue('O1', '# of Students')->setCellValue('P1', 'Outcome')->setCellValue('Q1', 'Actual Duration')->setCellValue('R1', 'Purpose'); $sheetIndex++; $objPHPExcel->getActiveSheet()->getStyle('A1:R1')->applyFromArray(self::$styleVisitLogHeader); $objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(24); $objPHPExcel->getActiveSheet()->setTitle($periodTime); $row = 2; foreach ($appointmentsWeekly as $appointment) { $appointmentStartDateTime = new DateTime($appointment[AppointmentFetcher::DB_COLUMN_START_TIME]); $appointmentEndDateTime = new DateTime($appointment[AppointmentFetcher::DB_COLUMN_END_TIME]); $appointmentId = $appointment[AppointmentFetcher::DB_COLUMN_ID]; $students = self::getStudentsForAppointment($appointmentsHaveStudents, $appointmentId); $numOfStudents = sizeof($students); // TODO: REMOVE autosize from loop $col = 0; // day $day = $appointmentStartDateTime->format('l'); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $day); $col++; // date $date = $appointmentStartDateTime->format('d'); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $date); $col++; // month $month = $appointmentStartDateTime->format('M'); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $month); $col++; // year $year = $appointmentStartDateTime->format('Y'); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $year); $col++; // time $time = $appointmentStartDateTime->format('H:i'); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $time); $col++; // tutor last name $tutorLastName = $appointment[UserFetcher::DB_COLUMN_LAST_NAME]; $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $tutorLastName); // TODO: add student that first requested the appointment. $col++; // student last name $studentLastName = $students[0][StudentFetcher::DB_COLUMN_LAST_NAME]; $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $studentLastName); $col++; // student first name $studentFirstName = $students[0][StudentFetcher::DB_COLUMN_FIRST_NAME]; $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $studentFirstName); $col++; // student ID $studentId = $students[0][StudentFetcher::DB_COLUMN_STUDENT_ID]; $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $studentId); $col++; // student major $majorCode = $students[0][MajorFetcher::DB_COLUMN_CODE]; $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $majorCode); $col++; // student mobile $mobile = $students[0][StudentFetcher::DB_COLUMN_MOBILE]; $objPHPExcel->getActiveSheet()->setCellValueExplicitByColumnAndRow($col, $row, $mobile); $col++; // student email $email = $students[0][StudentFetcher::DB_COLUMN_EMAIL]; $objPHPExcel->getActiveSheet()->setCellValueExplicitByColumnAndRow($col, $row, $email); $col++; // course code $courseCode = $appointment[CourseFetcher::DB_COLUMN_CODE]; $objPHPExcel->getActiveSheet()->setCellValueExplicitByColumnAndRow($col, $row, $courseCode); $col++; // instructor for first student $instructorLastName = $students[0][InstructorFetcher::DB_COLUMN_LAST_NAME]; $objPHPExcel->getActiveSheet()->setCellValueExplicitByColumnAndRow($col, $row, $instructorLastName); $col++; // instructor for first student $objPHPExcel->getActiveSheet()->setCellValueExplicitByColumnAndRow($col, $row, $numOfStudents); $col++; // appointment outcome $appointmentOutcome = $appointment[AppointmentFetcher::DB_COLUMN_LABEL_MESSAGE]; $objPHPExcel->getActiveSheet()->setCellValueExplicitByColumnAndRow($col, $row, $appointmentOutcome); $col++; // appointment duration $appointmentDuration = ($appointmentEndDateTime->getTimestamp() - $appointmentStartDateTime->getTimestamp()) / 60; $objPHPExcel->getActiveSheet()->setCellValueExplicitByColumnAndRow($col, $row, $appointmentDuration); $col++; // purpose $primaryFocusOfConferencesString = self::getFocusOfConferencesForAppointment($primaryFocusOfConferences, $appointmentId); if (!empty($primaryFocusOfConferencesString)) { $primaryFocusOfConferencesString = Report::convertFocusOfConferenceToString($primaryFocusOfConferencesString[0]); $objPHPExcel->getActiveSheet()->setCellValueExplicitByColumnAndRow($col, $row, $primaryFocusOfConferencesString); //$objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($col)->setAutoSize(true); } switch ($appointment[AppointmentFetcher::DB_COLUMN_LABEL_COLOR]) { case Appointment::LABEL_COLOR_PENDING: $color = '888888'; break; case Appointment::LABEL_COLOR_CANCELED: $color = 'e5412d'; break; case Appointment::LABEL_COLOR_SUCCESS: $color = '3fa67a'; break; case Appointment::LABEL_COLOR_WARNING: $color = 'f0ad4e'; break; default: $color = '444'; break; } $styleRow = array('font' => array('bold' => false, 'name' => 'Times New Roman', 'size' => 12), 'alignment' => array('horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_LEFT), 'borders' => array('bottom' => array('style' => PHPExcel_Style_Border::BORDER_THIN), 'right' => array('style' => PHPExcel_Style_Border::BORDER_MEDIUM)), 'fill' => array('type' => PHPExcel_Style_Fill::FILL_GRADIENT_LINEAR, 'rotation' => 90, 'startcolor' => array('argb' => $color), 'endcolor' => array('argb' => $color))); $objPHPExcel->getActiveSheet()->getStyle("A{$row}:R{$row}")->applyFromArray($styleRow); $row++; } // end foreach // enable all filters $objPHPExcel->getActiveSheet()->setAutoFilter($objPHPExcel->getActiveSheet()->calculateWorksheetDimension()); // source: http://stackoverflow.com/a/5578240 - autosize all columns $lastColumn = $objPHPExcel->getActiveSheet()->getHighestColumn(); $lastColumn++; for ($column = 'A'; $column != $lastColumn; $column++) { $objPHPExcel->getActiveSheet()->getColumnDimension($column)->setAutoSize(true); } // end for } // end foreach // Set active sheet index to the first sheet, so Excel opens this as the first sheet $objPHPExcel->setActiveSheetIndex(0); return array($termName, $objPHPExcel); }
public static function getTutorsOnTermOnCourse($courseId, $termId) { Course::validateId($courseId); Term::validateId($termId); return ScheduleFetcher::retrieveTutorsOnTermOnCourse($courseId, $termId); }
public static function updateTeachingCourse($id, $newCourseId, $oldCourseId, $termId) { if (!preg_match('/^[0-9]+$/', $newCourseId) || !preg_match('/^[0-9]+$/', $oldCourseId) || strcmp($newCourseId, $oldCourseId) === 0) { throw new Exception("Data has been tempered. Aborting process."); } Term::validateId($termId); if (self::teachesCourseWithIdOnTerm($newCourseId, $id, $termId)) { throw new Exception("Data has been tempered. Aborting process."); } try { $query = "UPDATE `" . App::getDbName() . "`.`" . self::DB_TABLE_TUTOR_HAS_COURSE_HAS_TERM . "` SET `course_id`= :newCourseId WHERE `tutor_user_id`= :tutorId and`course_id`= :oldCourseId"; $dbConnection = DatabaseManager::getConnection(); $query = $dbConnection->prepare($query); $query->bindParam(':newCourseId', $newCourseId, PDO::PARAM_INT); $query->bindParam(':tutorId', $id, PDO::PARAM_INT); $query->bindParam(':oldCourseId', $oldCourseId, PDO::PARAM_INT); $query->execute(); } catch (Exception $e) { throw new Exception("Could not replace teaching courses data into database."); } }
public static function getAppointmentsForCourseAndTutor($tutorId, $courseId, $termId) { Tutor::validateId($tutorId); Term::validateId($termId); $appointmentHours = AppointmentFetcher::getAppointmentsForTutorAndCourse($tutorId, $courseId, $termId); $appointmentHoursJSON = []; foreach ($appointmentHours as $appointmentHour) { $appointmentTitle = $appointmentHour[CourseFetcher::DB_COLUMN_CODE] . " - " . $appointmentHour[UserFetcher::DB_COLUMN_FIRST_NAME] . " " . $appointmentHour[UserFetcher::DB_COLUMN_LAST_NAME]; $students = AppointmentHasStudentFetcher::retrieveStudentsWithAppointment($appointmentHour[AppointmentFetcher::DB_COLUMN_ID]); $appointmentTitle .= " - "; foreach ($students as $student) { $appointmentTitle .= $student[StudentFetcher::DB_TABLE . "_" . StudentFetcher::DB_COLUMN_FIRST_NAME] . " " . $student[StudentFetcher::DB_TABLE . "_" . StudentFetcher::DB_COLUMN_LAST_NAME] . ", "; } $appointmentTitle = rtrim($appointmentTitle, ", "); $startDate = new DateTime($appointmentHour[AppointmentFetcher::DB_COLUMN_START_TIME]); $endDate = new DateTime($appointmentHour[AppointmentFetcher::DB_COLUMN_END_TIME]); $appointmentUrl = App::getDomainName() . "/appointments/" . $appointmentHour[UserFetcher::DB_COLUMN_ID]; switch ($appointmentHour[AppointmentFetcher::DB_COLUMN_LABEL_COLOR]) { case Appointment::LABEL_COLOR_PENDING: $color = '#888888'; break; case Appointment::LABEL_COLOR_CANCELED: $color = '#e5412d'; break; case Appointment::LABEL_COLOR_SUCCESS: $color = '#3fa67a'; break; case Appointment::LABEL_COLOR_WARNING: $color = '#f0ad4e'; break; default: $color = '#444'; break; } $appointmentHoursJSON[] = ['title' => $appointmentTitle, 'start' => $startDate->format('Y-m-d H:i:s'), 'end' => $endDate->format('Y-m-d H:i:s'), 'allDay' => false, 'url' => $appointmentUrl, 'color' => $color]; } return json_encode($appointmentHoursJSON); }