CoursePrefsTeamTeach::deleteById($id); accept_reject_email($teamteach, $user, false); } } } // Refresh accept and remove forms due to new information $accept_form = new teamteach_accept_form(); $remove_form = new teamteach_remove_form(); } else { if ($data = $remove_form->get_data()) { // Prematurely set heading that the form submission was processed and necessary emails were sent $heading = get_string('email_sent', 'block_courseprefs'); $teamteaches = array(); // Iterate over selected team teach requests and delete them accordingly foreach ($remove_form->selected_teamteaches as $id) { $teamteaches[$id] = CoursePrefsTeamTeach::findById($id); delete_email($teamteaches[$id], $user); } reset_prefs($teamteaches); // Refresh remove form due to new information $remove_form = new teamteach_remove_form(); } } } // Render the page headers and forms $heading_main = get_string('teamteach_heading', 'block_courseprefs'); $navigation = array(array('name' => get_string('blockname', 'block_courseprefs'), 'link' => '', 'type' => 'title'), array('name' => $heading_main, 'link' => '', 'type' => 'title')); print_header_simple($heading_main, '', build_navigation($navigation)); print_heading_with_help($heading_main, 'teamteach', 'block_courseprefs'); if ($heading) { print_heading($heading, 'center', 3);
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; }