]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-14679 remoed all instances of get_records_list()
authorskodak <skodak>
Sun, 1 Jun 2008 15:42:48 +0000 (15:42 +0000)
committerskodak <skodak>
Sun, 1 Jun 2008 15:42:48 +0000 (15:42 +0000)
17 files changed:
blocks/quiz_results/block_quiz_results.php
course/import/activities/mod.php
grade/report/grader/ajaxlib.php
grade/report/grader/lib.php
lib/dml/moodle_database.php
mod/hotpot/lib.php
mod/quiz/restorelibpre15.php
mod/survey/download.php
mod/survey/graph.php
mod/survey/lib.php
mod/survey/report.php
mod/survey/view.php
question/type/match/questiontype.php
question/type/multianswer/questiontype.php
question/type/multichoice/questiontype.php
question/type/questiontype.php
search/documents/glossary_document.php

index ffca8f2c830138040cfe87c6c9e8f16ebd124f65..0f4a99b7b6eaf68508239ee87b0f699a2b84e429 100644 (file)
@@ -18,7 +18,7 @@ class block_quiz_results extends block_base {
     }
 
     function get_content() {
-        global $USER, $CFG;
+        global $USER, $CFG, $DB;
 
         if ($this->content !== NULL) {
             return $this->content;
@@ -282,7 +282,7 @@ class block_quiz_results extends block_base {
                 return $this->content;
             }
 
-            $mygroupsusers = get_records_list('groups_members', 'groupid', implode(',', array_keys($mygroups)), '', 'userid, id');
+            $mygroupsusers = $DB->get_records_list('groups_members', 'groupid', array_keys($mygroups), '', 'userid, id');
             // There should be at least one user there, ourselves. So no more tests.
 
             // Just filter out the grades belonging to other users, and proceed as if there were no groups
@@ -318,7 +318,7 @@ class block_quiz_results extends block_base {
 
             // Now grab all the users from the database
             $userids = array_merge(array_keys($best), array_keys($worst));
-            $users = get_records_list('user', 'id', implode(',',$userids), '', 'id, firstname, lastname, idnumber');
+            $users = $DB->get_records_list('user', 'id', $userids, '', 'id, firstname, lastname, idnumber');
 
             // Ready for output!
 
index 2cdcab69e0a3ac185a23be1907643387f1fb2b1d..1fa142db19ee03e9aca84ce8090041425429e8dc 100644 (file)
 
     $strimport = get_string("importdata");
 
-    $tcourseids = '';
+    $tcourseids = array();
 
     if ($teachers = get_user_capability_course('moodle/course:update')) {
         foreach ($teachers as $teacher) {
             if ($teacher->id != $course->id && $teacher->id != SITEID){
-                $tcourseids .= $teacher->id.',';
+                $tcourseids[] = $teacher->id;
             }
         }
     }
 
     $taught_courses = array();
     if (!empty($tcourseids)) {
-        $tcourseids = substr($tcourseids,0,-1);
-        $taught_courses = get_records_list('course', 'id', $tcourseids);
+        $taught_courses = $DB->get_records_list('course', 'id', $tcourseids);
     }
 
     if (!empty($creator)) {
index 47358a16145aab1f39b6c006e8c148ef1a63b2a7..ec3e61a09de5ba04821a6eb4bb6d0530432c1ee1 100644 (file)
@@ -73,6 +73,8 @@ class grade_report_grader_ajax extends grade_report_grader {
      * @return array
      */
     function get_scales_array() {
+        global $DB;
+
         if (empty($this->gtree->items)) {
             return false;
         }
@@ -81,18 +83,17 @@ class grade_report_grader_ajax extends grade_report_grader {
             return $this->scales_array;
         }
 
-        $scales_list = '';
+        $scales_list = array();
         $scales_array = array();
         
         foreach ($this->gtree->items as $item) {
             if (!empty($item->scaleid)) {
-                $scales_list .= "$item->scaleid,";
+                $scales_list[] = $item->scaleid;
             }
         }
         
         if (!empty($scales_list)) {
-            $scales_list = substr($scales_list, 0, -1);
-            $scales_array = get_records_list('scale', 'id', $scales_list);
+            $scales_array = $DB->get_records_list('scale', 'id', $scales_list);
             $this->scales_array = $scales_array;
             return $scales_array;
         } else {
index 5487d67325202f15b11fb8e1ae3311fead7b0cb1..bfeaa9522e57aaf506cc4d1d6f4909faaac78c50 100644 (file)
@@ -645,7 +645,7 @@ class grade_report_grader extends grade_report {
      * @return string HTML
      */
     function get_studentshtml() {
-        global $CFG, $USER;
+        global $CFG, $USER, $DB;
 
         $studentshtml = '';
         $strfeedback  = $this->get_lang_string("feedback");
@@ -656,12 +656,12 @@ class grade_report_grader extends grade_report {
         $numusers      = count($this->users);
 
         // Preload scale objects for items with a scaleid
-        $scales_list = '';
+        $scales_list = array();
         $tabindices = array();
 
         foreach ($this->gtree->items as $item) {
             if (!empty($item->scaleid)) {
-                $scales_list .= "$item->scaleid,";
+                $scales_list[] = $item->scaleid;
             }
 
             $tabindices[$item->id]['grade'] = $gradetabindex;
@@ -671,8 +671,7 @@ class grade_report_grader extends grade_report {
         $scales_array = array();
 
         if (!empty($scales_list)) {
-            $scales_list = substr($scales_list, 0, -1);
-            $scales_array = get_records_list('scale', 'id', $scales_list);
+            $scales_array = $DB->get_records_list('scale', 'id', $scales_list);
         }
         
         $row_classes = array(' even ', ' odd ');
index cb21e8eb859e85e00585de65e2a20a260c7e6573..7480eab238840e2e84e2c252d2f6eacb237eaefc 100644 (file)
@@ -578,7 +578,7 @@ abstract class moodle_database {
      *   array.
      * @return mixed an array of objects, or empty array if no records were found, or false if an error occured.
      */
-    public function get_records_list($table, $field, array $values=null, $sort='', $fields='*', $limitfrom=0, $limitnum=0) {
+    public function get_records_list($table, $field, array $values, $sort='', $fields='*', $limitfrom=0, $limitnum=0) {
         $params = array();
         $select = array();
         $values = (array)$values;
@@ -593,6 +593,10 @@ abstract class moodle_database {
                 $params[] = $value;
             }
         }
+        if (empty($select)) {
+            // nothing to return
+            return array();
+        }
         $select = implode(" AND ", $select);
         return $this->get_records_select($table, $select, $params, $sort, $fields, $limitfrom, $limitnum);
     }
index 7208364b9bac192c0e3fe66459e25d811fe12d39..47d15b2368fb440b3dfdc5032a9a94c9013844a2 100644 (file)
@@ -365,6 +365,7 @@ function hotpot_set_form_values(&$hotpot) {
     return $ok;
 }
 function hotpot_get_chain(&$cm) {
+    global $DB;
     // get details of course_modules in this section
     $course_module_ids = get_field('course_sections', 'sequence', 'id', $cm->section);
     if (empty($course_module_ids)) {
@@ -386,7 +387,7 @@ function hotpot_get_chain(&$cm) {
     if (empty($ids)) {
         $hotpots = array();
     } else {
-        $hotpots = get_records_list('hotpot', 'id', implode(',', $ids));
+        $hotpots = $DB->get_records_list('hotpot', 'id', $ids);
     }
 
     $found = false;
index 4fcb8756cce1b0890576fe97692d67006936f1db..35233b78b8db96dc178b27c96f48f8ab7e824497 100644 (file)
     }
 
     function quiz_restore_pre15_multianswer ($old_question_id,$new_question_id,$info,$restore) {
-
-        global $CFG;
+        global $CFG, $DB;
 
         $status = true;
 
             //Remap question_answers records from the original multianswer question
             //to their newly created question
             if ($newid) {
-                $answersdb = get_records_list('question_answers','id',$multianswer->answers);
+                $answersdb = $DB->get_records_list('question_answers','id', explode(',',$multianswer->answers));
                 foreach ($answersdb as $answerdb) {
                     set_field('question_answers','question',$newid,'id',$answerdb->id);
                 }
index fab478824ab338a135c0a6913fb3876abedbef74..130c7ee0ad5cab72866e78d3bc9275700ac66155 100644 (file)
@@ -40,7 +40,7 @@
 
 // Get all the questions and their proper order
 
-    $questions = get_records_list("survey_questions", "id", $survey->questions);
+    $questions = $DB->get_records_list("survey_questions", "id", explode(',', $survey->questions));
     $order = explode(",", $survey->questions);
 
     $virtualscales = false;
         }
     }
 
-    $fullorderlist = "";
+    $fullorderlist = array();
     foreach ($order as $key => $qid) {    // build up list of actual questions
         $question = $questions[$qid];
 
-        if (!(empty($fullorderlist))) {
-            $fullorderlist .= ",";
-        }
-
         if ($question->multi) {
             $addlist = $question->multi;
         } else {
         }
 
         if ($virtualscales && ($question->type < 0)) {        // only use them
-            $fullorderlist .= $addlist;
+            $fullorderlist[] = $addlist;
 
         } else if (!$virtualscales && ($question->type >= 0)){   // ignore them
-            $fullorderlist .= $addlist;
+            $fullorderlist[] = $addlist;
         }
     }
 
-    $fullquestions = get_records_list("survey_questions", "id", $fullorderlist);
+    $fullquestions = $DB->get_records_list("survey_questions", "id", $fullorderlist);
 
 //  Question type of multi-questions overrides the type of single questions
     foreach ($order as $key => $qid) {
index 71f2bf01fa33c315f6530e16b30a0ca856706e74..b839281179221231160c794e81dc9dc83bc339f1 100644 (file)
        $options = explode(",",$question->options);
        $questionorder = explode( ",", $question->multi);
 
-       $qqq = get_records_list("survey_questions", "id", $question->multi);
+       $qqq = $DB->get_records_list("survey_questions", "id", explode(',',$question->multi));
 
        foreach ($questionorder as $i => $val) {
            $names[$i] = get_string($qqq["$val"]->shorttext, "survey");
 
      case "overall.png":
 
-       $qqq = get_records_list("survey_questions", "id", $survey->questions);
+       $qqq = $DB->get_records_list("survey_questions", "id", explode(',', $survey->questions));
 
 
        foreach ($qqq as $key => $qq) {
 
      case "student.png":
 
-       $qqq = get_records_list("survey_questions", "id", $survey->questions);
+       $qqq = $DB->get_records_list("survey_questions", "id", explode(',', $survey->questions));
 
        foreach ($qqq as $key => $qq) {
            if ($qq->multi) {
        $options = explode(",",$question->options);
        $questionorder = explode( ",", $question->multi);
 
-       $qqq = get_records_list("survey_questions", "id", $question->multi);
+       $qqq = $DB->get_records_list("survey_questions", "id", explode(',', $question->multi));
 
        foreach ($questionorder as $i => $val) {
            $names[$i] = get_string($qqq[$val]->shorttext, "survey");
index a31ac8732908e75591d79ae3ff05b6bd68a23ed1..cf0ce82abe8e9d562379bc331121fb9b31b63805 100644 (file)
@@ -99,14 +99,14 @@ function survey_user_outline($course, $user, $mod, $survey) {
 
 
 function survey_user_complete($course, $user, $mod, $survey) {
-    global $CFG;
+    global $CFG, $DB;
 
     if (survey_already_done($survey->id, $user->id)) {
         if ($survey->template == SURVEY_CIQ) { // print out answers for critical incidents
             $table = NULL;
             $table->align = array("left", "left");
 
-            $questions = get_records_list("survey_questions", "id", $survey->questions);
+            $questions = $DB->get_records_list("survey_questions", "id", explode(',', $survey->questions));
             $questionorder = explode(",", $survey->questions);
             
             foreach ($questionorder as $key=>$val) {
@@ -363,7 +363,7 @@ function survey_shorten_name ($name, $numwords) {
 
 
 function survey_print_multi($question) {
-    global $USER, $DB, $qnum, $checklist;
+    global $USER, $DB, $qnum, $checklist, $DB;
 
     $stripreferthat = get_string("ipreferthat", "survey");
     $strifoundthat = get_string("ifoundthat", "survey");
@@ -395,7 +395,7 @@ function survey_print_multi($question) {
         echo "<tr><th scope=\"col\" colspan=\"7\">$question->intro</th></tr>\n"; 
     }
 
-    $subquestions = get_records_list("survey_questions", "id", $question->multi);
+    $subquestions = $DB->get_records_list("survey_questions", "id", explode(',', $question->multi));
 
     foreach ($subquestions as $q) {
         $qnum++;
index b18ee4b8ccbd37c3dfc0690bf26b3757309872a9..753e20f8c95fd835f6d25fb7d7d51aea91745425 100644 (file)
 
         } else {
 
-            $questions = get_records_list("survey_questions", "id", $survey->questions);
+            $questions = $DB->get_records_list("survey_questions", "id", explode(',', $survey->questions));
             $questionorder = explode(",", $survey->questions);
 
             foreach ($questionorder as $key => $val) {
       case "questions":
 
         if ($qid) {     // just get one multi-question
-            $questions = get_records_list("survey_questions", "id", $qid);
+            $questions = $DB->get_record("survey_questions", "id", $qid);
             $questionorder = explode(",", $qid);
 
             if ($scale = get_records("survey_questions", "multi", "$qid")) {
             }
 
         } else {        // get all top-level questions
-            $questions = get_records_list("survey_questions", "id", $survey->questions);
+            $questions = $DB->get_records_list("survey_questions", "id", explode(',',$survey->questions));
             $questionorder = explode(",", $survey->questions);
 
             print_heading($strallquestions);
                 if ($question->multi) {
                     echo "<h3>$question->text:</h3>";
 
-                    $subquestions = get_records_list("survey_questions", "id", $question->multi);
+                    $subquestions = $DB->get_records_list("survey_questions", "id", explode(',', $question->multi));
                     $subquestionorder = explode(",", $question->multi);
                     foreach ($subquestionorder as $key => $val) {
                         $subquestion = $subquestions[$val];
          print_user_picture($user->id, $course->id, $user->picture, true);
          echo "</p>";
 
-         $questions = get_records_list("survey_questions", "id", $survey->questions);
+         $questions = $DB->get_records_list("survey_questions", "id", explode(',', $survey->questions));
          $questionorder = explode(",", $survey->questions);
 
          if ($showscales) {
index bf1e346d10d04b2277c1f5a8e0ae94fc9447b436..1ae335a8e2776ee542cabca448cb9954e69d1b9a 100644 (file)
@@ -83,7 +83,7 @@
             print_box(format_text($survey->intro), 'generalbox', 'intro');
             print_spacer(30);
 
-            $questions = get_records_list("survey_questions", "id", $survey->questions);
+            $questions = $DB->get_records_list("survey_questions", "id", explode(',', $survey->questions));
             $questionorder = explode(",", $survey->questions);
             foreach ($questionorder as $key => $val) {
                 $question = $questions[$val];
     print_simple_box(format_text($survey->intro), 'center', '70%', '', 5, 'generalbox', 'intro');
 
 // Get all the major questions and their proper order
-    if (! $questions = get_records_list("survey_questions", "id", $survey->questions)) {
+    if (! $questions = $DB->get_records_list("survey_questions", "id", explode(',', $survey->questions))) {
         print_error("Couldn't find any questions in this survey!!");
     }
     $questionorder = explode( ",", $survey->questions);
index bf60e8f57c8c7d528a905c0210e7e6e04dec3a81..a15a6f83a1a333a886c92a20e93752bad83f1ddd 100644 (file)
@@ -632,11 +632,12 @@ class question_match_qtype extends default_questiontype {
      * @return bool success or failure.
      */
     function decode_content_links_caller($questionids, $restore, &$i) {
+        global $DB;
+
         $status = true;
 
         // Decode links in the question_match_sub table.
-        if ($subquestions = get_records_list('question_match_sub', 'question',
-                implode(',',  $questionids), '', 'id, questiontext')) {
+        if ($subquestions = $DB->get_records_list('question_match_sub', 'question', $questionids, '', 'id, questiontext')) {
 
             foreach ($subquestions as $subquestion) {
                 $questiontext = restore_decode_content_links_worker($subquestion->questiontext, $restore);
index 8f83fce8036891a1bd7f4b5e332e16ea32bbf64d..b2de038de94b1677e238e4e086d826d227e2a75d 100644 (file)
@@ -24,7 +24,7 @@ class embedded_cloze_qtype extends default_questiontype {
     }
 
     function get_question_options(&$question) {
-        global $QTYPES;
+        global $QTYPES, $DB;
 
         // Get relevant data indexed by positionkey from the multianswers table
         if (!$sequence = get_field('question_multianswer', 'sequence', 'question', $question->id)) {
@@ -32,7 +32,7 @@ class embedded_cloze_qtype extends default_questiontype {
             return false;
         }
 
-        $wrappedquestions = get_records_list('question', 'id', $sequence, 'id ASC');
+        $wrappedquestions = $DB->get_records_list('question', 'id', explode(',', $sequence), 'id ASC');
 
         // We want an array with question ids as index and the positions as values
         $sequence = array_flip(explode(',', $sequence));
@@ -58,7 +58,7 @@ class embedded_cloze_qtype extends default_questiontype {
     }
 
     function save_question_options($question) {
-        global $QTYPES;
+        global $QTYPES, $DB;
         $result = new stdClass;
 
         // This function needs to be able to handle the case where the existing set of wrapped
@@ -72,7 +72,7 @@ class embedded_cloze_qtype extends default_questiontype {
         if (!$oldwrappedids = get_field('question_multianswer', 'sequence', 'question', $question->id)) {
             $oldwrappedids = array();
         } else {
-            $oldwrappedids = get_records_list('question', 'id', $oldwrappedids, 'id ASC','id');
+            $oldwrappedids = $DB->get_records_list('question', 'id', explode(',', $oldwrappedids), 'id ASC','id');
         }
         $sequence = array();
         foreach($question->options->questions as $wrapped) {
index 5e0459c50ef7c1e9a3d621a5feeb8de7c36bb5d9..05dbddce52bd66bbe0d9ec556984cef6c6a9b46b 100644 (file)
@@ -556,11 +556,13 @@ class question_multichoice_qtype extends default_questiontype {
      * @return bool success or failure.
      */
     function decode_content_links_caller($questionids, $restore, &$i) {
+        global $DB;
+
         $status = true;
 
         // Decode links in the question_multichoice table.
-        if ($multichoices = get_records_list('question_multichoice', 'question',
-                implode(',',  $questionids), '', 'id, correctfeedback, partiallycorrectfeedback, incorrectfeedback')) {
+        if ($multichoices = $DB->get_records_list('question_multichoice', 'question',
+                $questionids, '', 'id, correctfeedback, partiallycorrectfeedback, incorrectfeedback')) {
 
             foreach ($multichoices as $multichoice) {
                 $correctfeedback = restore_decode_content_links_worker($multichoice->correctfeedback, $restore);
index f44fea03b8e7c67d7b2d5139defdef8b408357e1..8772214912313ee9c074d4f72a9b99469c3b7593 100644 (file)
@@ -1318,6 +1318,7 @@ class default_questiontype {
     * @param integer $cmid optional The id of the course module currently being edited
     */
     function print_replacement_options($question, $course, $cmid='0') {
+        global $DB;
 
         // Disable until the versioning code has been fixed
         if (true) {
@@ -1337,8 +1338,7 @@ class default_questiontype {
         foreach($instances as $instance) {
             $quizlist[$instance->quiz] = $instance->quiz;
         }
-        $quizlist = implode(',', $quizlist);
-        if(empty($quizlist) or !$quizzes = get_records_list('quiz', 'id', $quizlist)) {
+        if(empty($quizlist) or !$quizzes = $DB->get_records_list('quiz', 'id', $quizlist)) {
             $quizzes = array();
         }
 
index 8950a1c6e0c821f82382367e3086559e8fad3054..fc1d82bfb5aceedeba692e38bb3f68759e49f9fb 100644 (file)
@@ -122,6 +122,7 @@ function glossary_iterator() {
 * @return an array of searchable documents
 */
 function glossary_get_content_for_index(&$glossary) {
+    global $DB;
 
     // get context
     $coursemodule = get_field('modules', 'id', 'name', 'glossary');
@@ -144,8 +145,7 @@ function glossary_get_content_for_index(&$glossary) {
     
     // index comments
     if (count($entryIds)){
-        $entryIdList = implode(',', $entryIds);
-        $comments = get_records_list('glossary_comments', 'entryid', $entryIdList);
+        $comments = $DB->get_records_list('glossary_comments', 'entryid', $entryIds);
         if ($comments){
             foreach($comments as $comment) {
                 if (strlen($comment->entrycomment) > 0) {