course_code = $course_code; $this->groups = array(); // Get an xml handler and begin extracting data $handler = $this->get_all_students_xml_handler(); $groups_data = $handler->get_node_array('/students/group'); foreach ( $groups_data as $group ) { $this->groups[] = new Student_Groups($group); } } // ---------------------------------------- // get_course_code // // Returns the course code for this object. // ---------------------------------------- public function get_course_code() { return $this->course_code; } // ---------------------------------------- // get_student_by_uid // // Returns the desired student, null if not found. // // Arguments: // $uid is the student's uid // ---------------------------------------- public function get_student_by_uid($uid) { // ---------- // Look through all the groups in an attempt to find the // student. // ---------- foreach ( $this->groups as $group ) { $result = $group->get_student_by_uid($uid); if ( isset($result) ) { // Found it! return $result; } } // No such student found return null; } // ---------------------------------------- // get_groups // // Returns an array of all groups. // ---------------------------------------- public function get_groups() { return $this->groups; } // ---------------------------------------- // get_faculty // // Returns the faculty for this course. // ---------------------------------------- public function get_faculty() { return $this->faculty; } // ---------------------------------------- // get_group_by_first_reg // // Returns the group of students with registration matching // $first_reg, null if no such group exists. // // Arguments: // $first_reg is the sought semester // ---------------------------------------- public function get_group_by_first_reg($first_reg) { // ---------- // Iterate over the array and find the appropriate group. // ---------- foreach ( $groups as $group ) { if ( $group->get_first_reg() == $first_reg ) { // Group found. return $group; } } // No group found. return null; } // ---------------------------------------- // print_dump // // Print function for debugging / testing. // ---------------------------------------- public function print_dump() { print "All Students for course: " . $this->course_code . ".\n"; foreach ( $this->groups as $group ) { $group->print(); } } // ---------------------------------------- // get_all_students_xml_handler // // Returns xml_handler to all students file. This file only includes a list // of ALL students the course (forever). // ---------------------------------------- private function get_all_students_xml_handler() { global $COURSE_INFO_PATH; $this->file_path = realpath($COURSE_INFO_PATH . '/' . $this->course_code . '/' . '/all_students.xml'); return xml_handler::get_xml_handler_for_file(realpath($this->file_path)); } // ---------------------------------------- // get_jsonversion_for_student // // Iterates over the student groups and attempts to find the // sought student. If found, returns the jsonversion for the // group. Returns "invalid" otherwise. // // Arguments: // $uid is a string containing the UID for the sought student. // ---------------------------------------- // ---------------------------------------- public function get_jsonversion_for_student($uid) { if ( isset($this->groups) && ! empty($this->groups) ) { foreach ( $this->groups as $group ) { if ( $group->contains_student($uid) ) { return $group->get_jsonversion(); } } } return "invalid"; } // ---------------------------------------- // End of All_Students class definition // ---------------------------------------- } // ---------------------------------------------------------------------------- ?>