From 44e1b7d7ff49501f344522543c6876a460fd3d1b Mon Sep 17 00:00:00 2001 From: skodak Date: Sun, 1 Jun 2008 15:42:48 +0000 Subject: [PATCH] MDL-14679 remoed all instances of get_records_list() --- blocks/quiz_results/block_quiz_results.php | 6 +++--- course/import/activities/mod.php | 7 +++---- grade/report/grader/ajaxlib.php | 9 +++++---- grade/report/grader/lib.php | 9 ++++----- lib/dml/moodle_database.php | 6 +++++- mod/hotpot/lib.php | 3 ++- mod/quiz/restorelibpre15.php | 5 ++--- mod/survey/download.php | 14 +++++--------- mod/survey/graph.php | 8 ++++---- mod/survey/lib.php | 8 ++++---- mod/survey/report.php | 10 +++++----- mod/survey/view.php | 4 ++-- question/type/match/questiontype.php | 5 +++-- question/type/multianswer/questiontype.php | 8 ++++---- question/type/multichoice/questiontype.php | 6 ++++-- question/type/questiontype.php | 4 ++-- search/documents/glossary_document.php | 4 ++-- 17 files changed, 59 insertions(+), 57 deletions(-) diff --git a/blocks/quiz_results/block_quiz_results.php b/blocks/quiz_results/block_quiz_results.php index ffca8f2c83..0f4a99b7b6 100644 --- a/blocks/quiz_results/block_quiz_results.php +++ b/blocks/quiz_results/block_quiz_results.php @@ -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! diff --git a/course/import/activities/mod.php b/course/import/activities/mod.php index 2cdcab69e0..1fa142db19 100644 --- a/course/import/activities/mod.php +++ b/course/import/activities/mod.php @@ -16,20 +16,19 @@ $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)) { diff --git a/grade/report/grader/ajaxlib.php b/grade/report/grader/ajaxlib.php index 47358a1614..ec3e61a09d 100644 --- a/grade/report/grader/ajaxlib.php +++ b/grade/report/grader/ajaxlib.php @@ -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 { diff --git a/grade/report/grader/lib.php b/grade/report/grader/lib.php index 5487d67325..bfeaa9522e 100644 --- a/grade/report/grader/lib.php +++ b/grade/report/grader/lib.php @@ -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 '); diff --git a/lib/dml/moodle_database.php b/lib/dml/moodle_database.php index cb21e8eb85..7480eab238 100644 --- a/lib/dml/moodle_database.php +++ b/lib/dml/moodle_database.php @@ -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); } diff --git a/mod/hotpot/lib.php b/mod/hotpot/lib.php index 7208364b9b..47d15b2368 100644 --- a/mod/hotpot/lib.php +++ b/mod/hotpot/lib.php @@ -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; diff --git a/mod/quiz/restorelibpre15.php b/mod/quiz/restorelibpre15.php index 4fcb8756cc..35233b78b8 100644 --- a/mod/quiz/restorelibpre15.php +++ b/mod/quiz/restorelibpre15.php @@ -940,8 +940,7 @@ } function quiz_restore_pre15_multianswer ($old_question_id,$new_question_id,$info,$restore) { - - global $CFG; + global $CFG, $DB; $status = true; @@ -1023,7 +1022,7 @@ //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); } diff --git a/mod/survey/download.php b/mod/survey/download.php index fab478824a..130c7ee0ad 100644 --- a/mod/survey/download.php +++ b/mod/survey/download.php @@ -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; @@ -52,14 +52,10 @@ } } - $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 { @@ -67,14 +63,14 @@ } 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) { diff --git a/mod/survey/graph.php b/mod/survey/graph.php index 71f2bf01fa..b839281179 100644 --- a/mod/survey/graph.php +++ b/mod/survey/graph.php @@ -136,7 +136,7 @@ $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"); @@ -258,7 +258,7 @@ 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) { @@ -399,7 +399,7 @@ 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) { @@ -572,7 +572,7 @@ $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"); diff --git a/mod/survey/lib.php b/mod/survey/lib.php index a31ac87329..cf0ce82abe 100644 --- a/mod/survey/lib.php +++ b/mod/survey/lib.php @@ -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 "$question->intro\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++; diff --git a/mod/survey/report.php b/mod/survey/report.php index b18ee4b8cc..753e20f8c9 100644 --- a/mod/survey/report.php +++ b/mod/survey/report.php @@ -145,7 +145,7 @@ } 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) { @@ -174,7 +174,7 @@ 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")) { @@ -185,7 +185,7 @@ } } 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); @@ -215,7 +215,7 @@ if ($question->multi) { echo "

$question->text:

"; - $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]; @@ -346,7 +346,7 @@ print_user_picture($user->id, $course->id, $user->picture, true); echo "

"; - $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) { diff --git a/mod/survey/view.php b/mod/survey/view.php index bf1e346d10..1ae335a8e2 100644 --- a/mod/survey/view.php +++ b/mod/survey/view.php @@ -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]; @@ -114,7 +114,7 @@ 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); diff --git a/question/type/match/questiontype.php b/question/type/match/questiontype.php index bf60e8f57c..a15a6f83a1 100644 --- a/question/type/match/questiontype.php +++ b/question/type/match/questiontype.php @@ -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); diff --git a/question/type/multianswer/questiontype.php b/question/type/multianswer/questiontype.php index 8f83fce803..b2de038de9 100644 --- a/question/type/multianswer/questiontype.php +++ b/question/type/multianswer/questiontype.php @@ -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) { diff --git a/question/type/multichoice/questiontype.php b/question/type/multichoice/questiontype.php index 5e0459c50e..05dbddce52 100644 --- a/question/type/multichoice/questiontype.php +++ b/question/type/multichoice/questiontype.php @@ -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); diff --git a/question/type/questiontype.php b/question/type/questiontype.php index f44fea03b8..8772214912 100644 --- a/question/type/questiontype.php +++ b/question/type/questiontype.php @@ -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(); } diff --git a/search/documents/glossary_document.php b/search/documents/glossary_document.php index 8950a1c6e0..fc1d82bfb5 100644 --- a/search/documents/glossary_document.php +++ b/search/documents/glossary_document.php @@ -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) { -- 2.39.5