Пример #1
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());
 }
Пример #2
0
 /**
  * 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 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;
 }