function definition() { global $CFG, $USER; $form =& $this->_form; $user = CoursePrefsUser::findByUnique($USER->username); $sections = $user->getSectionsInfoAsPrimaryTeacher(); $courses = $user->getCoursesAsPrimaryTeacher(); // Builds a lookup table associating sections with its parent course $coursesid_to_sections = array(); $semester_cache = array(); foreach ($sections as $sectionsid => $section) { $semestersid = $section->semestersid; $coursesid = $section->coursesid; // Lookup semester object and store in cache if not found if (!array_key_exists($semestersid, $semester_cache)) { $semester_cache[$semestersid] = CoursePrefsSemester::findById($semestersid); } $semester = $semester_cache[$semestersid]; $course = $courses[$coursesid]; // Associate section with course and build sorting string for cmpSemester if (!array_key_exists($coursesid, $coursesid_to_sections)) { $coursesid_to_sections[$coursesid] = array(); } $section_fullname = CoursePrefsSection::generateFullname($semester->getYear(), $semester->getName(), $course->getDepartment(), $course->getCourseNumber(), $section->section_number); $coursesid_to_sections[$coursesid][$sectionsid] = $section_fullname; } // Generate course-specific field sets foreach ($courses as $coursesid => $course) { $courses_sections = $coursesid_to_sections[$coursesid]; // Build information to be substituted in listing $a = new stdClass(); $a->course_department = $course->getDepartment(); $a->course_number = $course->getCourseNumber(); $form->addElement('header', 'course_settings' . $coursesid, get_string('unwanted_label_fieldset', 'block_courseprefs', $a)); $form->addElement('static', UNWANTED_COURSE_FIELD . $coursesid, '', '<a onclick="toggleUnwanted(\'' . $coursesid . '\', true)" href="javascript:void(0)">' . get_string('all') . '</a>/<a onclick="toggleUnwanted(\'' . $coursesid . '\', false)" href="javascript:void(0)">' . get_string('none') . '</a>'); uasort($courses_sections, "cmpSemester"); foreach ($courses_sections as $sectionsid => $fullname) { $section = $sections[$sectionsid]; $semester = $semester_cache[$section->semestersid]; // Build information to be substituted in listing $a = new stdClass(); $a->semester_year = $semester->getYear(); $a->semester_name = $semester->getName(); $a->section_number = $section->section_number; $form->addElement('checkbox', UNWANTED_SECTION_FIELD . $sectionsid . '_' . $coursesid, '<span class="choiceindenter">', get_string('unwanted_label_section', 'block_courseprefs', $a)); } } // Adding submit and cancel buttons to form $buttons = array(); $buttons[] =& $form->createElement('submit', 'submitbutton', get_string('savechanges')); $buttons[] =& $form->createElement('cancel'); $form->addGroup($buttons, 'buttonar', '', array(' '), false); $form->closeHeaderBefore('buttonar'); }
function definition() { global $USER; $form =& $this->_form; $user = CoursePrefsUser::findByUnique($USER->username); // prepare a 2D array of courseids and their sections $sections = $user->getTeamteachableSections(); //Builds the dropdown item array $dropdown_items = array(); foreach ($sections as $sid => $section) { $dropdown_items[$sid] = CoursePrefsSection::generateFullname($section->year, $section->name, $section->department, $section->course_number, $section->section_number); } // Sort listing of invitations by semesters and prepend the default "NONE" option uasort($dropdown_items, "cmpSemester"); $dropdown_items = array("NONE" => "NONE") + $dropdown_items; // Adding team teach fieldset $form->addElement('header', 'add_teamteach', get_string('header_teamteach_add', 'block_courseprefs')); $form->setHelpButton('add_teamteach', array('teamteach_add', get_string('teamteach_add_help', 'block_courseprefs'), 'block_courseprefs', true)); // Register regular expression rules for form elements $form->registerRule('valid_sectionsid', 'regex', SECTIONSID_PATTERN); $form->registerRule('valid_course_number', 'regex', COURSE_NUMBER_PATTERN); $form->registerRule('valid_section_number', 'regex', SECTION_NUMBER_PATTERN); // Adding dropdown element for user-owner sections $form->addElement('select', SECTIONSID_FIELD, get_string('teamteach_selected_courses', 'block_courseprefs'), $dropdown_items); $form->addRule(SECTIONSID_FIELD, get_string('err_select_section', 'block_courseprefs'), 'valid_sectionsid'); $form->addRule(SECTIONSID_FIELD, get_string('err_select_section', 'block_courseprefs'), 'required'); // Adding textbox elements to search for foreign section $textboxes = array(); $textboxes[] =& $form->createElement('text', DEPARTMENT_FIELD, null, array('value' => DEPARTMENT_DEFAULT)); $textboxes[] =& $form->createElement('text', COURSE_NUMBER_FIELD, null, array('value' => COURSE_DEFAULT)); $textboxes[] =& $form->createElement('text', SECTION_NUMBER_FIELD, null, array('value' => SECTION_DEFAULT)); $form->addGroup($textboxes, TEXTBOX_GROUP, get_string('teamteach_related_course', 'block_courseprefs'), '', false); $form->addGroupRule(TEXTBOX_GROUP, array(DEPARTMENT_FIELD => array(array(get_string('err_missing_department', 'block_courseprefs'), 'required')), COURSE_NUMBER_FIELD => array(array(get_string('err_missing_course_number', 'block_courseprefs'), 'required'), array(get_string('err_invalid_course_number', 'block_courseprefs'), 'valid_course_number')), SECTION_NUMBER_FIELD => array(array(get_string('err_missing_section_number', 'block_courseprefs'), 'required'), array(get_string('err_invalid_section_number', 'block_courseprefs'), 'valid_section_number')))); // Adding submit button to form $form->addElement('submit', 'submit', get_string('add_entry', 'block_courseprefs')); }
function print_changes($label, $the_prefs) { $html = ''; if (!empty($the_prefs)) { $html = '<span class="label">' . $label . '</span>'; $html .= "<ul>"; foreach ($the_prefs as $bucket => $sections) { $html .= '<li>Changes for Course ' . $bucket . '</li>'; $html .= '<ul>'; foreach ($sections as $section) { $html .= '<li>' . CoursePrefsSection::generateFullname($section->year, $section->name, $section->department, $section->course_number, $section->section_number) . '</li>'; } $html .= '</ul>'; } $html .= "</ul>"; } return $html; }