Esempio n. 1
0
 /**
  * Convenience method for obtaining the teacher of the section
  */
 function getSectionsUser()
 {
     $teachers = CoursePrefsTeacher::findBySectionId($this->sectionsid);
     foreach ($teachers as $teacher) {
         if ($teacher->getPrimaryFlag()) {
             return CoursePrefsUser::findById($teacher->getUsersId());
         }
     }
 }
Esempio n. 2
0
File: lib.php Progetto: rrusso/EARS
 function process_enrollment($user, $section, $fields)
 {
     global $CFG;
     $role = (int) $fields[0];
     // Student role=1
     // Else it's a Teacher primary role=2
     if ($role == 1) {
         $status = lookup_statuscode($fields[1], STATUSCODE_TYPE_STUDENT);
         $student = CoursePrefsStudent::findByUnique($section->getId(), $user->getId());
         $credit_hours = $fields[4];
         if (!$student && $status == 'unenroll') {
             throw new Exception(get_string('cant_drop', 'block_courseprefs'));
         } else {
             if (!$student) {
                 $student = new CoursePrefsStudent($section->getId(), $user->getId(), $status, $credit_hours);
             } else {
                 // Recalculate hours
                 $student->findHours($status, $credit_hours);
             }
         }
         try {
             $student->save();
         } catch (Exception $e) {
             throw new Exception($e->getMessage());
         }
         // Time to add a log entry for this course
         CoursePrefsLog::add_to_log($user->getId(), $section->getId(), strtotime($fields[2]), $status, strtotime($fields[3]));
     } else {
         $status = lookup_statuscode($fields[1], STATUSCODE_TYPE_TEACHER);
         $primary_flag = $role == 2 ? 1 : 0;
         $teacher = CoursePrefsTeacher::findByUnique($user->getId(), $section->getId(), $primary_flag);
         // In the event that the teacher does not exist, and the mainframe
         // gives us a non-primary teacher drop, then change the info to be a
         // primary teacher drop.
         if (!$teacher && !$primary_flag && $status == 'unenroll') {
             $role = 2;
             $teacher = CoursePrefsTeacher::findByUnique($user->getId(), $section->getId(), 1);
         }
         if (!$teacher) {
             $teacher = new CoursePrefsTeacher($section->getId(), $user->getId(), $primary_flag, $status);
         }
         /*
         $teacher->setPrimaryFlag($primary_flag);
         */
         $teacher->setStatus($status);
         $teacher->setTimeStamp(strtotime($fields[2]));
         try {
             $teacher->save();
             CoursePrefsLog::add_to_log($user->getId(), $section->getId(), strtotime($fields[2]), $status, 'Teacher event');
         } catch (Exception $e) {
             throw new Exception($e->getMessage());
         }
         // Great job; now if the primary teacher is being dropped, mark the section as pending
         // cron will take care of the rest
         if ($role == 2 && $status == 'unenroll') {
             $section->setStatus('pending');
             $section->save();
             // Clean any preference that was applied
             foreach (array('crosslist', 'split') as $pref) {
                 $sql = "UPDATE {$CFG->prefix}block_courseprefs_{$pref}\n                                SET status='todo'\n                                WHERE sectionsid={$section->getId()}";
                 execute_sql($sql, false);
                 // delete_records('block_courseprefs_'.$pref, 'sectionsid', $section->getId());
             }
         }
     }
 }
Esempio n. 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;
 }