예제 #1
0
파일: Courses.php 프로젝트: hughnguy/php
 /**
  * Given a student, fetch all the courses they are registered to in a given semester
  * @param int $student_num The student number
  * @param string $semester The semester
  * @return array
  */
 public function fetchAllStudentCoursesForSemester($student_num, $semester)
 {
     if (!ctype_digit($student_num) && !is_int($student_num)) {
         throw new \InvalidArgumentException('Invalid student number');
     }
     if (!ctype_digit($semester)) {
         throw new \InvalidArgumentException("Semester provided is not a numeric value…");
     }
     $sql = "SELECT c.name, c.code, c.section, c.session,\n                       cc.professor_first_name, cc.professor_last_name,\n                       GROUP_CONCAT(DISTINCT cc.professor_email SEPARATOR ',') AS professor_email\n                  FROM org_courses c\n                  JOIN org_course_classes cc\n                    ON c.course_id = cc.course_id\n                  JOIN org_student_course_classes x\n                    ON cc.class_id = x.class_id\n                 WHERE x.student_id = :student_num\n                   AND c.session = :semester\n              GROUP BY c.code, c.section\n              ORDER BY c.session DESC;";
     $current_courses = $this->db->query($sql, array('student_num' => $student_num, 'semester' => $semester))->fetchAll();
     //Add the opt out status
     foreach ($current_courses as $key => $cc) {
         $current_courses[$key]['opted_out'] = \Ventus\Utilities\Functions::checkIfStudentHasOptedOut($student_num, $cc['code'], $cc['section'], $cc['session']);
         $current_courses[$key]['csa_active'] = \Ventus\Utilities\Functions::checkIfStudentHasCSA($student_num, $cc['code'], $cc['section'], $cc['session']);
         $current_courses[$key]['template_active'] = \Ventus\Utilities\Functions::checkIfStudentHasTemplateAccs($student_num);
         $current_courses[$key]['expired'] = \Ventus\Utilities\Functions::checkIfStudentHasExpiredAccs($student_num, $cc['code'], $cc['section'], $cc['session']);
     }
     return $current_courses;
 }