students = array(); $this->first_reg = $xml_data->getAttribute('firstreg'); $this->jsonversion = $xml_data->getAttribute('jsonversion'); // ---------- // Extract student data and initiate the students for the // group. // ---------- $students_data = $xml_data->getElementsByTagName('student'); foreach ( $students_data as $student ) { $this->students[] = new Student($student); } } // ---------------------------------------- // get_jsonversion // // Returns the jsonversion for this group. // ---------------------------------------- public function get_jsonversion() { return $this->jsonversion; } // ---------------------------------------- // get_first_reg // // Returns the first_reg for this group. // ---------------------------------------- public function get_first_reg() { return $this->first_reg; } // ---------------------------------------- // get_students // // Returns an array with all students in this group. // ---------------------------------------- public function get_students() { return $students; } // ---------------------------------------- // get_student_by_uid // // Returns the student with uid matching $uid, null if no such // student exists. // ---------------------------------------- public function get_student_by_uid($uid) { // ---------- // Iterative over the students and find the one we seek. // ---------- foreach ( $this->students as $student ) { if ( $student->get_uid() == $uid or $student->get_old_uid() == $uid) { // Found it! return $student; } } // The student we seek did not exist. return null; } // ---------------------------------------- // print_dump // // Print function for debugging / testing. // ---------------------------------------- public function print_dump() { print "\tGroup first registered: " . $this->first_reg . ".\n"; foreach ( $this->students as $student ) { $student->print(); } } // ---------------------------------------- // contains_student // // Check whether the group contains a particular student. Returns // true if so, false otherwise. // // Arguments: // $uid is a string containing the sought students UID. // ---------------------------------------- function contains_student($uid) { if ( isset($this->students) && ! empty($this->students) ) { foreach ( $this->students as $student ) { if ( strcasecmp($student->get_uid(), $uid) == 0 ) { return true; } } } return false; } // ---------------------------------------- // End of Student_Groups class definition // ---------------------------------------- } // ---------------------------------------------------------------------------- ?>