]> git.mjollnir.org Git - moodle.git/commitdiff
change restore code to use the more efficient get_user_courses_bycap
authortoyomoyo <toyomoyo>
Thu, 20 Sep 2007 09:16:49 +0000 (09:16 +0000)
committertoyomoyo <toyomoyo>
Thu, 20 Sep 2007 09:16:49 +0000 (09:16 +0000)
backup/restore_check.html
backup/restore_form.html
lib/datalib.php

index a0f3940060cb57595138153d6b37b611f68708c9..2bf20935d9418a4b553a3fc28fbbe2382d0509a8 100644 (file)
         }
     }
 
+
+
+    // Non-cached - get accessinfo
+    if (isset($USER->access)) {
+        $accessinfo = $USER->access;
+    } else {
+        $accessinfo = get_user_access_sitewide($USER->id);
+    }
+    $mycourses = get_user_courses_bycap($USER->id, 'moodle/site:restore', $accessinfo, true, 'c.sortorder ASC',  array('id', 'fullname', 'shortname', 'visible'));
+
     //Now, select the course if needed
     //if (($restore->restoreto == 0 or $restore->restoreto == 1) and ($restore->course_id == 0) and get_capability_courses('moodle/site:restore')) {
-    if (($restore->restoreto == 0 or $restore->restoreto == 1) and ($restore->course_id == 0)) {
+    if (($restore->restoreto == 0 or $restore->restoreto == 1) and ($restore->course_id == 0) && count($mycourses) > 1) {
 
-        if ($courses = get_courses("all","c.fullname","c.id,c.fullname,c.shortname,c.visible")) {
+        if ($courses = $mycourses) {
             print_heading(get_string("choosecourse"));
             print_simple_box_start("center");
             foreach ($courses as $course) {
index 92b1d963fe1a569b3d62797a43ae7105a724c5d2..83b5f14cf043974801ac8c69169aa099bc34c551 100644 (file)
@@ -193,14 +193,20 @@ function selectItemInCheckboxByName(formId, checkName, checked ) {
      * if user has course:create in any category, we show
      *      newcourse
      */
-
-    //$mycourses = get_capability_courses('moodle/site:restore');
-
+     
+    // Non-cached - get accessinfo
+    if (isset($USER->access)) {
+        $accessinfo = $USER->access;
+    } else {
+        $accessinfo = get_user_access_sitewide($USER->id);
+    }
+    
+    $mycourses = get_user_courses_bycap($USER->id, 'moodle/site:restore', $accessinfo, true);
     // if the user can manage 2 or more courses,
     // or if the only course the user can manage is not the current course
     // we show options for existing courses
-    if (user_can_create_courses()) { // this is not entirely accurate but much faster
-    //if (count($mycourses) > 1 || !in_array($id, $mycourses)) {
+    
+    if (count($mycourses) > 1) {
         // if user can manage more than 1 course, or if user can restore to a single different course
         $restore_restoreto_options[0] = get_string("existingcoursedeleting");
         $restore_restoreto_options[1] = get_string("existingcourseadding");
index 7f13fa084ebacb849783dde4f293feadf97c73f6..7f176fd23e4fdefada4b01da590e7f8bf395daf6 100644 (file)
@@ -2134,30 +2134,6 @@ function xmldb_debug($message, $object) {
     debugging($message, DEBUG_DEVELOPER);
 }
 
-/**
- * Get the lists of courses the current user has $cap capability in
- * I am not sure if this is needed, it loops through all courses so
- * could cause performance problems.
- * If it's not used, we can use a faster function to detect
- * capability in restorelib.php
- * @param string $cap
- * @return array
- */
-function get_capability_courses($cap) {
-    global $USER;
-
-    $mycourses = array();
-    if ($courses = get_records('course')) {
-        foreach ($courses as $course) {
-            if (has_capability($cap, get_context_instance(CONTEXT_COURSE, $course->id))) {
-                $mycourses[] = $course->id;
-            }
-        }
-    }
-
-    return $mycourses;
-}
-
 /**
  * true or false function to see if user can create any courses at all
  * @return bool