Skip to content

Commit

Permalink
MDL-14679 remoed all instances of get_records_list()
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Jun 1, 2008
1 parent 29c1951 commit 44e1b7d
Show file tree
Hide file tree
Showing 17 changed files with 59 additions and 57 deletions.
6 changes: 3 additions & 3 deletions blocks/quiz_results/block_quiz_results.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function applicable_formats() {
}

function get_content() {
global $USER, $CFG;
global $USER, $CFG, $DB;

if ($this->content !== NULL) {
return $this->content;
Expand Down Expand Up @@ -282,7 +282,7 @@ function get_content() {
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
Expand Down Expand Up @@ -318,7 +318,7 @@ function get_content() {

// 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!

Expand Down
7 changes: 3 additions & 4 deletions course/import/activities/mod.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
9 changes: 5 additions & 4 deletions grade/report/grader/ajaxlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ function grade_report_grader_ajax($courseid, $gpr, $context, $page=null, $sortit
* @return array
*/
function get_scales_array() {
global $DB;

if (empty($this->gtree->items)) {
return false;
}
Expand All @@ -81,18 +83,17 @@ function get_scales_array() {
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 {
Expand Down
9 changes: 4 additions & 5 deletions grade/report/grader/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ function get_headerhtml() {
* @return string HTML
*/
function get_studentshtml() {
global $CFG, $USER;
global $CFG, $USER, $DB;

$studentshtml = '';
$strfeedback = $this->get_lang_string("feedback");
Expand All @@ -656,12 +656,12 @@ function get_studentshtml() {
$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;
Expand All @@ -671,8 +671,7 @@ function get_studentshtml() {
$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 ');
Expand Down
6 changes: 5 additions & 1 deletion lib/dml/moodle_database.php
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ public function get_records($table, array $conditions=null, $sort='', $fields='*
* 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;
Expand All @@ -593,6 +593,10 @@ public function get_records_list($table, $field, array $values=null, $sort='', $
$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);
}
Expand Down
3 changes: 2 additions & 1 deletion mod/hotpot/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions mod/quiz/restorelibpre15.php
Original file line number Diff line number Diff line change
Expand Up @@ -940,8 +940,7 @@ function quiz_restore_pre15_calculated ($old_question_id,$new_question_id,$info,
}

function quiz_restore_pre15_multianswer ($old_question_id,$new_question_id,$info,$restore) {

global $CFG;
global $CFG, $DB;

$status = true;

Expand Down Expand Up @@ -1023,7 +1022,7 @@ function quiz_restore_pre15_multianswer ($old_question_id,$new_question_id,$info
//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);
}
Expand Down
14 changes: 5 additions & 9 deletions mod/survey/download.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -52,29 +52,25 @@
}
}

$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 {
$addlist = $qid;
}

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) {
Expand Down
8 changes: 4 additions & 4 deletions mod/survey/graph.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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");
Expand Down
8 changes: 4 additions & 4 deletions mod/survey/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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++;
Expand Down
10 changes: 5 additions & 5 deletions mod/survey/report.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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")) {
Expand All @@ -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);
Expand Down Expand Up @@ -215,7 +215,7 @@
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];
Expand Down Expand Up @@ -346,7 +346,7 @@
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) {
Expand Down
4 changes: 2 additions & 2 deletions mod/survey/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions question/type/match/questiontype.php
Original file line number Diff line number Diff line change
Expand Up @@ -632,11 +632,12 @@ function restore_recode_answer($state, $restore) {
* @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);
Expand Down
8 changes: 4 additions & 4 deletions question/type/multianswer/questiontype.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ function name() {
}

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)) {
notify('Error: Cloze question '.$question->id.' is missing question options!');
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));
Expand All @@ -58,7 +58,7 @@ function get_question_options(&$question) {
}

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
Expand All @@ -72,7 +72,7 @@ function save_question_options($question) {
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) {
Expand Down
Loading

0 comments on commit 44e1b7d

Please sign in to comment.