}
function get_content() {
- global $USER, $CFG;
+ global $USER, $CFG, $DB;
if ($this->content !== NULL) {
return $this->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
// 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!
$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)) {
* @return array
*/
function get_scales_array() {
+ global $DB;
+
if (empty($this->gtree->items)) {
return false;
}
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 {
* @return string HTML
*/
function get_studentshtml() {
- global $CFG, $USER;
+ global $CFG, $USER, $DB;
$studentshtml = '';
$strfeedback = $this->get_lang_string("feedback");
$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;
$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 ');
* 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;
$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);
}
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)) {
if (empty($ids)) {
$hotpots = array();
} else {
- $hotpots = get_records_list('hotpot', 'id', implode(',', $ids));
+ $hotpots = $DB->get_records_list('hotpot', 'id', $ids);
}
$found = false;
}
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);
}
// 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) {
$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");
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) {
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");
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++;
} 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) {
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);
* @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);
}
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)) {
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));
}
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
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) {
* @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);
* @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) {
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();
}
* @return an array of searchable documents
*/
function glossary_get_content_for_index(&$glossary) {
+ global $DB;
// get context
$coursemodule = get_field('modules', 'id', 'name', '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) {