示例#1
0
 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');
 }
示例#2
0
文件: lib.php 项目: rrusso/EARS
 /**
  * PROCESS ENROLLMENT FILE
  * Expects a file of format: Semester|Student PawsID|Campus|Department|Course #|Section #|Status Code|HRS|Real Date|EFFECTIVE DATE|FERP
  */
 function parse_enrollfile($now, $line)
 {
     $fields = array_map('addslashes', array_map('trim', explode('|', $line)));
     // Process only if we have the correct number of fields
     if (count($fields) != 11) {
         $a->file = $this->files['enrollfile'];
         $a->line = $line;
         $this->errorlog[] = get_string('malformed', 'block_courseprefs', $a);
         return;
     }
     // Lookup necessary foreign keys for enrollment lookup; throw exception if any are missing
     list($year, $semester_name) = $this->parse_semester($fields[0]);
     $semester = CoursePrefsSemester::findByUnique($year, $semester_name, $fields[2]);
     if (!$semester) {
         $this->errorlog[] = 'Unable to lookup semester entry for enrollment in ' . $this->files['enrollfile'] . ': ' . $line;
         return;
     }
     $user = CoursePrefsUser::findByUnique($fields[1]);
     if (!$user) {
         $this->errorlog[] = 'Unable to lookup user entry for enrollment in ' . $this->files['enrollfile'] . ': ' . $line;
         return;
     }
     $course = CoursePrefsCourse::findByUnique($fields[3], $fields[4]);
     if (!$course) {
         $this->errorlog[] = 'Unable to lookup course entry for enrollment in ' . $this->files['enrollfile'] . ': ' . $line;
         return;
     }
     $section = CoursePrefsSection::findByUnique($semester->getId(), $course->getId(), $fields[5]);
     if (!$section) {
         $this->errorlog[] = 'Unable to lookup section entry for enrollment in ' . $this->files['enrollfile'] . ': ' . $line;
         return;
     }
     try {
         $new_fields = array(1, $fields[6], $fields[8], $fields[9], $fields[7]);
         $this->process_enrollment($user, $section, $new_fields);
     } catch (Exception $e) {
         $this->errorlog[] = $e->getMessage() . ' from ' . $this->files['enrollfile'] . ': ' . $line;
     }
     $user->setFerpa($fields[10]);
     try {
         $user->save();
     } catch (Exception $e) {
         $this->errorlog[] = $e->getMessage() . ' from ' . $this->files['enrollfile'] . ': ' . $line;
     }
 }
