]> git.mjollnir.org Git - moodle.git/commitdiff
Hopefully improve performance on site with lots of question categories Merged from...
authortjhunt <tjhunt>
Fri, 6 Oct 2006 16:48:54 +0000 (16:48 +0000)
committertjhunt <tjhunt>
Fri, 6 Oct 2006 16:48:54 +0000 (16:48 +0000)
lib/questionlib.php
question/export.php

index 71a1a7b2486afd6157180bd4bd8ca473619e9ca1..51b7b46febea0d1a9a6901ca9d8adf74899b531c 100644 (file)
@@ -1462,14 +1462,19 @@ function add_indented_names($categories) {
  * @param integer $selected optionally, the id of a category to be selected by default in the dropdown.
  */
 function question_category_select_menu($courseid, $published = false, $only_editable = false, $selected = "") {
-
+    global $CFG;
+    
     // get sql fragment for published
     $publishsql="";
     if ($published) {
-        $publishsql = "or publish=1";
+        $publishsql = " OR publish = 1";
     }
 
-    $categories = get_records_select("question_categories","course=$courseid $publishsql", 'parent, sortorder, name ASC');
+    $categories = get_records_sql("
+            SELECT cat.*, c.shortname AS coursename 
+            FROM {$CFG->prefix}question_categories cat, {$CFG->prefix}course c
+            WHERE c.id = cat.course AND (cat.course = $courseid $publishsql)
+            ORDER BY parent, sortorder, name ASC");
 
     $categories = add_indented_names($categories);
 
@@ -1488,22 +1493,27 @@ function question_category_select_menu($courseid, $published = false, $only_edit
     echo "</select>\n";
 }
 
+/**
+ * If the category is not from this course, and it is a published category,
+ * then return the course category name with the course shortname appended in
+ * brackets. Otherwise, just return the category name.
+ */
 function question_category_coursename($category, $courseid = 0) {
-/// if the category is not from this course and is published , adds on the course
-/// name
     $cname = (isset($category->indentedname)) ? $category->indentedname : $category->name;
     if ($category->course != $courseid && $category->publish) {
-        if ($catcourse=get_record("course","id",$category->course)) {
-            $cname .= " ($catcourse->shortname) ";
+        if (!empty($category->coursename)) {
+            $coursename = $category->coursename;
+        } else {
+            $coursename = get_field('course', 'shortname', 'id', $category->course);
         }
+        $cname .= " ($coursename)";
     }
     return $cname;
 }
 
-
 /**
-* Returns a comma separated list of ids of the category and all subcategories
-*/
+ * Returns a comma separated list of ids of the category and all subcategories
+ */
 function question_categorylist($categoryid) {
     // returns a comma separated list of ids of the category and all subcategories
     $categorylist = $categoryid;
index 7ff74b57a8a795173116add3fcf2e86d7c28390e..201a70b93e97011206f0d1fe2e5069c4106eb9d8 100644 (file)
         $exportfilename = default_export_filename($course, $category);
     }
 
-    /// Get all the existing categories now
-    if (!$categories = get_records_select("question_categories", "course = '{$course->id}' OR publish = '1'", "parent, sortorder, name ASC")) {
-        error("Could not find any question categories!");
-    }
-    $categories = add_indented_names($categories);
-    foreach ($categories as $key => $cat) {
-       if ($catcourse = get_record("course", "id", $cat->course)) {
-           if ($cat->publish && $cat->course != $course->id) {
-               $cat->indentedname .= " ($catcourse->shortname)";
-           }
-           $catmenu[$cat->id] = $cat->indentedname;
-       }
-    }
-    
     print_heading_with_help($strexportquestions, "export", "quiz");
 
     print_simple_box_start("center");
         echo question_category_coursename($category);
         echo " <input type=\"hidden\" name=\"category\" value=\"$category->id\" />";
     } else { // no category specified, let user choose
-        choose_from_menu($catmenu, "category", $category->id, "");
+        question_category_select_menu($course->id, true, false, $category->id);
     }
     //echo str_replace('&nbsp;', '', $category->name) . " ($categorycourse->shortname)";
     echo "</td></tr>\n";