]> git.mjollnir.org Git - moodle.git/commitdiff
[multienrol]Improved get_student/teacher_courses() functions to cache enrolment type...
authormartinlanghoff <martinlanghoff>
Thu, 9 Mar 2006 03:15:42 +0000 (03:15 +0000)
committermartinlanghoff <martinlanghoff>
Thu, 9 Mar 2006 03:15:42 +0000 (03:15 +0000)
enrol/database/enrol.php
enrol/internal/enrol.php
enrol/ldap/enrol.php

index 0b8f3bc9adc74b7542d915dc3809794abd5d88d8..c4415802b490d7a2bf3db1a4e61907872404ae69 100644 (file)
@@ -37,7 +37,7 @@ function get_student_courses(&$user) {
 
                 foreach ($courselist as $coursefield) {
                     if ($course = get_record('course', $CFG->enrol_localcoursefield, $coursefield)) {
-                        $newstudent[$course->id] = true;             /// Add it to new list
+                        $newstudent[$course->id] = 'database';             /// Add it to new list
                         if (isset($user->student[$course->id])) {   /// We have it already
                             unset($user->student[$course->id]);       /// Remove from old list
                         } else {
@@ -51,11 +51,11 @@ function get_student_courses(&$user) {
                 foreach ($user->student as $courseid => $value) {
 
                     // unenrol only if it's a record pulled from external db
-                    if (get_record('user_students', 'userid', $user->id, 'course', $courseid, 'enrol', 'database')) {
+                    if ($value == 'database') {
                         unenrol_student($user->id, $courseid);       /// Unenrol the student
                         unset($user->student[$course->id]);           /// Remove from old list
                     } else {
-                        $newstudent[$courseid] = true;
+                        $newstudent[$courseid] = $value;
                     }
                 }
             }
index 0800229539b93ad4b82cc58a8f8b3227376a5dcd..9ebbfbb28c67ee306c92455b87873c19d24c822d 100644 (file)
@@ -59,7 +59,7 @@ function get_student_courses(&$user) {
 
                 if ( ( $student->timestart == 0 or ( $currenttime > $student->timestart )) and 
                      ( $student->timeend   == 0 or ( $currenttime < $student->timeend )) ) {
-                    $user->student[$student->course] = true;
+                    $user->student[$student->course] = $student->enrol;
                     $user->timeaccess[$student->course] = $student->timeaccess;
                 }
             }
@@ -89,7 +89,7 @@ function get_teacher_courses(&$user) {
             if ( ( $teacher->timestart == 0 or ( $currenttime > $teacher->timestart )) and 
                  ( $teacher->timeend   == 0 or ( $currenttime < $teacher->timeend )) ) {
 
-                $user->teacher[$teacher->course] = true;
+                $user->teacher[$teacher->course] = $teacher->enrol;
 
                 if ($teacher->editall) {
                     $user->teacheredit[$teacher->course] = true;
index ea37bc7c46e99e6180d4743536db33f4c0b07f89..0664da8f5728b0292533e0f81b3fb789c7396cc6 100755 (executable)
@@ -73,7 +73,7 @@ function get_user_courses(&$user, $type) {
                 error_log("User $user->username enrolled to a nonexistant course $course_ext_id \n");
             }
         } else { // the course object exists before we call...
-            if ($course_obj->visible==0) {
+            if ($course_obj->visible==0 && $user->{$type}[$course_obj->id] == 'ldap') {
                 // non-visible courses don't show up in the enrolled 
                 // array, so we should skip them -- 
                 unset($user->{$type}[$course_obj->id]);
@@ -83,7 +83,7 @@ function get_user_courses(&$user, $type) {
         
         // deal with enrolment in the moodle db
         if (!empty($course_obj)) { // does course exist now?     
-            if(isset($user->{$type}[$course_obj->id])){
+            if(isset($user->{$type}[$course_obj->id]) && $user->{$type}[$course_obj->id] == 'ldap'){
                 unset($user->{$type}[$course_obj->id]); // remove from old list
             } else {
                 $CFG->debug=10;
@@ -104,11 +104,8 @@ function get_user_courses(&$user, $type) {
     // ok, if there's any thing still left in the $user->student or $user->teacher
     // array, those are old enrolments that we want to remove (or are they?)
     if(!empty($user->{$type})){
-        $courses = array_keys($user->{$type});
-        foreach ($courses as $courseid){
-            // get the record if it's ldap
-            $rec = get_record('user_' . $type . 's', 'userid', $user->id, 'course', $courseid, 'enrol', 'ldap');
-            if(!empty($rec)){ // this was a legacy 
+        foreach ($user->{$type} as $courseid => $value){
+            if($value == 'ldap'){ // this was a legacy 
                 if ($type === 'student') { // enrol
                     unenrol_student($user->id, $courseid);
                 } else if ($type === 'teacher') {