示例#3
0
 function definition()
 {
     global $CFG, $USER;
     $form =& $this->_form;
     $user = CoursePrefsUser::findByUnique($USER->username);
     // Register regular expression rules for form elements
     $form->registerRule('valid_days', 'regex', VALID_DAYS_PATTERN);
     // Default settings fieldset
     $form->addElement('header', 'default_settings', get_string('default_settings', 'block_courseprefs'));
     $form->setHelpButton('default_settings', array('creation_enrol_default', get_string('creation_enrol_default_help', 'block_courseprefs'), 'block_courseprefs', true));
     $form->addElement('static', 'course_create_days', get_string('course_create_days', 'block_courseprefs'), CoursePrefsConfig::getNamedValue('course_create_days'));
     $form->addElement('static', 'course_enroll_days', get_string('course_enroll_days', 'block_courseprefs'), CoursePrefsConfig::getNamedValue('course_enroll_days'));
     $courseformats = mr_get_list_of_plugins('course/format');
     $formcourseformats = array();
     foreach ($courseformats as $courseformat) {
         $formcourseformats["{$courseformat}"] = get_string("format{$courseformat}", "format_{$courseformat}");
         if ($formcourseformats["{$courseformat}"] == "[[format{$courseformat}]]") {
             $formcourseformats["{$courseformat}"] = get_string("format{$courseformat}");
         }
     }
     $form->addElement('select', 'format', get_string('format', 'block_courseprefs'), $formcourseformats);
     $numsections = array();
     foreach (range(1, 52) as $i) {
         $numsections[$i] = $i;
     }
     $form->addElement('select', 'numsections', get_string('numberweeks', 'block_courseprefs'), $numsections);
     $choices = array();
     $choices['0'] = get_string('courseavailablenot');
     $choices['1'] = get_string('courseavailable');
     $form->addElement('select', 'visible', get_string('availability', 'block_courseprefs'), $choices);
     /*
     $choices = array();
     $choices['0'] = get_string('delete_choice_0', 'block_courseprefs');
     $choices['1'] = get_string('delete_choice_1', 'block_courseprefs');
     $form->addElement('select', 'delete', get_string('delete_option', 'block_courseprefs'), $choices);
     */
     /*
     // Adding textbox for user's default for course creation
     $form->addElement('text', 'course_create_days', get_string('course_create_days', 'block_courseprefs'));
     $form->setDefault('course_create_days', $user->getCourseCreateDays());
     $form->addRule('course_create_days', get_string('err_required', 'form'), 'required');
     $form->addRule('course_create_days', get_string('err_negative_number', 'block_courseprefs'), 'valid_days');
     
     // Adding textbox for user's default for course enrollment
     $form->addElement('text', 'course_enroll_days', get_string('course_enroll_days', 'block_courseprefs'));
     $form->setDefault('course_enroll_days', $user->getCourseEnrollDays());
     $form->addRule('course_enroll_days', get_string('err_required', 'form'), 'required');
     $form->addRule('course_enroll_days', get_string('err_negative_number', 'block_courseprefs'), 'valid_days');
     $form->addRule(array('course_create_days', 'course_enroll_days'),
         get_string('err_create_enroll_compare', 'block_courseprefs'), 'compare', 'gte');
     */
     // Lookup necessary information to build form elements
     $user = CoursePrefsUser::findByUnique($USER->username);
     $courses = $user->getCoursesAsTeacher();
     $sections = $user->getSectionsAsTeacher();
     // Build lookup of semesters to the courses the user teaches
     $semester_lookup = array();
     $semester_to_courses = array();
     $semester_cache = array();
     foreach ($sections as $section) {
         $semestersid = $section->getSemestersId();
         // Check semester cache for object and look it up if not found
         if (!array_key_exists($semestersid, $semester_cache)) {
             $semester_cache[$semestersid] = CoursePrefsSemester::findById($semestersid);
             $semester_to_courses[$semestersid] = array();
         }
         $semester = $semester_cache[$section->getSemestersId()];
         // Build semester name for fieldsets and associate course with semester
         $semester_lookup[$semester->getId()] = $semester->getYear() . ' ' . $semester->getName();
         $semester_to_courses[$semester->getId()][$section->getCoursesId()] = $courses[$section->getCoursesId()];
         // Resort semester's courses and maintain the array indexes
         asort($semester_to_courses[$semester->getId()]);
     }
     // Sort semesters
     uasort($semester_lookup, "cmpSemester");
     // Generate semester-specific field sets containing a list of courses the user teaches
     foreach ($semester_lookup as $semestersid => $semesterheader) {
         $form->addElement('header', 'year_semester' . $semestersid, $semesterheader);
         $form->setHelpButton('year_semester' . $semestersid, array('creation_enrol_semester', get_string('creation_enrol_semester_help', 'block_courseprefs'), 'block_courseprefs', true));
         $statics = array();
         $statics[] =& $form->createElement('static', 'create_heading', '', '<span style="margin:0px 30px 0px 35px; font-weight: bold">' . get_string('creation_days', 'block_courseprefs') . '</span>');
         $statics[] =& $form->createElement('static', 'enroll_heading', '', '<span style="margin:0px 35px 0px 70px; font-weight: bold">' . get_string('enroll_days', 'block_courseprefs') . '</span>');
         $form->addGroup($statics, 'static_groupings', false);
         foreach ($semester_to_courses[$semestersid] as $course) {
             // Build textbox group to hold course-specific creation/enrollment settings
             $textboxes = array();
             $textboxes[] =& $form->createElement('text', $semestersid . CREATE_DAYS_FIELD . $course->getId(), null);
             $textboxes[] =& $form->createElement('text', $semestersid . ENROLL_DAYS_FIELD . $course->getId(), null);
             // Add form elements for course
             $form->addGroup($textboxes, $semestersid . COURSE_GROUP . $course->getId(), $course->getDepartment() . ' ' . $course->getCourseNumber(), '&nbsp;', false);
             /*$form->addGroupRule($semestersid . COURSE_GROUP . $course->getId(), array(
                   $semestersid . CREATE_DAYS_FIELD . $course->getId() => array(
                       array(get_string('err_negative_number', 'block_courseprefs'), 'compare', 'neq', 0),
                   ),
                   $semestersid . ENROLL_DAYS_FIELD . $course->getId() => array(
                       array(get_string('err_negative_number', 'block_courseprefs'), 'compare', 'neq', 0),
                   ),
               ));*/
         }
     }
     // Adding submit and cancel buttons to form
     $buttonarray = array();
     $buttonarray[] =& $form->createElement('submit', 'submitbutton', get_string('savechanges'));
     $buttonarray[] =& $form->createElement('cancel');
     $form->addGroup($buttonarray, 'buttonar', '', array(' '), false);
     $form->closeHeaderBefore('buttonar');
 }
示例#4
0
 /**
  * Generate full display name of a section given a section's ID.  Returns the same output as the
  * generateFullname() method.
  * Example output: 2008 Fall CSC 1001 001
  */
 static function generateFullnameById($sectionsid)
 {
     $section = self::findById($sectionsid);
     if (!$section) {
         return null;
     }
     $course = CoursePrefsCourse::findById($section->getCoursesId());
     $semester = CoursePrefsSemester::findById($section->getSemestersId());
     return self::generateFullname($semester->getYear(), $semester->getName(), $course->getDepartment(), $course->getCourseNumber(), $section->getSectionNumber());
 }