Esempio n. 1
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. 2
0
 /**
  * Class method that finds and removes a split from the database
  * based on the id provided
  */
 static function deleteById($id)
 {
     $split = get_record('block_courseprefs_split', 'id', $id);
     // Logging that they've removed a split entry
     CoursePrefsLog::add_to_log($split->usersid, $split->sectionsid, time(), 'reset', 'Split reset');
     // ----------------------
     delete_records('block_courseprefs_split', 'id', $id);
 }
Esempio n. 3
0
 public static function add_to_log($usersid = 0, $sectionsid = 0, $timestamp = 0, $action = '', $info = '')
 {
     $log = new CoursePrefsLog($usersid, $sectionsid, $timestamp, $action, $info);
     $log->save();
 }
Esempio n. 4
0
 /**
  * Finds and removes an entry in the database based on the id provided
  */
 static function deleteById($id)
 {
     $tt = get_record('block_courseprefs_teamteach', 'id', $id);
     // Add to the logs
     CoursePrefsLog::add_to_log($tt->usersid, $tt->sectionsid, time(), 'reset', 'Teamteach reset');
     delete_records('block_courseprefs_teamteach', 'id', $id);
 }
Esempio n. 5
0
 /**
  * Class method that finds and removes a crosslist from the database
  * based on the id provided
  */
 static function deleteById($id)
 {
     $cr = get_record('block_courseprefs_crosslist', 'id', $id);
     // Add to the logs
     CoursePrefsLog::add_to_log($cr->usersid, $cr->sectionsid, time(), 'reset', 'Crosslist reset');
     delete_records('block_courseprefs_crosslist', 'id', $id);
 }
Esempio n. 6
0
            $unwanted->save();
            CoursePrefsLog::add_to_log($user->getId(), $unwanted->getId(), time(), 'reset', 'Unwant reset');
        }
        $in = implode(',', $unwants);
        foreach (array('teachers', 'students') as $concern) {
            $sql = "UPDATE {$CFG->prefix}block_courseprefs_{$concern} t \n                        SET status='enroll'\n                        WHERE t.sectionsid IN ({$in})\n                          AND t.status = 'enrolled'";
            execute_sql($sql, false);
        }
    }
    // Iterate over new unwanted sections and store them in the database
    foreach ($form->selected_sections as $coursesid => $section_array) {
        foreach ($section_array as $sectionsid => $section) {
            try {
                $section->status = CoursePrefsSection::STATUS_UNWANT;
                update_record('block_courseprefs_sections', $section);
                CoursePrefsLog::add_to_log($user->getId(), $sectionsid, time(), 'unwant', 'unwant');
            } catch (Exception $e) {
                $heading = get_string('changes_not_saved', 'block_courseprefs');
                add_to_log(SITEID, 'courseprefs', 'update', 'blocks/courseprefs/unwanted.php', 'Unable to insert new user unwanted section preference; ' . "Course ID: {$section->coursesid}, " . "Section ID: {$sectionsid}");
            }
        }
    }
} else {
    if (!$form->is_submitted()) {
        // Set user preferences since the form wasn't submitted
        $unwanted_array = $user->getUnwanted();
        $form_defaults = array();
        foreach ($unwanted_array as $unwanted) {
            $form_defaults[UNWANTED_SECTION_FIELD . $unwanted->getId() . '_' . $unwanted->getCoursesId()] = true;
        }
        $form->set_data($form_defaults);