function validation($data) { global $USER; $errorlog = array(); $form_errorlog = $this->_form->_errors; // Skip processing group if there were errors with any of the related group fields if ($form_errorlog[TEXTBOX_GROUP] || $form_errorlog[SECTIONSID_FIELD]) { return $errorlog; } // Parse form submission and glean necessary information $section_id = $data[SECTIONSID_FIELD]; $department = $data[DEPARTMENT_FIELD]; $course_number = $data[COURSE_NUMBER_FIELD]; $section_number = $data[SECTION_NUMBER_FIELD]; // Build sections ID to courses ID lookup for data validation $user = CoursePrefsUser::findByUnique($USER->username); $sections = $user->getSectionsAsTeacher(); // Log an error if the user isn't the primary teacher of the section selected if (!($sections[$section_id] && $user->isPrimaryTeacher($sections[$section_id]))) { $errorlog[TEXTBOX_GROUP] = get_string('err_not_primary', 'block_courseprefs'); return $errorlog; } // Log an error if the section selected doesn't exist $users_section = $sections[$section_id]; if (!$users_section) { $errorlog[TEXTBOX_GROUP] = get_string('err_unknown_section', 'block_courseprefs'); return $errorlog; } // Retrieve course related to critera and log an error if course doesn't exist $course = CoursePrefsCourse::findByUnique($department, $course_number); if (!$course) { $errorlog[TEXTBOX_GROUP] = get_string('err_unknown_course', 'block_courseprefs'); return $errorlog; } // Retrieve section related to critera and log an error if course doesn't exist $section = CoursePrefsSection::findByUnique($users_section->getSemestersId(), $course->getId(), $section_number); if (!$section) { $errorlog[TEXTBOX_GROUP] = get_string('err_unknown_section', 'block_courseprefs'); return $errorlog; } // Log an error if the user has already selected these sections to be team taught if (CoursePrefsTeamTeach::findByUnique($user->getId(), $users_section->getId(), $section->getId())) { $errorlog[TEXTBOX_GROUP] = get_string('err_same_teamteach', 'block_courseprefs'); return $errorlog; } // Determine the primary teacher of the foreign section $teachers = CoursePrefsTeacher::findBySectionId($section->getId()); $teacher_primary = null; foreach ($teachers as $teacher) { // Skip if teacher is not the primary teacher if (!$teacher->getPrimaryFlag()) { continue; } $teacher_primary = $teacher; break; } // Log an error if there isn't a primary teacher to notify or if the user teaches both courses. // Otherwise, store the ids of the sections selected for team teaching if (!$teacher_primary) { $errorlog[TEXTBOX_GROUP] = get_string('no_instructor', 'block_courseprefs'); } else { if ($teacher_primary->getUsersId() == $user->getId()) { $errorlog[TEXTBOX_GROUP] = get_string('same_teacher', 'block_courseprefs'); } else { $this->section_selections = $section_id; $this->secondary_teamteaches = $section->getId(); } } return $errorlog; }