From 646fc29036d11295583e006232dd07db59015cd1 Mon Sep 17 00:00:00 2001 From: jerome Date: Fri, 6 Jun 2008 04:03:40 +0000 Subject: [PATCH] MDL-15112 lesson dml conversion --- mod/lesson/action/addbranchtable.php | 6 +- mod/lesson/action/addcluster.php | 12 +-- mod/lesson/action/addendofbranch.php | 14 +-- mod/lesson/action/addendofcluster.php | 10 +- mod/lesson/action/addpage.php | 6 +- mod/lesson/action/confirmdelete.php | 7 +- mod/lesson/action/continue.php | 41 +++++---- mod/lesson/action/delete.php | 24 ++--- mod/lesson/action/editpage.php | 8 +- mod/lesson/action/insertpage.php | 23 ++--- mod/lesson/action/move.php | 7 +- mod/lesson/action/moveit.php | 38 ++++---- mod/lesson/action/updatepage.php | 19 ++-- mod/lesson/backuplib.php | 74 ++++++++------- mod/lesson/edit.php | 13 +-- mod/lesson/essay.php | 78 +++++++++------- mod/lesson/format.php | 17 ++-- mod/lesson/grade.php | 4 +- mod/lesson/highscores.php | 35 +++---- mod/lesson/import.php | 4 +- mod/lesson/importppt.php | 24 +++-- mod/lesson/index.php | 2 +- mod/lesson/lib.php | 120 ++++++++++++++---------- mod/lesson/locallib.php | 126 ++++++++++++++++---------- mod/lesson/mediafile.php | 4 +- mod/lesson/mod_form.php | 4 +- mod/lesson/report.php | 72 ++++++++------- mod/lesson/tabs.php | 2 +- mod/lesson/view.php | 97 +++++++++++--------- 29 files changed, 503 insertions(+), 388 deletions(-) diff --git a/mod/lesson/action/addbranchtable.php b/mod/lesson/action/addbranchtable.php index 7b1ffba6dde..e8f1148cb0a 100644 --- a/mod/lesson/action/addbranchtable.php +++ b/mod/lesson/action/addbranchtable.php @@ -19,14 +19,14 @@ $jump[LESSON_PREVIOUSPAGE] = get_string("previouspage", "lesson"); $jump[LESSON_EOL] = get_string("endoflesson", "lesson"); if (!optional_param('firstpage', 0, PARAM_INT)) { - if (!$apageid = get_field("lesson_pages", "id", "lessonid", $lesson->id, "prevpageid", 0)) { + if (!$apageid = $DB->get_field("lesson_pages", "id", array("lessonid" => $lesson->id, "prevpageid" => 0))) { print_error("Add page: first page not found"); } while (true) { if ($apageid) { - $title = get_field("lesson_pages", "title", "id", $apageid); + $title = $DB->get_field("lesson_pages", "title", array("id" => $apageid)); $jump[$apageid] = $title; - $apageid = get_field("lesson_pages", "nextpageid", "id", $apageid); + $apageid = $DB->get_field("lesson_pages", "nextpageid", array("id" => $apageid)); } else { // last page reached break; diff --git a/mod/lesson/action/addcluster.php b/mod/lesson/action/addcluster.php index fc8025ea247..e61fdf75300 100644 --- a/mod/lesson/action/addcluster.php +++ b/mod/lesson/action/addcluster.php @@ -15,11 +15,11 @@ $timenow = time(); if ($pageid == 0) { - if (!$page = get_record("lesson_pages", "prevpageid", 0, "lessonid", $lesson->id)) { + if (!$page = $DB->get_record("lesson_pages", array("prevpageid" => 0, "lessonid" => $lesson->id))) { print_error("Error: Add cluster: page record not found"); } } else { - if (!$page = get_record("lesson_pages", "id", $pageid)) { + if (!$page = $DB->get_record("lesson_pages", array("id" => $pageid))) { print_error("Error: Add cluster: page record not found"); } } @@ -35,12 +35,12 @@ $newpage->timecreated = $timenow; $newpage->title = get_string("clustertitle", "lesson"); $newpage->contents = get_string("clustertitle", "lesson"); - if (!$newpageid = insert_record("lesson_pages", $newpage)) { + if (!$newpageid = $DB->insert_record("lesson_pages", $newpage)) { print_error("Insert page: new page not inserted"); } // update the linked list... if ($pageid != 0) { - if (!set_field("lesson_pages", "nextpageid", $newpageid, "id", $pageid)) { + if (!$DB->set_field("lesson_pages", "nextpageid", $newpageid, array("id" => $pageid))) { print_error("Add cluster: unable to update link"); } } @@ -50,7 +50,7 @@ } if ($page->nextpageid) { // the new page is not the last page - if (!set_field("lesson_pages", "prevpageid", $newpageid, "id", $page->nextpageid)) { + if (!$DB->set_field("lesson_pages", "prevpageid", $newpageid, array("id" => $page->nextpageid))) { print_error("Insert page: unable to update previous link"); } } @@ -60,7 +60,7 @@ $newanswer->pageid = $newpageid; $newanswer->timecreated = $timenow; $newanswer->jumpto = LESSON_CLUSTERJUMP; - if(!$newanswerid = insert_record("lesson_answers", $newanswer)) { + if(!$newanswerid = $DB->insert_record("lesson_answers", $newanswer)) { print_error("Add cluster: answer record not inserted"); } lesson_set_message(get_string('addedcluster', 'lesson'), 'notifysuccess'); diff --git a/mod/lesson/action/addendofbranch.php b/mod/lesson/action/addendofbranch.php index 83c02501727..3839b9befe9 100644 --- a/mod/lesson/action/addendofbranch.php +++ b/mod/lesson/action/addendofbranch.php @@ -14,17 +14,17 @@ $timenow = time(); // the new page is not the first page (end of branch always comes after an existing page) - if (!$page = get_record("lesson_pages", "id", $pageid)) { + if (!$page = $DB->get_record("lesson_pages", array("id" => $pageid))) { print_error("Add end of branch: page record not found"); } // chain back up to find the (nearest branch table) $btpageid = $pageid; - if (!$btpage = get_record("lesson_pages", "id", $btpageid)) { + if (!$btpage = $DB->get_record("lesson_pages", array("id" => $btpageid))) { print_error("Add end of branch: btpage record not found"); } while (($btpage->qtype != LESSON_BRANCHTABLE) AND ($btpage->prevpageid > 0)) { $btpageid = $btpage->prevpageid; - if (!$btpage = get_record("lesson_pages", "id", $btpageid)) { + if (!$btpage = $DB->get_record("lesson_pages", array("id" => $btpageid))) { print_error("Add end of branch: btpage record not found"); } } @@ -37,16 +37,16 @@ $newpage->timecreated = $timenow; $newpage->title = get_string("endofbranch", "lesson"); $newpage->contents = get_string("endofbranch", "lesson"); - if (!$newpageid = insert_record("lesson_pages", $newpage)) { + if (!$newpageid = $DB->insert_record("lesson_pages", $newpage)) { print_error("Insert page: new page not inserted"); } // update the linked list... - if (!set_field("lesson_pages", "nextpageid", $newpageid, "id", $pageid)) { + if (!$DB->set_field("lesson_pages", "nextpageid", $newpageid, array("id" => $pageid))) { print_error("Add end of branch: unable to update link"); } if ($page->nextpageid) { // the new page is not the last page - if (!set_field("lesson_pages", "prevpageid", $newpageid, "id", $page->nextpageid)) { + if (!$DB->set_field("lesson_pages", "prevpageid", $newpageid, array("id" => $page->nextpageid))) { print_error("Insert page: unable to update previous link"); } } @@ -56,7 +56,7 @@ $newanswer->pageid = $newpageid; $newanswer->timecreated = $timenow; $newanswer->jumpto = $btpageid; - if(!$newanswerid = insert_record("lesson_answers", $newanswer)) { + if(!$newanswerid = $DB->insert_record("lesson_answers", $newanswer)) { print_error("Add end of branch: answer record not inserted"); } diff --git a/mod/lesson/action/addendofcluster.php b/mod/lesson/action/addendofcluster.php index 23a085259b9..9656fe92d92 100644 --- a/mod/lesson/action/addendofcluster.php +++ b/mod/lesson/action/addendofcluster.php @@ -14,7 +14,7 @@ $timenow = time(); // the new page is not the first page (end of cluster always comes after an existing page) - if (!$page = get_record("lesson_pages", "id", $pageid)) { + if (!$page = $DB->get_record("lesson_pages", array("id" => $pageid))) { print_error("Error: Could not find page"); } @@ -28,16 +28,16 @@ $newpage->timecreated = $timenow; $newpage->title = get_string("endofclustertitle", "lesson"); $newpage->contents = get_string("endofclustertitle", "lesson"); - if (!$newpageid = insert_record("lesson_pages", $newpage)) { + if (!$newpageid = $DB->insert_record("lesson_pages", $newpage)) { print_error("Insert page: end of cluster page not inserted"); } // update the linked list... - if (!set_field("lesson_pages", "nextpageid", $newpageid, "id", $pageid)) { + if (!$DB->set_field("lesson_pages", "nextpageid", $newpageid, array("id" => $pageid))) { print_error("Add end of cluster: unable to update link"); } if ($page->nextpageid) { // the new page is not the last page - if (!set_field("lesson_pages", "prevpageid", $newpageid, "id", $page->nextpageid)) { + if (!$DB->set_field("lesson_pages", "prevpageid", $newpageid, array("id" => $page->nextpageid))) { print_error("Insert end of cluster: unable to update previous link"); } } @@ -47,7 +47,7 @@ $newanswer->pageid = $newpageid; $newanswer->timecreated = $timenow; $newanswer->jumpto = LESSON_NEXTPAGE; - if(!$newanswerid = insert_record("lesson_answers", $newanswer)) { + if(!$newanswerid = $DB->insert_record("lesson_answers", $newanswer)) { print_error("Add end of cluster: answer record not inserted"); } lesson_set_message(get_string('addedendofcluster', 'lesson'), 'notifysuccess'); diff --git a/mod/lesson/action/addpage.php b/mod/lesson/action/addpage.php index 1d4130a89e1..8b783808f44 100644 --- a/mod/lesson/action/addpage.php +++ b/mod/lesson/action/addpage.php @@ -27,13 +27,13 @@ } if (!optional_param('firstpage', 0, PARAM_INT)) { $linkadd = ""; - $apageid = get_field("lesson_pages", "id", "lessonid", $lesson->id, "prevpageid", 0); + $apageid = $DB->get_field("lesson_pages", "id", array("lessonid" => $lesson->id, "prevpageid" => 0)); while (true) { if ($apageid) { - $title = get_field("lesson_pages", "title", "id", $apageid); + $title = $DB->get_field("lesson_pages", "title", array("id" => $apageid)); $jump[$apageid] = strip_tags(format_string($title,true)); - $apageid = get_field("lesson_pages", "nextpageid", "id", $apageid); + $apageid = $DB->get_field("lesson_pages", "nextpageid", array("id" => $apageid)); } else { // last page reached break; diff --git a/mod/lesson/action/confirmdelete.php b/mod/lesson/action/confirmdelete.php index 580d44bd928..70a4b11ca62 100644 --- a/mod/lesson/action/confirmdelete.php +++ b/mod/lesson/action/confirmdelete.php @@ -9,16 +9,17 @@ confirm_sesskey(); $pageid = required_param('pageid', PARAM_INT); - if (!$thispage = get_record("lesson_pages", "id", $pageid)) { + if (!$thispage = $DB->get_record("lesson_pages", array ("id" => $pageid))) { print_error("Confirm delete: the page record not found"); } print_heading(get_string("deletingpage", "lesson", format_string($thispage->title))); // print the jumps to this page - if ($answers = get_records_select("lesson_answers", "lessonid = $lesson->id AND jumpto = $pageid + 1")) { + $params = array("lessonid" => $lesson->id, "pageid" => $pageid); + if ($answers = $DB->get_records_select("lesson_answers", "lessonid = :lessonid AND jumpto = :pageid + 1", $params)) { print_heading(get_string("thefollowingpagesjumptothispage", "lesson")); echo "

\n"; foreach ($answers as $answer) { - if (!$title = get_field("lesson_pages", "title", "id", $answer->pageid)) { + if (!$title = $DB->get_field("lesson_pages", "title", array("id" => $answer->pageid))) { print_error("Confirm delete: page title not found"); } echo $title."
\n"; diff --git a/mod/lesson/action/continue.php b/mod/lesson/action/continue.php index c4cb12144ea..e34a6e4df3d 100644 --- a/mod/lesson/action/continue.php +++ b/mod/lesson/action/continue.php @@ -21,7 +21,8 @@ // get time information for this user $timer = new stdClass; if (!has_capability('mod/lesson:manage', $context)) { - if (!$timer = get_records_select('lesson_timer', "lessonid = $lesson->id AND userid = $USER->id", 'starttime')) { + $params = array ("lessonid" => $lesson->id, "userid" => $USER->id); + if (!$timer = $DB->get_records_select('lesson_timer', "lessonid = :lessonid AND userid = :userid", $params, 'starttime')) { print_error('Error: could not find records'); } else { $timer = array_pop($timer); // this will get the latest start time record @@ -42,14 +43,14 @@ } $timer->lessontime = time(); - if (!update_record("lesson_timer", $timer)) { + if (!$DB->update_record("lesson_timer", $timer)) { print_error("Error: could not update lesson_timer table"); } } // record answer (if necessary) and show response (if none say if answer is correct or not) $pageid = required_param('pageid', PARAM_INT); - if (!$page = get_record("lesson_pages", "id", $pageid)) { + if (!$page = $DB->get_record("lesson_pages", array("id" => $pageid))) { print_error("Continue: Page record not found"); } // set up some defaults @@ -68,7 +69,7 @@ } $useranswer = clean_param($useranswer, PARAM_RAW); - if (!$answers = get_records("lesson_answers", "pageid", $pageid, "id")) { + if (!$answers = $DB->get_records("lesson_answers", array("pageid" => $pageid), "id")) { print_error("Continue: No answers found"); } $correctanswer = false; @@ -93,7 +94,7 @@ } $useranswer = s(stripslashes(clean_param($useranswer, PARAM_RAW))); $userresponse = addslashes($useranswer); - if (!$answers = get_records("lesson_answers", "pageid", $pageid, "id")) { + if (!$answers = $DB->get_records("lesson_answers", array("pageid" => $pageid), "id")) { print_error("Continue: No answers found"); } $i=0; @@ -196,7 +197,7 @@ break; } $answerid = required_param('answerid', PARAM_INT); - if (!$answer = get_record("lesson_answers", "id", $answerid)) { + if (!$answer = $DB->get_record("lesson_answers", array("id" => $answerid))) { print_error("Continue: answer record not found"); } if (lesson_iscorrect($pageid, $answer->jumpto)) { @@ -229,7 +230,7 @@ // get what the user answered $userresponse = implode(",", $useranswers); // get the answers in a set order, the id order - if (!$answers = get_records("lesson_answers", "pageid", $pageid, "id")) { + if (!$answers = $DB->get_records("lesson_answers", array("pageid" => $pageid), "id")) { print_error("Continue: No answers found"); } $ncorrect = 0; @@ -344,7 +345,7 @@ break; } $answerid = required_param('answerid', PARAM_INT); - if (!$answer = get_record("lesson_answers", "id", $answerid)) { + if (!$answer = $DB->get_record("lesson_answers", array("id" => $answerid))) { print_error("Continue: answer record not found"); } if (lesson_iscorrect($pageid, $answer->jumpto)) { @@ -373,7 +374,7 @@ break; } - if (!$answers = get_records("lesson_answers", "pageid", $pageid, "id")) { + if (!$answers = $DB->get_records("lesson_answers", array("pageid" => $pageid), "id")) { print_error("Continue: No answers found"); } @@ -454,7 +455,7 @@ break; } $studentanswer = $userresponse = $useranswer; - if (!$answers = get_records("lesson_answers", "pageid", $pageid, "id")) { + if (!$answers = $DB->get_records("lesson_answers", array("pageid" => $pageid), "id")) { print_error("Continue: No answers found"); } foreach ($answers as $answer) { @@ -496,8 +497,9 @@ } else { $branchflag = 0; } - if ($grades = get_records_select("lesson_grades", "lessonid = $lesson->id AND userid = $USER->id", - "grade DESC")) { + $params = array ("lessonid" => $lesson->id, "userid" => $USER->id); + if ($grades = $DB->get_records_select("lesson_grades", "lessonid = :lessonid AND userid = :userid", + $params, "grade DESC")) { $retries = count($grades); } else { $retries = 0; @@ -510,7 +512,7 @@ $branch->flag = $branchflag; $branch->timeseen = time(); - if (!insert_record("lesson_branch", $branch)) { + if (!$DB->insert_record("lesson_branch", $branch)) { print_error("Error: could not insert row into lesson_branch table"); } @@ -570,7 +572,7 @@ if (isset($USER->modattempts[$lesson->id])) { $attempt->retry = $nretakes - 1; // they are going through on review, $nretakes will be too high } - if (!$newattemptid = insert_record("lesson_attempts", $attempt)) { + if (!$newattemptid = $DB->insert_record("lesson_attempts", $attempt)) { print_error("Continue: attempt not inserted"); } // "number of attempts remaining" message if $lesson->maxattempts > 1 @@ -599,7 +601,7 @@ if ($lesson->nextpagedefault) { // in Flash Card mode... // ... first get the page ids (lessonid the 5th param is needed to make get_records play) - $allpages = get_records("lesson_pages", "lessonid", $lesson->id, "id", "id,lessonid,qtype"); + $allpages = $DB->get_records("lesson_pages", array("lessonid" => $lesson->id), "id", "id,lessonid,qtype"); shuffle ($allpages); $found = false; if ($lesson->nextpagedefault == LESSON_UNSEENPAGE) { @@ -669,7 +671,7 @@ if ($response) { //optionally display question page title - //if ($title = get_field("lesson_pages", "title", "id", $pageid)) { + //if ($title = $DB->get_field("lesson_pages", "title", array("id" => $pageid))) { // print_heading($title); //} if ($lesson->review and !$correctanswer and !$isessayquestion) { @@ -705,7 +707,8 @@ $newpageid = LESSON_EOL; } else { $nretakes--; // make sure we are looking at the right try. - $attempts = get_records_select("lesson_attempts", "lessonid = $lesson->id AND userid = $USER->id AND retry = $nretakes", "timeseen", "id, pageid"); + $params = array ("lessonid" => $lesson->id, "userid" => $USER->id, "retry" => $nretakes); + $attempts = $DB->get_records_select("lesson_attempts", "lessonid = :lessonid AND userid = :userid AND retry = :retry", $params, "timeseen", "id, pageid"); $found = false; $temppageid = 0; foreach($attempts as $attempt) { @@ -720,13 +723,13 @@ } } } elseif ($newpageid != LESSON_CLUSTERJUMP && $pageid != 0 && $newpageid > 0) { // going to check to see if the page that the user is going to view next, is a cluster page. If so, dont display, go into the cluster. The $newpageid > 0 is used to filter out all of the negative code jumps. - if (!$page = get_record("lesson_pages", "id", $newpageid)) { + if (!$page = $DB->get_record("lesson_pages", array("id" => $newpageid))) { print_error("Error: could not find page"); } if ($page->qtype == LESSON_CLUSTER) { $newpageid = lesson_cluster_jump($lesson->id, $USER->id, $page->id); } elseif ($page->qtype == LESSON_ENDOFCLUSTER) { - $jump = get_field("lesson_answers", "jumpto", "pageid", $page->id, "lessonid", $lesson->id); + $jump = $DB->get_field("lesson_answers", "jumpto", array("pageid" => $page->id, "lessonid" => $lesson->id)); if ($jump == LESSON_NEXTPAGE) { if ($page->nextpageid == 0) { $newpageid = LESSON_EOL; diff --git a/mod/lesson/action/delete.php b/mod/lesson/action/delete.php index b747b50477d..81ee2893b81 100644 --- a/mod/lesson/action/delete.php +++ b/mod/lesson/action/delete.php @@ -9,46 +9,46 @@ confirm_sesskey(); $pageid = required_param('pageid', PARAM_INT); - if (!$thispage = get_record("lesson_pages", "id", $pageid)) { + if (!$thispage = $DB->get_record("lesson_pages", array("id" => $pageid))) { print_error("Delete: page record not found"); } // first delete all the associated records... - delete_records("lesson_attempts", "pageid", $pageid); + $DB->delete_records("lesson_attempts", array("pageid" => $pageid)); // ...now delete the answers... - delete_records("lesson_answers", "pageid", $pageid); + $DB->delete_records("lesson_answers", array("pageid" => $pageid)); // ..and the page itself - delete_records("lesson_pages", "id", $pageid); + $DB->delete_records("lesson_pages", array("id" => $pageid)); // repair the hole in the linkage if (!$thispage->prevpageid) { // this is the first page... - if (!$page = get_record("lesson_pages", "id", $thispage->nextpageid)) { + if (!$page = $DB->get_record("lesson_pages", array("id" => $thispage->nextpageid))) { print_error("Delete: next page not found"); } - if (!set_field("lesson_pages", "prevpageid", 0, "id", $page->id)) { + if (!$DB->set_field("lesson_pages", "prevpageid", 0, array("id" => $page->id))) { print_error("Delete: unable to set prevpage link"); } } elseif (!$thispage->nextpageid) { // this is the last page... - if (!$page = get_record("lesson_pages", "id", $thispage->prevpageid)) { + if (!$page = $DB->get_record("lesson_pages", array("id" => $thispage->prevpageid))) { print_error("Delete: prev page not found"); } - if (!set_field("lesson_pages", "nextpageid", 0, "id", $page->id)) { + if (!$DB->set_field("lesson_pages", "nextpageid", 0, array("id" => $page->id))) { print_error("Delete: unable to set nextpage link"); } } else { // page is in the middle... - if (!$prevpage = get_record("lesson_pages", "id", $thispage->prevpageid)) { + if (!$prevpage = $DB->get_record("lesson_pages", array("id" => $thispage->prevpageid))) { print_error("Delete: prev page not found"); } - if (!$nextpage = get_record("lesson_pages", "id", $thispage->nextpageid)) { + if (!$nextpage = $DB->get_record("lesson_pages", array("id" => $thispage->nextpageid))) { print_error("Delete: next page not found"); } - if (!set_field("lesson_pages", "nextpageid", $nextpage->id, "id", $prevpage->id)) { + if (!$DB->set_field("lesson_pages", "nextpageid", $nextpage->id, array("id" => $prevpage->id))) { print_error("Delete: unable to set next link"); } - if (!set_field("lesson_pages", "prevpageid", $prevpage->id, "id", $nextpage->id)) { + if (!$DB->set_field("lesson_pages", "prevpageid", $prevpage->id, array("id" => $nextpage->id))) { print_error("Delete: unable to set prev link"); } } diff --git a/mod/lesson/action/editpage.php b/mod/lesson/action/editpage.php index aee538b99b6..c431a82aad6 100644 --- a/mod/lesson/action/editpage.php +++ b/mod/lesson/action/editpage.php @@ -11,7 +11,7 @@ $pageid = required_param('pageid', PARAM_INT); $redirect = optional_param('redirect', '', PARAM_ALPHA); - if (!$page = get_record("lesson_pages", "id", $pageid)) { + if (!$page = $DB->get_record("lesson_pages", array("id" => $pageid))) { print_error("Edit page: page record not found"); } @@ -33,12 +33,12 @@ $jump[LESSON_CLUSTERJUMP] = get_string("clusterjump", "lesson"); } $jump[LESSON_EOL] = get_string("endoflesson", "lesson"); - if (!$apageid = get_field("lesson_pages", "id", "lessonid", $lesson->id, "prevpageid", 0)) { + if (!$apageid = $DB->get_field("lesson_pages", "id", array("lessonid" => $lesson->id, "prevpageid" => 0))) { print_error("Edit page: first page not found"); } while (true) { if ($apageid) { - if (!$apage = get_record("lesson_pages", "id", $apageid)) { + if (!$apage = $DB->get_record("lesson_pages", array("id" => $apageid))) { print_error("Edit page: apage record not found"); } // removed != LESSON_ENDOFBRANCH... @@ -161,7 +161,7 @@ echo "\n"; // get the answers in a set order, the id order - if ($answers = get_records("lesson_answers", "pageid", $page->id, "id")) { + if ($answers = $DB->get_records("lesson_answers", array("pageid" => $page->id), "id")) { foreach ($answers as $answer) { $flags = intval($answer->flags); // force into an integer $nplus1 = $n + 1; diff --git a/mod/lesson/action/insertpage.php b/mod/lesson/action/insertpage.php index aeda9b80c86..ac279383fc6 100644 --- a/mod/lesson/action/insertpage.php +++ b/mod/lesson/action/insertpage.php @@ -20,7 +20,7 @@ $newanswer = new stdClass; if ($form->pageid) { // the new page is not the first page - if (!$page = get_record("lesson_pages", "id", $form->pageid)) { + if (!$page = $DB->get_record("lesson_pages", array("id" => $form->pageid))) { print_error("Insert page: page record not found"); } $newpage->lessonid = clean_param($lesson->id, PARAM_INT); @@ -46,24 +46,25 @@ $newpage->title = clean_param($form->title, PARAM_CLEANHTML); $newpage->contents = trim($form->contents); $newpage->title = addslashes($newpage->title); - $newpageid = insert_record("lesson_pages", $newpage); + $newpageid = $DB->insert_record("lesson_pages", $newpage); if (!$newpageid) { print_error("Insert page: new page not inserted"); } // update the linked list (point the previous page to this new one) - if (!set_field("lesson_pages", "nextpageid", $newpageid, "id", $newpage->prevpageid)) { + if (!$DB->set_field("lesson_pages", "nextpageid", $newpageid, array("id" => $newpage->prevpageid))) { print_error("Insert page: unable to update next link"); } if ($page->nextpageid) { // new page is not the last page - if (!set_field("lesson_pages", "prevpageid", $newpageid, "id", $page->nextpageid)) { + if (!$DB->set_field("lesson_pages", "prevpageid", $newpageid, array("id" => $page->nextpageid))) { print_error("Insert page: unable to update previous link"); } } } else { // new page is the first page // get the existing (first) page (if any) - if (!$page = get_record_select("lesson_pages", "lessonid = $lesson->id AND prevpageid = 0")) { + $params = array ("lessonid" => $lesson->id, "prevpageid" => 0); + if (!$page = $DB->get_record_select("lesson_pages", "lessonid = :lessonid AND prevpageid = :prevpageid", $params)) { // there are no existing pages $newpage->lessonid = $lesson->id; $newpage->prevpageid = 0; // this is a first page @@ -88,7 +89,7 @@ $newpage->title = clean_param($form->title, PARAM_CLEANHTML); $newpage->contents = trim($form->contents); $newpage->title = addslashes($newpage->title); - $newpageid = insert_record("lesson_pages", $newpage); + $newpageid = $DB->insert_record("lesson_pages", $newpage); if (!$newpageid) { print_error("Insert page: new first page not inserted"); } @@ -117,12 +118,12 @@ $newpage->title = clean_param($form->title, PARAM_CLEANHTML); $newpage->contents = trim($form->contents); $newpage->title = addslashes($newpage->title); - $newpageid = insert_record("lesson_pages", $newpage); + $newpageid = $DB->insert_record("lesson_pages", $newpage); if (!$newpageid) { print_error("Insert page: first page not inserted"); } // update the linked list - if (!set_field("lesson_pages", "prevpageid", $newpageid, "id", $newpage->nextpageid)) { + if (!$DB->set_field("lesson_pages", "prevpageid", $newpageid, array("id" => $newpage->nextpageid))) { print_error("Insert page: unable to update link"); } } @@ -138,7 +139,7 @@ if (isset($form->score[0])) { $newanswer->score = clean_param($form->score[0], PARAM_INT); } - $newanswerid = insert_record("lesson_answers", $newanswer); + $newanswerid = $DB->insert_record("lesson_answers", $newanswer); if (!$newanswerid) { print_error("Insert Page: answer record not inserted"); } @@ -164,7 +165,7 @@ $newanswer->score = clean_param($form->score[$i], PARAM_INT); } } - $newanswerid = insert_record("lesson_answers", $newanswer); + $newanswerid = $DB->insert_record("lesson_answers", $newanswer); if (!$newanswerid) { print_error("Insert Page: answer record $i not inserted"); } @@ -174,7 +175,7 @@ $newanswer->lessonid = $lesson->id; $newanswer->pageid = $newpageid; $newanswer->timecreated = $timenow; - $newanswerid = insert_record("lesson_answers", $newanswer); + $newanswerid = $DB->insert_record("lesson_answers", $newanswer); if (!$newanswerid) { print_error("Insert Page: answer record $i not inserted"); } diff --git a/mod/lesson/action/move.php b/mod/lesson/action/move.php index 0eca9f1c506..518f81c5fee 100644 --- a/mod/lesson/action/move.php +++ b/mod/lesson/action/move.php @@ -8,10 +8,11 @@ **/ $pageid = required_param('pageid', PARAM_INT); - $title = get_field("lesson_pages", "title", "id", $pageid); + $title = $DB->get_field("lesson_pages", "title", array("id" => $pageid)); print_heading(get_string("moving", "lesson", format_string($title))); - if (!$page = get_record_select("lesson_pages", "lessonid = $lesson->id AND prevpageid = 0")) { + $params = array ("lessonid" => $lesson->id, "prevpageid" => 0); + if (!$page = $DB->get_record_select("lesson_pages", "lessonid = :lessonid AND prevpageid = :prevpageid", $params)) { print_error("Move: first page not found"); } @@ -28,7 +29,7 @@ get_string("movepagehere", "lesson")."\n"; } if ($page->nextpageid) { - if (!$page = get_record("lesson_pages", "id", $page->nextpageid)) { + if (!$page = $DB->get_record("lesson_pages", array("id" => $page->nextpageid))) { print_error("Teacher view: Next page not found!"); } } else { diff --git a/mod/lesson/action/moveit.php b/mod/lesson/action/moveit.php index 08172e0707c..1114a201c4c 100644 --- a/mod/lesson/action/moveit.php +++ b/mod/lesson/action/moveit.php @@ -9,7 +9,7 @@ confirm_sesskey(); $pageid = required_param('pageid', PARAM_INT); // page to move - if (!$page = get_record("lesson_pages", "id", $pageid)) { + if (!$page = $DB->get_record("lesson_pages", array("id" => $pageid))) { print_error("Moveit: page not found"); } $after = required_param('after', PARAM_INT); // target page @@ -22,7 +22,7 @@ // reset $after so that is points to the last page // (when the pages are in a ring this will in effect be the first page) if ($page->nextpageid) { - if (!$after = get_field("lesson_pages", "id", "lessonid", $lesson->id, "nextpageid", 0)) { + if (!$after = $DB->get_field("lesson_pages", "id", array("lessonid" => $lesson->id, "nextpageid" => 0))) { print_error("Moveit: last page id not found"); } } else { @@ -34,66 +34,66 @@ $newfirstpageid = $page->nextpageid; } else { // the current first page remains the first page - if (!$newfirstpageid = get_field("lesson_pages", "id", "lessonid", $lesson->id, "prevpageid", 0)) { + if (!$newfirstpageid = $DB->get_field("lesson_pages", "id", array("lessonid" => $lesson->id, "prevpageid" => 0))) { print_error("Moveit: current first page id not found"); } } // the rest is all unconditional... // second step. join pages into a ring - if (!$firstpageid = get_field("lesson_pages", "id", "lessonid", $lesson->id, "prevpageid", 0)) { + if (!$firstpageid = $DB->get_field("lesson_pages", "id", array("lessonid" => $lesson->id, "prevpageid" => 0))) { print_error("Moveit: firstpageid not found"); } - if (!$lastpageid = get_field("lesson_pages", "id", "lessonid", $lesson->id, "nextpageid", 0)) { + if (!$lastpageid = $DB->get_field("lesson_pages", "id", array("lessonid" => $lesson->id, "nextpageid" => 0))) { print_error("Moveit: lastpage not found"); } - if (!set_field("lesson_pages", "prevpageid", $lastpageid, "id", $firstpageid)) { + if (!$DB->set_field("lesson_pages", "prevpageid", $lastpageid, array("id" => $firstpageid))) { print_error("Moveit: unable to update link"); } - if (!set_field("lesson_pages", "nextpageid", $firstpageid, "id", $lastpageid)) { + if (!$DB->set_field("lesson_pages", "nextpageid", $firstpageid, array("id" => $lastpageid))) { print_error("Moveit: unable to update link"); } // third step. remove the page to be moved - if (!$prevpageid = get_field("lesson_pages", "prevpageid", "id", $pageid)) { + if (!$prevpageid = $DB->get_field("lesson_pages", "prevpageid", array("id" => $pageid))) { print_error("Moveit: prevpageid not found"); } - if (!$nextpageid = get_field("lesson_pages", "nextpageid", "id", $pageid)) { + if (!$nextpageid = $DB->get_field("lesson_pages", "nextpageid", array("id" => $pageid))) { print_error("Moveit: nextpageid not found"); } - if (!set_field("lesson_pages", "nextpageid", $nextpageid, "id", $prevpageid)) { + if (!$DB->set_field("lesson_pages", "nextpageid", $nextpageid, array("id" => $prevpageid))) { print_error("Moveit: unable to update link"); } - if (!set_field("lesson_pages", "prevpageid", $prevpageid, "id", $nextpageid)) { + if (!$DB->set_field("lesson_pages", "prevpageid", $prevpageid, array("id" => $nextpageid))) { print_error("Moveit: unable to update link"); } // fourth step. insert page to be moved in new place... - if (!$nextpageid = get_field("lesson_pages", "nextpageid", "id", $after)) { + if (!$nextpageid = $DB->get_field("lesson_pages", "nextpageid", array("id" => $after))) { print_error("Movit: nextpageid not found"); } - if (!set_field("lesson_pages", "nextpageid", $pageid, "id", $after)) { + if (!$DB->set_field("lesson_pages", "nextpageid", $pageid, array("id" => $after))) { print_error("Moveit: unable to update link"); } - if (!set_field("lesson_pages", "prevpageid", $pageid, "id", $nextpageid)) { + if (!$DB->set_field("lesson_pages", "prevpageid", $pageid, array("id" => $nextpageid))) { print_error("Moveit: unable to update link"); } // ...and set the links in the moved page - if (!set_field("lesson_pages", "prevpageid", $after, "id", $pageid)) { + if (!$DB->set_field("lesson_pages", "prevpageid", $after, array("id" => $pageid))) { print_error("Moveit: unable to update link"); } - if (!set_field("lesson_pages", "nextpageid", $nextpageid, "id", $pageid)) { + if (!$DB->set_field("lesson_pages", "nextpageid", $nextpageid, array("id" => $pageid))) { print_error("Moveit: unable to update link"); } // fifth step. break the ring - if (!$newlastpageid = get_field("lesson_pages", "prevpageid", "id", $newfirstpageid)) { + if (!$newlastpageid = $DB->get_field("lesson_pages", "prevpageid", array("id" => $newfirstpageid))) { print_error("Moveit: newlastpageid not found"); } - if (!set_field("lesson_pages", "prevpageid", 0, "id", $newfirstpageid)) { + if (!$DB->set_field("lesson_pages", "prevpageid", 0, array("id" => $newfirstpageid))) { print_error("Moveit: unable to update link"); } - if (!set_field("lesson_pages", "nextpageid", 0, "id", $newlastpageid)) { + if (!$DB->set_field("lesson_pages", "nextpageid", 0, array("id" => $newlastpageid))) { print_error("Moveit: unable to update link"); } lesson_set_message(get_string('movedpage', 'lesson'), 'notifysuccess'); diff --git a/mod/lesson/action/updatepage.php b/mod/lesson/action/updatepage.php index 7b978ccfbd7..5aeda1e58c2 100644 --- a/mod/lesson/action/updatepage.php +++ b/mod/lesson/action/updatepage.php @@ -47,7 +47,7 @@ $page->contents = trim($form->contents); $page->title = addslashes($page->title); - if (!update_record("lesson_pages", $page)) { + if (!$DB->update_record("lesson_pages", $page)) { print_error("Update page: page not updated"); } if ($page->qtype == LESSON_ENDOFBRANCH || $page->qtype == LESSON_ESSAY || $page->qtype == LESSON_CLUSTER || $page->qtype == LESSON_ENDOFCLUSTER) { @@ -62,16 +62,17 @@ // delete other answers this if mainly for essay questions. If one switches from using a qtype like Multichoice, // then switches to essay, the old answers need to be removed because essay is // supposed to only have one answer record - if ($answers = get_records_select("lesson_answers", "pageid = ".$page->id)) { + $params = array ("pageid" => $page->id); + if ($answers = $DB->get_records_select("lesson_answers", "pageid = :pageid", $params)) { foreach ($answers as $answer) { if ($answer->id != clean_param($form->answerid[0], PARAM_INT)) { - if (!delete_records("lesson_answers", "id", $answer->id)) { + if (!$DB->delete_records("lesson_answers", array("id" => $answer->id))) { print_error("Update page: unable to delete answer record"); } } } } - if (!update_record("lesson_answers", $oldanswer)) { + if (!$DB->update_record("lesson_answers", $oldanswer)) { print_error("Update page: EOB not updated"); } } else { @@ -106,7 +107,7 @@ if (isset($form->score[$i])) { $oldanswer->score = clean_param($form->score[$i], PARAM_INT); } - if (!update_record("lesson_answers", $oldanswer)) { + if (!$DB->update_record("lesson_answers", $oldanswer)) { print_error("Update page: answer $i not updated"); } } else { @@ -131,7 +132,7 @@ if (isset($form->score[$i])) { $newanswer->score = clean_param($form->score[$i], PARAM_INT); } - $newanswerid = insert_record("lesson_answers", $newanswer); + $newanswerid = $DB->insert_record("lesson_answers", $newanswer); if (!$newanswerid) { print_error("Update page: answer record not inserted"); } @@ -141,7 +142,7 @@ if ($i >= 2) { if ($form->answerid[$i]) { // need to delete blanked out answer - if (!delete_records("lesson_answers", "id", clean_param($form->answerid[$i], PARAM_INT))) { + if (!$DB->delete_records("lesson_answers", array("id" => clean_param($form->answerid[$i], PARAM_INT)))) { print_error("Update page: unable to delete answer record"); } } @@ -158,13 +159,13 @@ $form->responseeditor[$i] * LESSON_RESPONSE_EDITOR; $oldanswer->timemodified = $timenow; $oldanswer->answer = NULL; - if (!update_record("lesson_answers", $oldanswer)) { + if (!$DB->update_record("lesson_answers", $oldanswer)) { print_error("Update page: answer $i not updated"); } } } elseif (!empty($form->answerid[$i])) { // need to delete blanked out answer - if (!delete_records("lesson_answers", "id", clean_param($form->answerid[$i], PARAM_INT))) { + if (!$DB->delete_records("lesson_answers", array("id" => clean_param($form->answerid[$i], PARAM_INT)))) { print_error("Update page: unable to delete answer record"); } } diff --git a/mod/lesson/backuplib.php b/mod/lesson/backuplib.php index 451f9e46662..ee73d3e82ba 100644 --- a/mod/lesson/backuplib.php +++ b/mod/lesson/backuplib.php @@ -40,12 +40,12 @@ //This function executes all the backup procedure about this mod function lesson_backup_mods($bf, $preferences) { - global $CFG; + global $CFG, $DB; $status = true; //Iterate over lesson table - $lessons = get_records("lesson", "course", $preferences->backup_course, "id"); + $lessons = $DB->get_records("lesson", array ("course" => $preferences->backup_course), "id"); if ($lessons) { foreach ($lessons as $lesson) { if (backup_mod_selected($preferences,'lesson',$lesson->id)) { @@ -58,10 +58,10 @@ function lesson_backup_one_mod($bf,$preferences,$lesson) { - global $CFG; + global $CFG, $DB; if (is_numeric($lesson)) { - $lesson = get_record('lesson','id',$lesson); + $lesson = $DB->get_record('lesson',array ('id' => $lesson)); } $status = true; @@ -140,12 +140,13 @@ //Backup lesson_pages contents (executed from lesson_backup_mods) function backup_lesson_pages ($bf, $preferences, $lessonid) { - global $CFG; + global $CFG, $DB; $status = true; // run through the pages in their logical order, get the first page - if ($page = get_record_select("lesson_pages", "lessonid = $lessonid AND prevpageid = 0")) { + $params = array ("lessonid" => $lessonid, "prevpageid" => 0); + if ($page = $DB->get_record_select("lesson_pages", "lessonid = :lessonid AND prevpageid = :prevpageid", $params)) { //Write start tag $status =fwrite ($bf,start_tag("PAGES",4,true)); //Iterate over each page @@ -174,7 +175,7 @@ $status =fwrite ($bf,end_tag("PAGE",5,true)); // move to the next (logical) page if ($page->nextpageid) { - if (!$page = get_record("lesson_pages", "id", $page->nextpageid)) { + if (!$page = $DB->get_record("lesson_pages", array ("id" => $page->nextpageid))) { print_error("Lesson Backup: Next page not found!"); } } else { @@ -192,12 +193,12 @@ //Backup lesson_answers contents (executed from backup_lesson_pages) function backup_lesson_answers($bf,$preferences,$pageno) { - global $CFG; + global $CFG, $DB; $status = true; // get the answers in a set order, the id order - $lesson_answers = get_records("lesson_answers", "pageid", $pageno, "id"); + $lesson_answers = $DB->get_records("lesson_answers", array("pageid" => $pageno), "id"); //If there is lesson_answers if ($lesson_answers) { @@ -233,11 +234,11 @@ //Backup lesson_attempts contents (executed from lesson_backup_answers) function backup_lesson_attempts ($bf,$preferences,$answerid) { - global $CFG; + global $CFG, $DB; $status = true; - $lesson_attempts = get_records("lesson_attempts","answerid", $answerid); + $lesson_attempts = $DB->get_records("lesson_attempts", array("answerid" => $answerid)); //If there are attempts if ($lesson_attempts) { //Write start tag @@ -265,11 +266,11 @@ //Backup lesson_grades contents (executed from backup_lesson_mods) function backup_lesson_grades ($bf,$preferences,$lessonid) { - global $CFG; + global $CFG, $DB; $status = true; - $grades = get_records("lesson_grades", "lessonid", $lessonid); + $grades = $DB->get_records("lesson_grades", array("lessonid" => $lessonid)); //If there is grades if ($grades) { @@ -296,12 +297,12 @@ //Backup lesson_branch contents (executed from backup_lesson_pages) function backup_lesson_branch($bf,$preferences,$pageno) { - global $CFG; + global $CFG, $DB; $status = true; // get the branches in a set order, the id order - $lesson_branch = get_records("lesson_branch", "pageid", $pageno, "id"); + $lesson_branch = $DB->get_records("lesson_branch", array("pageid" => $pageno), "id"); //If there is lesson_branch if ($lesson_branch) { @@ -328,11 +329,11 @@ //Backup lesson_timer contents (executed from backup_lesson_mods) function backup_lesson_timer ($bf,$preferences,$lessonid) { - global $CFG; + global $CFG, $DB; $status = true; - $times = get_records("lesson_timer", "lessonid", $lessonid); + $times = $DB->get_records("lesson_timer", array("lessonid" => $lessonid)); //If there is times if ($times) { @@ -357,11 +358,11 @@ // backup lesson_high_score contents (executed from backup_lesson_mods) function backup_lesson_high_scores($bf, $preferences, $lessonid) { - global $CFG; + global $CFG, $DB; $status = true; - $highscores = get_records("lesson_high_scores", "lessonid", $lessonid); + $highscores = $DB->get_records("lesson_high_scores", array("lessonid" => $lessonid)); //If there is highscores if ($highscores) { @@ -386,12 +387,12 @@ // backup lesson_default contents (executed from backup_lesson_mods) function backup_lesson_default ($bf,$preferences) { - global $CFG; + global $CFG, $DB; $status = true; //only one default record per course - $default = get_record("lesson_default", "course", $preferences->backup_course); + $default = $DB->get_record("lesson_default", array("course" => $preferences->backup_course)); if ($default) { //Start mod $status =fwrite ($bf,start_tag("DEFAULTS",4,true)); @@ -503,32 +504,35 @@ //Returns an array of lesson id function lesson_ids ($course) { - global $CFG; + global $CFG, $DB; - return get_records_sql ("SELECT l.id, l.course - FROM {$CFG->prefix}lesson l - WHERE l.course = '$course'"); + $params = array ("course" => $course); + return $DB->get_records_sql ("SELECT l.id, l.course + FROM {lesson} l + WHERE l.course = :course", $params); } //Returns an array of lesson_submissions id function lesson_attempts_ids_by_course ($course) { - global $CFG; + global $CFG, $DB; - return get_records_sql ("SELECT a.id , a.lessonid - FROM {$CFG->prefix}lesson_attempts a, - {$CFG->prefix}lesson l - WHERE l.course = '$course' AND - a.lessonid = l.id"); + $params = array ("course" => $course); + return $DB->get_records_sql ("SELECT a.id , a.lessonid + FROM {lesson_attempts} a, + {lesson} l + WHERE l.course = :course AND + a.lessonid = l.id", $params); } //Returns an array of lesson_submissions id function lesson_attempts_ids_by_instance ($instanceid) { - global $CFG; + global $CFG, $DB; - return get_records_sql ("SELECT a.id , a.lessonid - FROM {$CFG->prefix}lesson_attempts a - WHERE a.lessonid = $instanceid"); + $params = array ("lessonid" => $instanceid); + return $DB->get_records_sql ("SELECT a.id , a.lessonid + FROM {lesson_attempts} a + WHERE a.lessonid = :lessonid", $params); } ?> diff --git a/mod/lesson/edit.php b/mod/lesson/edit.php index e92507ea710..a04ae8947e2 100644 --- a/mod/lesson/edit.php +++ b/mod/lesson/edit.php @@ -22,14 +22,14 @@ list($cm, $course, $lesson) = lesson_get_basics($id); - if ($firstpage = get_record('lesson_pages', 'lessonid', $lesson->id, 'prevpageid', 0)) { - if (!$pages = get_records('lesson_pages', 'lessonid', $lesson->id)) { + if ($firstpage = $DB->get_record('lesson_pages', array('lessonid' => $lesson->id, 'prevpageid' => 0))) { + if (!$pages = $DB->get_records('lesson_pages', array('lessonid' => $lesson->id))) { print_error('Could not find lesson pages'); } } if ($pageid) { - if (!$singlepage = get_record('lesson_pages', 'id', $pageid)) { + if (!$singlepage = $DB->get_record('lesson_pages', array('id' => $pageid))) { print_error('Could not find page ID: '.$pageid); } } @@ -83,7 +83,8 @@ } $jumps = array(); - if($answers = get_records_select("lesson_answers", "lessonid = $lesson->id and pageid = $pageid", 'id', '*', $limitfrom, $limitnum)) { + $params = array ("lessonid" => $lesson->id, "pageid" => $pageid); + if($answers = $DB->get_records_select("lesson_answers", "lessonid = :lessonid and pageid = :pageid", $params, 'id', '*', $limitfrom, $limitnum)) { foreach ($answers as $answer) { $jumps[] = lesson_get_jump_name($answer->jumpto); } @@ -129,7 +130,7 @@ echo format_text($page->contents, FORMAT_MOODLE, $options); echo "\n"; // get the answers in a set order, the id order - if ($answers = get_records("lesson_answers", "pageid", $page->id, "id")) { + if ($answers = $DB->get_records("lesson_answers", array("pageid" => $page->id), "id")) { echo "\n"; echo lesson_get_qtype_name($page->qtype); switch ($page->qtype) { @@ -277,7 +278,7 @@ // links were not used in those versions if ($page->prevpageid != $prevpageid) { // fix it - set_field("lesson_pages", "prevpageid", $prevpageid, "id", $page->id); + $DB->set_field("lesson_pages", "prevpageid", $prevpageid, array("id" => $page->id)); debugging("

***prevpageid of page $page->id set to $prevpageid***"); } diff --git a/mod/lesson/essay.php b/mod/lesson/essay.php index 2bda00e150c..bec46d05b68 100644 --- a/mod/lesson/essay.php +++ b/mod/lesson/essay.php @@ -26,27 +26,32 @@ switch ($mode) { case 'display': // Default view - get the necessary data // Get lesson pages that are essay - if ($pages = get_records_select('lesson_pages', "lessonid = $lesson->id AND qtype = ".LESSON_ESSAY)) { + $params = array ("lessonid" => $lesson->id, "qtype" => LESSON_ESSAY); + if ($pages = $DB->get_records_select('lesson_pages', "lessonid = :lessonid AND qtype = :qtype", $params)) { // Get only the attempts that are in response to essay questions - if ($essayattempts = get_records_select('lesson_attempts', 'pageid IN('.implode(',', array_keys($pages)).')')) { + list($usql, $parameters) = $DB->get_in_or_equal(array_keys($pages)); + if ($essayattempts = $DB->get_records_select('lesson_attempts', 'pageid $usql', $parameters)) { // Get all the users who have taken this lesson, order by their last name + $paras = array(); + $paras["lessonid"] = $lesson->id; if (!empty($CFG->enablegroupings) && !empty($cm->groupingid)) { + $paras["groupinid"] = $cm->groupingid; $sql = "SELECT DISTINCT u.* - FROM {$CFG->prefix}lesson_attempts a - INNER JOIN {$CFG->prefix}user u ON u.id = a.userid - INNER JOIN {$CFG->prefix}groups_members gm ON gm.userid = u.id - INNER JOIN {$CFG->prefix}groupings_groups gg ON gm.groupid = {$cm->groupingid} - WHERE a.lessonid = '$lesson->id' + FROM {lesson_attempts} a + INNER JOIN {user} u ON u.id = a.userid + INNER JOIN {groups_members} gm ON gm.userid = u.id + INNER JOIN {groupings_groups} gg ON gm.groupid = :groupinid + WHERE a.lessonid = :lessonid ORDER BY u.lastname"; } else { $sql = "SELECT u.* - FROM {$CFG->prefix}user u, - {$CFG->prefix}lesson_attempts a - WHERE a.lessonid = '$lesson->id' and + FROM {user} u, + {lesson_attempts} a + WHERE a.lessonid = :lessonid and u.id = a.userid ORDER BY u.lastname"; } - if (!$users = get_records_sql($sql)) { + if (!$users = $DB->get_records_sql($sql, $paras)) { $mode = 'none'; // not displaying anything lesson_set_message(get_string('noonehasanswered', 'lesson')); } @@ -64,16 +69,16 @@ $attemptid = required_param('attemptid', PARAM_INT); - if (!$attempt = get_record('lesson_attempts', 'id', $attemptid)) { + if (!$attempt = $DB->get_record('lesson_attempts', array('id' => $attemptid))) { print_error('Error: could not find attempt'); } - if (!$page = get_record('lesson_pages', 'id', $attempt->pageid)) { + if (!$page = $DB->get_record('lesson_pages', array('id' => $attempt->pageid))) { print_error('Error: could not find lesson page'); } - if (!$user = get_record('user', 'id', $attempt->userid)) { + if (!$user = $DB->get_record('user', array('id' => $attempt->userid))) { print_error('Error: could not find users'); } - if (!$answer = get_record('lesson_answers', 'lessonid', $lesson->id, 'pageid', $page->id)) { + if (!$answer = $DB->get_record('lesson_answers', array('lessonid' => $lesson->id, 'pageid' => $page->id))) { print_error('Error: could not find answer'); } break; @@ -85,10 +90,11 @@ $attemptid = required_param('attemptid', PARAM_INT); - if (!$attempt = get_record('lesson_attempts', 'id', $attemptid)) { + if (!$attempt = $DB->get_record('lesson_attempts', array('id' => $attemptid))) { print_error('Error: could not find essay'); } - if (!$grades = get_records_select('lesson_grades', "lessonid = $lesson->id and userid = $attempt->userid", 'completed', '*', $attempt->retry, 1)) { + $params = array ("lessonid" => $lesson->id, "userid" => $attempt->userid); + if (!$grades = $DB->get_records_select('lesson_grades', "lessonid = :lessonid and userid = :userid", $params, 'completed', '*', $attempt->retry, 1)) { print_error('Error: could not find grades'); } @@ -107,7 +113,7 @@ $attempt->useranswer = addslashes(serialize($essayinfo)); - if (!update_record('lesson_attempts', $attempt)) { + if (!$DB->update_record('lesson_attempts', $attempt)) { print_error('Could not update essay score'); } @@ -118,7 +124,7 @@ // Set and update $updategrade->id = $grade->id; $updategrade->grade = $gradeinfo->grade; - if(update_record('lesson_grades', $updategrade)) { + if($DB->update_record('lesson_grades', $updategrade)) { // Log it add_to_log($course->id, 'lesson', 'update grade', "essay.php?id=$cm->id", $lesson->name, $cm->id); @@ -140,34 +146,41 @@ // Get our users (could be singular) if ($userid = optional_param('userid', 0, PARAM_INT)) { - $queryadd = " AND userid = $userid"; - if (! $users = get_records('user', 'id', $userid)) { + $queryadd = " AND userid = :userid"; + if (! $users = $DB->get_records('user', array('id' => $userid))) { print_error('Error: could not find users'); } } else { $queryadd = ''; - if (!$users = get_records_sql("SELECT u.* - FROM {$CFG->prefix}user u, - {$CFG->prefix}lesson_attempts a - WHERE a.lessonid = '$lesson->id' and + $params = array ("lessonid" => $lesson->id); + if (!$users = $DB->get_records_sql("SELECT u.* + FROM {user} u, + {lesson_attempts} a + WHERE a.lessonid = :lessonid and u.id = a.userid - ORDER BY u.lastname")) { + ORDER BY u.lastname", $params)) { print_error('Error: could not find users'); } } // Get lesson pages that are essay - if (!$pages = get_records_select('lesson_pages', "lessonid = $lesson->id AND qtype = ".LESSON_ESSAY)) { + $params = array ("lessonid" => $lesson->id, "qtype" => LESSON_ESSAY); + if (!$pages = $DB->get_records_select('lesson_pages', "lessonid = :lessonid AND qtype = :qtype", $params)) { print_error('Error: could not find lesson pages'); } // Get only the attempts that are in response to essay questions - $pageids = implode(',', array_keys($pages)); // all the pageids in comma seperated list - if (!$attempts = get_records_select('lesson_attempts', "pageid IN($pageids)".$queryadd)) { + list($usql, $params) = $DB->get_in_or_equal(array_keys($pages)); + if (isset($queryadd) && $queryadd!='') { + $params["userid"] = $userid; + } + if (!$attempts = $DB->get_records_select('lesson_attempts', "pageid $usql".$queryadd, $params)) { error ('No one has answered essay questions yet...'); } // Get the answers - if (!$answers = get_records_select('lesson_answers', "lessonid = $lesson->id AND pageid IN($pageids)", '', 'pageid, score')) { + list($answerUsql, $parameters) = $DB->get_in_or_equal(array_keys($pages)); + $parameters["lessonid"] = $lesson->id; + if (!$answers = $DB->get_records_select('lesson_answers', "lessonid = :lessonid AND pageid $answerUsql", $parameters, '', 'pageid, score')) { error ('Could not find answer records.'); } $options = new stdClass; @@ -180,7 +193,8 @@ $a = new stdClass; // Set the grade - $grades = get_records_select('lesson_grades', "lessonid = $lesson->id and userid = $attempt->userid", 'completed', '*', $attempt->retry, 1); + $params = array ("lessonid" => $lesson->id, "userid" => $attempt->userid); + $grades = $DB->get_records_select('lesson_grades', "lessonid = :lessonid and userid = :userid", $params, 'completed', '*', $attempt->retry, 1); $grade = current($grades); $a->newgrade = $grade->grade; @@ -210,7 +224,7 @@ if(email_to_user($users[$attempt->userid], $USER, $subject, $plaintxt, $message)) { $essayinfo->sent = 1; $attempt->useranswer = addslashes(serialize($essayinfo)); - update_record('lesson_attempts', $attempt); + $DB->update_record('lesson_attempts', $attempt); // Log it add_to_log($course->id, 'lesson', 'update email essay grade', "essay.php?id=$cm->id", format_string($pages[$attempt->pageid]->title,true).': '.fullname($users[$attempt->userid]), $cm->id); } else { diff --git a/mod/lesson/format.php b/mod/lesson/format.php index 7fbf98c6c46..a2d82de8dd9 100644 --- a/mod/lesson/format.php +++ b/mod/lesson/format.php @@ -31,6 +31,8 @@ class qformat_default { } function importprocess($filename, $lesson, $pageid) { + global $DB; + /// Processes a given file. There's probably little need to change this $timenow = time(); @@ -85,28 +87,29 @@ class qformat_default { // set up page links if ($pageid) { // the new page follows on from this page - if (!$page = get_record("lesson_pages", "id", $pageid)) { + if (!$page = $DB->get_record("lesson_pages", array("id" => $pageid))) { error ("Format: Page $pageid not found"); } $newpage->prevpageid = $pageid; $newpage->nextpageid = $page->nextpageid; // insert the page and reset $pageid - if (!$newpageid = insert_record("lesson_pages", $newpage)) { + if (!$newpageid = $DB->insert_record("lesson_pages", $newpage)) { print_error("Format: Could not insert new page!"); } // update the linked list - if (!set_field("lesson_pages", "nextpageid", $newpageid, "id", $pageid)) { + if (!$DB->set_field("lesson_pages", "nextpageid", $newpageid, array("id" => $pageid))) { print_error("Format: unable to update link"); } } else { // new page is the first page // get the existing (first) page (if any) - if (!$page = get_record_select("lesson_pages", "lessonid = $lesson->id AND prevpageid = 0")) { + $params = array ("lessonid" => $lesson->id, "prevpageid" => 0); + if (!$page = $DB->get_record_select("lesson_pages", "lessonid = :lessonid AND prevpageid = :prevpageid", $params)) { // there are no existing pages $newpage->prevpageid = 0; // this is a first page $newpage->nextpageid = 0; // this is the only page - $newpageid = insert_record("lesson_pages", $newpage); + $newpageid = $DB->insert_record("lesson_pages", $newpage); if (!$newpageid) { print_error("Insert page: new first page not inserted"); } @@ -114,12 +117,12 @@ class qformat_default { // there are existing pages put this at the start $newpage->prevpageid = 0; // this is a first page $newpage->nextpageid = $page->id; - $newpageid = insert_record("lesson_pages", $newpage); + $newpageid = $DB->insert_record("lesson_pages", $newpage); if (!$newpageid) { print_error("Insert page: first page not inserted"); } // update the linked list - if (!set_field("lesson_pages", "prevpageid", $newpageid, "id", $page->id)) { + if (!$DB->set_field("lesson_pages", "prevpageid", $newpageid, array("id" => $page->id))) { print_error("Insert page: unable to update link"); } } diff --git a/mod/lesson/grade.php b/mod/lesson/grade.php index 740730e3718..179cfdf66dc 100644 --- a/mod/lesson/grade.php +++ b/mod/lesson/grade.php @@ -8,11 +8,11 @@ print_error("Course Module ID was incorrect"); } - if (! $lesson = get_record("lesson", "id", $cm->instance)) { + if (! $lesson = $DB->get_record("lesson", array("id" => $cm->instance))) { print_error("lesson ID was incorrect"); } - if (! $course = get_record("course", "id", $lesson->course)) { + if (! $course = $DB->get_record("course", array("id" => $lesson->course))) { print_error("Course is misconfigured"); } diff --git a/mod/lesson/highscores.php b/mod/lesson/highscores.php index b411a5dec4e..2e113e749c5 100644 --- a/mod/lesson/highscores.php +++ b/mod/lesson/highscores.php @@ -53,29 +53,31 @@ if ($mode == 'add') { break; } - - if (!$grades = get_records_select('lesson_grades', "lessonid = $lesson->id", 'completed')) { + $params = array ("lessonid" => $lesson->id); + if (!$grades = $DB->get_records_select('lesson_grades', "lessonid = :lessonid", $params, 'completed')) { print_error('Error: could not find grades'); } - if (!$newgrade = get_record_sql("SELECT * - FROM {$CFG->prefix}lesson_grades - WHERE lessonid = $lesson->id - AND userid = $USER->id - ORDER BY completed DESC", true)) { + $paremeters = array ("lessonid" => $lesson->id, "userid" => $USER->id); + if (!$newgrade = $DB->get_record_sql("SELECT * + FROM {lesson_grades} + WHERE lessonid = :lessonid + AND userid = :userid + ORDER BY completed DESC", $paremeters, true)) { print_error('Error: could not find newest grade'); } // Check for multiple submissions - if (record_exists('lesson_high_scores', 'gradeid', $newgrade->id)) { + if ($DB->record_exists('lesson_high_scores', array('gradeid' => $newgrade->id))) { print_error('Only one posting per grade'); } // Find out if we need to delete any records - if ($highscores = get_records_sql("SELECT h.*, g.grade - FROM {$CFG->prefix}lesson_grades g, {$CFG->prefix}lesson_high_scores h + $params = array ("lessonid" => $lesson->id); + if ($highscores = $DB->get_records_sql("SELECT h.*, g.grade + FROM {lesson_grades} g, {lesson_high_scores} h WHERE h.gradeid = g.id - AND h.lessonid = $lesson->id - ORDER BY g.grade DESC")) { + AND h.lessonid = :lessonid + ORDER BY g.grade DESC", $params)) { // Only count unique scores in our total for max high scores $uniquescores = array(); foreach ($highscores as $highscore) { @@ -102,7 +104,7 @@ // Now, delete all high scores with the low score foreach ($highscores as $highscore) { if ($highscore->grade == $lowscore) { - delete_records('lesson_high_scores', 'id', $highscore->id); + $DB->delete_records('lesson_high_scores', array('id' => $highscore->id)); } } } @@ -115,7 +117,7 @@ $newhighscore->gradeid = $newgrade->id; $newhighscore->nickname = $name; - if (!insert_record('lesson_high_scores', $newhighscore)) { + if (!$DB->insert_record('lesson_high_scores', $newhighscore)) { print_error("Insert of new high score Failed!"); } @@ -150,13 +152,14 @@ print_simple_box_end(); break; default: - if (!$grades = get_records_select("lesson_grades", "lessonid = $lesson->id", "completed")) { + $params = array ("lessonid" => $lesson->id); + if (!$grades = $DB->get_records_select("lesson_grades", "lessonid = :lessonid", $params, "completed")) { $grades = array(); } print_heading(get_string("topscorestitle", "lesson", $lesson->maxhighscores), 'center', 4); - if (!$highscores = get_records_select("lesson_high_scores", "lessonid = $lesson->id")) { + if (!$highscores = $DB->get_records_select("lesson_high_scores", "lessonid = :lessonid", $params)) { print_heading(get_string("nohighscores", "lesson"), 'center', 3); } else { foreach ($highscores as $highscore) { diff --git a/mod/lesson/import.php b/mod/lesson/import.php index 809e09a2a52..25b41020208 100644 --- a/mod/lesson/import.php +++ b/mod/lesson/import.php @@ -19,11 +19,11 @@ print_error("Course Module ID was incorrect"); } - if (! $course = get_record("course", "id", $cm->course)) { + if (! $course = $DB->get_record("course", array("id" => $cm->course))) { print_error("Course is misconfigured"); } - if (! $lesson = get_record("lesson", "id", $cm->instance)) { + if (! $lesson = $DB->get_record("lesson", array("id" => $cm->instance))) { print_error("Course module is incorrect"); } diff --git a/mod/lesson/importppt.php b/mod/lesson/importppt.php index 2d61a9daf4e..47b984f42c3 100644 --- a/mod/lesson/importppt.php +++ b/mod/lesson/importppt.php @@ -24,16 +24,16 @@ print_error("Course Module ID was incorrect"); } - if (! $course = get_record("course", "id", $cm->course)) { + if (! $course = $DB->get_record("course", array("id" => $cm->course))) { print_error("Course is misconfigured"); } // allows for adaption for multiple modules - if(! $modname = get_field('modules', 'name', 'id', $cm->module)) { + if(! $modname = $DB->get_field('modules', 'name', array('id' => $cm->module))) { print_error("Could not find module name"); } - if (! $mod = get_record($modname, "id", $cm->instance)) { + if (! $mod = $DB->get_record($modname, array("id" => $cm->instance))) { print_error("Course module is incorrect"); } @@ -523,17 +523,19 @@ function prep_page($pageobject, $count) { Saves the branchtable objects to the DB */ function lesson_save_objects($branchtables, $lessonid, $after) { + global $DB; + // first set up the prevpageid and nextpageid if ($after == 0) { // adding it to the top of the lesson $prevpageid = 0; // get the id of the first page. If not found, then no pages in the lesson - if (!$nextpageid = get_field('lesson_pages', 'id', 'prevpageid', 0, 'lessonid', $lessonid)) { + if (!$nextpageid = $DB->get_field('lesson_pages', 'id', array('prevpageid' => 0, 'lessonid' => $lessonid))) { $nextpageid = 0; } } else { // going after an actual page $prevpageid = $after; - $nextpageid = get_field('lesson_pages', 'nextpageid', 'id', $after); + $nextpageid = $DB->get_field('lesson_pages', 'nextpageid', array('id' => $after)); } foreach ($branchtables as $branchtable) { @@ -543,13 +545,13 @@ function lesson_save_objects($branchtables, $lessonid, $after) { $branchtable->page->prevpageid = $prevpageid; // insert the page - if(!$id = insert_record('lesson_pages', $branchtable->page)) { + if(!$id = $DB->insert_record('lesson_pages', $branchtable->page)) { print_error("insert page"); } // update the link of the page previous to the one we just updated if ($prevpageid != 0) { // if not the first page - if (!set_field("lesson_pages", "nextpageid", $id, "id", $prevpageid)) { + if (!$DB->set_field("lesson_pages", "nextpageid", $id, array("id" => $prevpageid))) { print_error("Insert page: unable to update next link $prevpageid"); } } @@ -557,7 +559,7 @@ function lesson_save_objects($branchtables, $lessonid, $after) { // insert the answers foreach ($branchtable->answers as $answer) { $answer->pageid = $id; - if(!insert_record('lesson_answers', $answer)) { + if(!$DB->insert_record('lesson_answers', $answer)) { print_error("insert answer $id"); } } @@ -567,7 +569,7 @@ function lesson_save_objects($branchtables, $lessonid, $after) { // all done with inserts. Now check to update our last page (this is when we import between two lesson pages) if ($nextpageid != 0) { // if the next page is not the end of lesson - if (!set_field("lesson_pages", "prevpageid", $id, "id", $nextpageid)) { + if (!$DB->set_field("lesson_pages", "prevpageid", $id, array("id" => $nextpageid))) { print_error("Insert page: unable to update next link $prevpageid"); } } @@ -579,9 +581,11 @@ function lesson_save_objects($branchtables, $lessonid, $after) { Save the chapter objects to the database */ function book_save_objects($chapters, $bookid, $pageid='0') { + global $DB; + // nothing fancy, just save them all in order foreach ($chapters as $chapter) { - if (!$chapter->id = insert_record('book_chapters', $chapter)) { + if (!$chapter->id = $DB->insert_record('book_chapters', $chapter)) { print_error('Could not update your book'); } } diff --git a/mod/lesson/index.php b/mod/lesson/index.php index 4433fc6d927..96915e7b727 100644 --- a/mod/lesson/index.php +++ b/mod/lesson/index.php @@ -13,7 +13,7 @@ $id = required_param('id', PARAM_INT); // course - if (!$course = get_record("course", "id", $id)) { + if (!$course = $DB->get_record("course", array("id" => $id))) { print_error("Course ID is incorrect"); } diff --git a/mod/lesson/lib.php b/mod/lesson/lib.php index f7996b20dbc..5e475cf4081 100644 --- a/mod/lesson/lib.php +++ b/mod/lesson/lib.php @@ -130,9 +130,10 @@ function lesson_delete_instance($id) { * @return boolean */ function lesson_delete_course($course, $feedback=true) { + global $DB; $count = count_records('lesson_default', 'course', $course->id); - delete_records('lesson_default', 'course', $course->id); + $DB->delete_records('lesson_default', array('course' => $course->id)); //Inform about changes performed if feedback is enabled if ($feedback) { @@ -149,8 +150,10 @@ function lesson_user_outline($course, $user, $mod, $lesson) { /// Used for user activity reports. /// $return->time = the time they did it /// $return->info = a short text description - - if ($grades = get_records_select("lesson_grades", "lessonid = $lesson->id AND userid = $user->id", + global $DB; + + $params = array ("lessonid" => $lesson->id, "userid" => $user->id); + if ($grades = $DB->get_records_select("lesson_grades", "lessonid = :lessonid AND userid = :userid", $params, "grade DESC")) { foreach ($grades as $grade) { $max_grade = number_format($grade->grade * $lesson->grade / 100.0, 1); @@ -173,8 +176,10 @@ function lesson_user_outline($course, $user, $mod, $lesson) { function lesson_user_complete($course, $user, $mod, $lesson) { /// Print a detailed representation of what a user has done with /// a given particular instance of this module, for user activity reports. - - if ($attempts = get_records_select("lesson_attempts", "lessonid = $lesson->id AND userid = $user->id", + global $DB; + + $params = array ("lessonid" => $lesson->id, "userid" => $user->id); + if ($attempts = $DB->get_records_select("lesson_attempts", "lessonid = :lessonid AND userid = :userid", $params, "retry, timeseen")) { print_simple_box_start(); $table->head = array (get_string("attempt", "lesson"), get_string("numberofpagesviewed", "lesson"), @@ -213,7 +218,8 @@ function lesson_user_complete($course, $user, $mod, $lesson) { print_table($table); print_simple_box_end(); // also print grade summary - if ($grades = get_records_select("lesson_grades", "lessonid = $lesson->id AND userid = $user->id", + $params = array ("lessonid" => $lesson->id, "userid" => $user->id); + if ($grades = $DB->get_records_select("lesson_grades", "lessonid = :lessonid AND userid = :userid", $params, "grade DESC")) { foreach ($grades as $grade) { $max_grade = number_format($grade->grade * $lesson->grade / 100.0, 1); @@ -317,22 +323,39 @@ function lesson_cron () { * @return array array of grades, false if none */ function lesson_get_user_grades($lesson, $userid=0) { - global $CFG; + global $CFG, $DB; - $user = $userid ? "AND u.id = $userid" : ""; - $fuser = $userid ? "AND uu.id = $userid" : ""; + $params = array(); + + if (isset($userid)) { + $params["userid"] = $userid; + $user = "AND u.id = :userid"; + } + else { + $user=""; + } + + if (isset($fuser)) { + $params["userid"] = $userid; + $fuser = "AND uu.id = :userid"; + } + else { + $fuser=""; + } + $params["lessonid"] = $lesson->id; + if ($lesson->retake) { if ($lesson->usemaxgrade) { $sql = "SELECT u.id, u.id AS userid, MAX(g.grade) AS rawgrade - FROM {$CFG->prefix}user u, {$CFG->prefix}lesson_grades g - WHERE u.id = g.userid AND g.lessonid = $lesson->id + FROM {user} u, {lesson_grades} g + WHERE u.id = g.userid AND g.lessonid = :lessonid $user GROUP BY u.id"; } else { $sql = "SELECT u.id, u.id AS userid, AVG(g.grade) AS rawgrade - FROM {$CFG->prefix}user u, {$CFG->prefix}lesson_grades g - WHERE u.id = g.userid AND g.lessonid = $lesson->id + FROM {user} u, {lesson_grades} g + WHERE u.id = g.userid AND g.lessonid = :lessonid $user GROUP BY u.id"; } @@ -340,19 +363,19 @@ function lesson_get_user_grades($lesson, $userid=0) { } else { // use only first attempts (with lowest id in lesson_grades table) $firstonly = "SELECT uu.id AS userid, MIN(gg.id) AS firstcompleted - FROM {$CFG->prefix}user uu, {$CFG->prefix}lesson_grades gg - WHERE uu.id = gg.userid AND gg.lessonid = $lesson->id + FROM {user} uu, {lesson_grades} gg + WHERE uu.id = gg.userid AND gg.lessonid = :lessonid $fuser GROUP BY uu.id"; $sql = "SELECT u.id, u.id AS userid, g.grade AS rawgrade - FROM {$CFG->prefix}user u, {$CFG->prefix}lesson_grades g, ($firstonly) f - WHERE u.id = g.userid AND g.lessonid = $lesson->id + FROM {user} u, {lesson_grades} g, ($firstonly) f + WHERE u.id = g.userid AND g.lessonid = :lessonid AND g.id = f.firstcompleted AND g.userid=f.userid $user"; } - return get_records_sql($sql); + return $DB->get_records_sql($sql, $params); } /** @@ -362,7 +385,7 @@ function lesson_get_user_grades($lesson, $userid=0) { * @param int $userid specific user only, 0 mean all */ function lesson_update_grades($lesson=null, $userid=0, $nullifnone=true) { - global $CFG; + global $CFG, $DB; if (!function_exists('grade_update')) { //workaround for buggy PHP versions require_once($CFG->libdir.'/gradelib.php'); } @@ -383,17 +406,17 @@ function lesson_update_grades($lesson=null, $userid=0, $nullifnone=true) { } else { $sql = "SELECT l.*, cm.idnumber as cmidnumber, l.course as courseid - FROM {$CFG->prefix}lesson l, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m + FROM {lesson} l, {course_modules} cm, {modules} m WHERE m.name='lesson' AND m.id=cm.module AND cm.instance=l.id"; - if ($rs = get_recordset_sql($sql)) { - while ($lesson = rs_fetch_next_record($rs)) { + if ($rs = $DB->get_recordset_sql($sql)) { + foreach ($rs as $lesson) { if ($lesson->grade != 0) { lesson_update_grades($lesson, 0, false); } else { lesson_grade_item_update($lesson); } } - rs_close($rs); + $rs->close(); } } } @@ -456,14 +479,15 @@ function lesson_get_participants($lessonid) { //for a given instance of lesson. Must include every user involved //in the instance, independient of his role (student, teacher, admin...) - global $CFG; + global $CFG, $DB; //Get students - $students = get_records_sql("SELECT DISTINCT u.id, u.id - FROM {$CFG->prefix}user u, - {$CFG->prefix}lesson_attempts a - WHERE a.lessonid = '$lessonid' and - u.id = a.userid"); + $params = array ("lessonid" => $lessonid); + $students = $DB->get_records_sql("SELECT DISTINCT u.id, u.id + FROM {user} u, + {lesson_attempts} a + WHERE a.lessonid = :lessonid and + u.id = a.userid", $params); //Return students array (it contains an array of unique users) return ($students); @@ -485,6 +509,8 @@ function lesson_get_post_actions() { * @return void **/ function lesson_process_pre_save(&$lesson) { + global $DB; + $lesson->timemodified = time(); if (empty($lesson->timed)) { @@ -507,7 +533,7 @@ function lesson_process_pre_save(&$lesson) { $conditions->timespent = $lesson->timespent; $conditions->completed = $lesson->completed; $conditions->gradebetterthan = $lesson->gradebetterthan; - $lesson->conditions = addslashes(serialize($conditions)); + $lesson->conditions = serialize($conditions); unset($lesson->timespent); unset($lesson->completed); unset($lesson->gradebetterthan); @@ -525,10 +551,10 @@ function lesson_process_pre_save(&$lesson) { unset($default->timemodified); unset($default->available); unset($default->deadline); - if ($default->id = get_field('lesson_default', 'id', 'course', $default->course)) { - update_record('lesson_default', $default); + if ($default->id = $DB->get_field('lesson_default', 'id', array('course' => $default->course))) { + $DB->update_record('lesson_default', $default); } else { - insert_record('lesson_default', $default); + $DB->insert_record('lesson_default', $default); } } unset($lesson->lessondefault); @@ -559,7 +585,9 @@ function lesson_process_post_save(&$lesson) { $event->instance = $lesson->id; $event->eventtype = 'open'; $event->timestart = $lesson->available; + $event->visible = instance_is_visible('lesson', $lesson); + $event->timeduration = ($lesson->deadline - $lesson->available); if ($lesson->deadline and $lesson->available and $event->timeduration <= LESSON_MAX_EVENT_LENGTH) { @@ -607,13 +635,13 @@ function lesson_reset_course_form_defaults($course) { * @param string optional type */ function lesson_reset_gradebook($courseid, $type='') { - global $CFG; + global $CFG, $DB; $sql = "SELECT l.*, cm.idnumber as cmidnumber, l.course as courseid - FROM {$CFG->prefix}lesson l, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m - WHERE m.name='lesson' AND m.id=cm.module AND cm.instance=l.id AND l.course=$courseid"; - - if ($lessons = get_records_sql($sql)) { + FROM {lesson} l, {course_modules} cm, {modules} m + WHERE m.name='lesson' AND m.id=cm.module AND cm.instance=l.id AND l.course=:course"; + $params = array ("course" => $courseid); + if ($lessons = $DB->get_records_sql($sql,$params)) { foreach ($lessons as $lesson) { lesson_grade_item_update($lesson, 'reset'); } @@ -627,21 +655,21 @@ function lesson_reset_gradebook($courseid, $type='') { * @return array status array */ function lesson_reset_userdata($data) { - global $CFG; + global $CFG, $DB; $componentstr = get_string('modulenameplural', 'lesson'); $status = array(); if (!empty($data->reset_lesson)) { $lessonssql = "SELECT l.id - FROM {$CFG->prefix}lesson l - WHERE l.course={$data->courseid}"; + FROM {lesson} l + WHERE l.course=:course"; - - delete_records_select('lesson_timer', "lessonid IN ($lessonssql)"); - delete_records_select('lesson_high_scores', "lessonid IN ($lessonssql)"); - delete_records_select('lesson_grades', "lessonid IN ($lessonssql)"); - delete_records_select('lesson_attempts', "lessonid IN ($lessonssql)"); + $params = array ("course" => $data->courseid); + $DB->delete_records_select('lesson_timer', "lessonid IN ($lessonssql)", $params); + $DB->delete_records_select('lesson_high_scores', "lessonid IN ($lessonssql)", $params); + $DB->delete_records_select('lesson_grades', "lessonid IN ($lessonssql)", $params); + $DB->delete_records_select('lesson_attempts', "lessonid IN ($lessonssql)", $params); // remove all grades from gradebook if (empty($data->reset_gradebook_grades)) { diff --git a/mod/lesson/locallib.php b/mod/lesson/locallib.php index a25a4d03a23..6efc88d02fa 100644 --- a/mod/lesson/locallib.php +++ b/mod/lesson/locallib.php @@ -268,21 +268,23 @@ function lesson_print_header($cm, $course, $lesson, $currenttab = '') { * @return array array($cm, $course, $lesson) **/ function lesson_get_basics($cmid = 0, $lessonid = 0) { + global $DB; + if ($cmid) { if (!$cm = get_coursemodule_from_id('lesson', $cmid)) { print_error('Course Module ID was incorrect'); } - if (!$course = get_record('course', 'id', $cm->course)) { + if (!$course = $DB->get_record('course', array('id' => $cm->course))) { print_error('Course is misconfigured'); } - if (!$lesson = get_record('lesson', 'id', $cm->instance)) { + if (!$lesson = $DB->get_record('lesson', array('id' => $cm->instance))) { print_error('Course module is incorrect'); } } else if ($lessonid) { - if (!$lesson = get_record('lesson', 'id', $lessonid)) { + if (!$lesson = $DB->get_record('lesson', array('id' => $lessonid))) { print_error('Course module is incorrect'); } - if (!$course = get_record('course', 'id', $lesson->course)) { + if (!$course = $DB->get_record('course', array('id' => $lesson->course))) { print_error('Course is misconfigured'); } if (!$cm = get_coursemodule_from_instance('lesson', $lesson->id, $course->id)) { @@ -571,6 +573,8 @@ function lesson_get_qtype_name($qtype) { * @return string **/ function lesson_get_jump_name($jumpto) { + global $DB; + if ($jumpto == 0) { $jumptitle = get_string('thispage', 'lesson'); } elseif ($jumpto == LESSON_NEXTPAGE) { @@ -588,7 +592,7 @@ function lesson_get_jump_name($jumpto) { } elseif ($jumpto == LESSON_CLUSTERJUMP) { $jumptitle = get_string('clusterjump', 'lesson'); } else { - if (!$jumptitle = get_field('lesson_pages', 'title', 'id', $jumpto)) { + if (!$jumptitle = $DB->get_field('lesson_pages', 'title', array('id' => $jumpto))) { $jumptitle = ''.get_string('notdefined', 'lesson').''; } } @@ -614,6 +618,7 @@ function lesson_get_jump_name($jumpto) { * @return object Returns $result->error or $result->notice. **/ function lesson_save_question_options($question) { + global $DB; $timenow = time(); switch ($question->qtype) { @@ -635,7 +640,7 @@ function lesson_save_question_options($question) { $answer->grade = $question->fraction[$key] * 100; $answer->answer = $dataanswer; $answer->response = $question->feedback[$key]; - if (!$answer->id = insert_record("lesson_answers", $answer)) { + if (!$answer->id = $DB->insert_record("lesson_answers", $answer)) { $result->error = "Could not insert shortanswer quiz answer!"; return $result; } @@ -675,7 +680,7 @@ function lesson_save_question_options($question) { $answer->answer = $min.":".$max; // $answer->answer = $question->min[$key].":".$question->max[$key]; original line for min/max $answer->response = $question->feedback[$key]; - if (!$answer->id = insert_record("lesson_answers", $answer)) { + if (!$answer->id = $DB->insert_record("lesson_answers", $answer)) { $result->error = "Could not insert numerical quiz answer!"; return $result; } @@ -710,7 +715,7 @@ function lesson_save_question_options($question) { if (isset($question->feedbacktrue)) { $answer->response = $question->feedbacktrue; } - if (!$true->id = insert_record("lesson_answers", $answer)) { + if (!$true->id = $DB->insert_record("lesson_answers", $answer)) { $result->error = "Could not insert quiz answer \"true\")!"; return $result; } @@ -728,7 +733,7 @@ function lesson_save_question_options($question) { if (isset($question->feedbackfalse)) { $answer->response = $question->feedbackfalse; } - if (!$false->id = insert_record("lesson_answers", $answer)) { + if (!$false->id = $DB->insert_record("lesson_answers", $answer)) { $result->error = "Could not insert quiz answer \"false\")!"; return $result; } @@ -764,7 +769,7 @@ function lesson_save_question_options($question) { // end Replace $answer->answer = $dataanswer; $answer->response = $question->feedback[$key]; - if (!$answer->id = insert_record("lesson_answers", $answer)) { + if (!$answer->id = $DB->insert_record("lesson_answers", $answer)) { $result->error = "Could not insert multichoice quiz answer! "; return $result; } @@ -814,7 +819,7 @@ function lesson_save_question_options($question) { // first answer contains the correct answer jump $answer->jumpto = LESSON_NEXTPAGE; } - if (!$subquestion->id = insert_record("lesson_answers", $answer)) { + if (!$subquestion->id = $DB->insert_record("lesson_answers", $answer)) { $result->error = "Could not insert quiz match subquestion!"; return $result; } @@ -834,14 +839,14 @@ function lesson_save_question_options($question) { case LESSON_RANDOMSAMATCH: $options->question = $question->id; $options->choose = $question->choose; - if ($existing = get_record("quiz_randomsamatch", "question", $options->question)) { + if ($existing = $DB->get_record("quiz_randomsamatch", array("question" => $options->question))) { $options->id = $existing->id; - if (!update_record("quiz_randomsamatch", $options)) { + if (!$DB->update_record("quiz_randomsamatch", $options)) { $result->error = "Could not update quiz randomsamatch options!"; return $result; } } else { - if (!insert_record("quiz_randomsamatch", $options)) { + if (!$DB->insert_record("quiz_randomsamatch", $options)) { $result->error = "Could not insert quiz randomsamatch options!"; return $result; } @@ -849,7 +854,7 @@ function lesson_save_question_options($question) { break; case LESSON_MULTIANSWER: - if (!$oldmultianswers = get_records("quiz_multianswers", "question", $question->id, "id ASC")) { + if (!$oldmultianswers = $DB->get_records("quiz_multianswers", array("question" => $question->id), "id ASC")) { $oldmultianswers = array(); } @@ -868,7 +873,7 @@ function lesson_save_question_options($question) { $result->error = "Could not update multianswer alternatives! (id=$multianswer->id)"; return $result; } - if (!update_record("quiz_multianswers", $multianswer)) { + if (!$DB->update_record("quiz_multianswers", $multianswer)) { $result->error = "Could not update quiz multianswer! (id=$multianswer->id)"; return $result; } @@ -886,7 +891,7 @@ function lesson_save_question_options($question) { $result->error = "Could not insert multianswer alternatives! (questionid=$question->id)"; return $result; } - if (!insert_record("quiz_multianswers", $multianswer)) { + if (!$DB->insert_record("quiz_multianswers", $multianswer)) { $result->error = "Could not insert quiz multianswer!"; return $result; } @@ -919,6 +924,7 @@ function lesson_save_question_options($question) { * @return boolean True or false after a series of tests. **/ function lesson_iscorrect($pageid, $jumpto) { + global $DB; // first test the special values if (!$jumpto) { @@ -936,8 +942,8 @@ function lesson_iscorrect($pageid, $jumpto) { return true; } // we have to run through the pages from pageid looking for jumpid - if ($lessonid = get_field('lesson_pages', 'lessonid', 'id', $pageid)) { - if ($pages = get_records('lesson_pages', 'lessonid', $lessonid, '', 'id, nextpageid')) { + if ($lessonid = $DB->get_field('lesson_pages', 'lessonid', array('id' => $pageid))) { + if ($pages = $DB->get_records('lesson_pages', array('lessonid' => $lessonid), '', 'id, nextpageid')) { $apageid = $pages[$pageid]->nextpageid; while ($apageid != 0) { if ($jumpto == $apageid) { @@ -960,12 +966,15 @@ function lesson_iscorrect($pageid, $jumpto) { * @return boolean True or false. **/ function lesson_display_branch_jumps($lessonid, $pageid) { + global $DB; + if($pageid == 0) { // first page return false; } // get all of the lesson pages - if (!$lessonpages = get_records_select("lesson_pages", "lessonid = $lessonid")) { + $params = array ("lessonid" => $lessonid); + if (!$lessonpages = $DB->get_records_select("lesson_pages", "lessonid = :lessonid", $params)) { // adding first page return false; } @@ -987,12 +996,15 @@ function lesson_display_branch_jumps($lessonid, $pageid) { * @return boolean True or false. **/ function lesson_display_cluster_jump($lesson, $pageid) { + global $DB; + if($pageid == 0) { // first page return false; } // get all of the lesson pages - if (!$lessonpages = get_records_select("lesson_pages", "lessonid = $lesson")) { + $params = array ("lessonid" => $lesson); + if (!$lessonpages = $DB->get_records_select("lesson_pages", "lessonid = :lessonid", $params)) { // adding first page return false; } @@ -1016,8 +1028,11 @@ function lesson_display_cluster_jump($lesson, $pageid) { * @return boolean True or false. **/ function lesson_display_teacher_warning($lesson) { + global $DB; + // get all of the lesson answers - if (!$lessonanswers = get_records_select("lesson_answers", "lessonid = $lesson")) { + $params = array ("lessonid" => $lesson); + if (!$lessonanswers = $DB->get_records_select("lesson_answers", "lessonid = :lessonid", $params)) { // no answers, then not useing cluster or unseen return false; } @@ -1048,13 +1063,16 @@ function lesson_display_teacher_warning($lesson) { * @return int The id of the next page. **/ function lesson_cluster_jump($lessonid, $userid, $pageid) { + global $DB; + // get the number of retakes if (!$retakes = count_records("lesson_grades", "lessonid", $lessonid, "userid", $userid)) { $retakes = 0; } // get all the lesson_attempts aka what the user has seen - if ($seen = get_records_select("lesson_attempts", "lessonid = $lessonid AND userid = $userid AND retry = $retakes", "timeseen DESC")) { + $params = array ("lessonid" => $lessonid, "userid" => $userid, "retry" => $retakes); + if ($seen = $DB->get_records_select("lesson_attempts", "lessonid = :lessonid AND userid = :userid AND retry = :retry", $params, "timeseen DESC")) { foreach ($seen as $value) { // load it into an array that I can more easily use $seenpages[$value->pageid] = $value->pageid; } @@ -1063,7 +1081,8 @@ function lesson_cluster_jump($lessonid, $userid, $pageid) { } // get the lesson pages - if (!$lessonpages = get_records_select("lesson_pages", "lessonid = $lessonid")) { + $parameters = array ("lessonid" => $lessonid); + if (!$lessonpages = $DB->get_records_select("lesson_pages", "lessonid = :lessonid", $parameters)) { print_error("Error: could not find records in lesson_pages table"); } // find the start of the cluster @@ -1080,7 +1099,7 @@ function lesson_cluster_jump($lessonid, $userid, $pageid) { while (true) { // now load all the pages into the cluster that are not already inside of a branch table. if ($lessonpages[$pageid]->qtype == LESSON_ENDOFCLUSTER) { // store the endofcluster page's jump - $exitjump = get_field("lesson_answers", "jumpto", "pageid", $pageid, "lessonid", $lessonid); + $exitjump = $DB->get_field("lesson_answers", "jumpto", array("pageid" => $pageid, "lessonid" => $lessonid)); if ($exitjump == LESSON_NEXTPAGE) { $exitjump = $lessonpages[$pageid]->nextpageid; } @@ -1176,13 +1195,16 @@ function lesson_pages_in_branch($lessonpages, $branchid) { * @return int Id of the next page. **/ function lesson_unseen_question_jump($lesson, $user, $pageid) { + global $DB; + // get the number of retakes if (!$retakes = count_records("lesson_grades", "lessonid", $lesson, "userid", $user)) { $retakes = 0; } // get all the lesson_attempts aka what the user has seen - if ($viewedpages = get_records_select("lesson_attempts", "lessonid = $lesson AND userid = $user AND retry = $retakes", "timeseen DESC")) { + $params = array ("lessonid" => $lesson, "userid" => $user, "retry" => $retakes); + if ($viewedpages = $DB->get_records_select("lesson_attempts", "lessonid = :lessonid AND userid = :userid AND retry = :retry", $params, "timeseen DESC")) { foreach($viewedpages as $viewed) { $seenpages[] = $viewed->pageid; } @@ -1191,7 +1213,8 @@ function lesson_unseen_question_jump($lesson, $user, $pageid) { } // get the lesson pages - if (!$lessonpages = get_records_select("lesson_pages", "lessonid = $lesson")) { + $parameters = array ("lessonid" => $lesson); + if (!$lessonpages = $DB->get_records_select("lesson_pages", "lessonid = :lessonid", $parameters)) { print_error("Error: could not find records in lesson_pages table"); } @@ -1243,17 +1266,21 @@ function lesson_unseen_question_jump($lesson, $user, $pageid) { * @return int Will return the page id of a branch table or end of lesson **/ function lesson_unseen_branch_jump($lessonid, $userid) { + global $DB; + if (!$retakes = count_records("lesson_grades", "lessonid", $lessonid, "userid", $userid)) { $retakes = 0; } - if (!$seenbranches = get_records_select("lesson_branch", "lessonid = $lessonid AND userid = $userid AND retry = $retakes", + $params = array ("lessonid" => $lessonid, "userid" => $userid, "retry" => $retakes); + if (!$seenbranches = $DB->get_records_select("lesson_branch", "lessonid = :lessonid AND userid = :userid AND retry = :retry", $params, "timeseen DESC")) { print_error("Error: could not find records in lesson_branch table"); } // get the lesson pages - if (!$lessonpages = get_records_select("lesson_pages", "lessonid = $lessonid")) { + $parameters = array ("lessonid" => $lessonid); + if (!$lessonpages = $DB->get_records_select("lesson_pages", "lessonid = :lessonid", $parameters)) { print_error("Error: could not find records in lesson_pages table"); } @@ -1299,8 +1326,11 @@ function lesson_unseen_branch_jump($lessonid, $userid) { * @return int The pageid of a random page that is within a branch table **/ function lesson_random_question_jump($lessonid, $pageid) { + global $DB; + // get the lesson pages - if (!$lessonpages = get_records_select("lesson_pages", "lessonid = $lessonid")) { + $params = array ("lessonid" => $lessonid); + if (!$lessonpages = $DB->get_records_select("lesson_pages", "lessonid = :lessonid", $params)) { print_error("Error: could not find records in lesson_pages table"); } @@ -1396,7 +1426,7 @@ function lesson_is_page_in_cluster($pages, $pageid) { manualpoints => point value for manually graded questions } */ function lesson_grade($lesson, $ntries, $userid = 0) { - global $USER; + global $USER, $DB; if (empty($userid)) { $userid = $USER->id; @@ -1413,8 +1443,9 @@ function lesson_grade($lesson, $ntries, $userid = 0) { $total = 0; $earned = 0; - if ($useranswers = get_records_select("lesson_attempts", "lessonid = $lesson->id AND - userid = $userid AND retry = $ntries", "timeseen")) { + $params = array ("lessonid" => $lesson->id, "userid" => $userid, "retry" => $ntries); + if ($useranswers = $DB->get_records_select("lesson_attempts", "lessonid = :lessonid AND + userid = :userid AND retry = :retry", $params, "timeseen")) { // group each try with its page $attemptset = array(); foreach ($useranswers as $useranswer) { @@ -1426,11 +1457,11 @@ function lesson_grade($lesson, $ntries, $userid = 0) { $attemptset[$key] = array_slice($set, 0, $lesson->maxattempts); } - $pageids = implode(",", array_keys($attemptset)); - // get only the pages and their answers that the user answered - $pages = get_records_select("lesson_pages", "lessonid = $lesson->id AND id IN($pageids)"); - $answers = get_records_select("lesson_answers", "lessonid = $lesson->id AND pageid IN($pageids)"); + list($usql, $parameters) = $DB->get_in_or_equal(array_keys($attemptset)); + $parameters["lessonid"] = $lesson->id; + $pages = $DB->get_records_select("lesson_pages", "lessonid = :lessonid AND id $usql", $parameters); + $answers = $DB->get_records_select("lesson_answers", "lessonid = :lessonid AND pageid $usql", $parameters); // Number of pages answered $nquestions = count($pages); @@ -1573,7 +1604,7 @@ function lesson_qtype_menu($qtypes, $selected="", $link="", $onclick="") { * @return boolean The return is not significant as of yet. Will return true/false. **/ function lesson_print_progress_bar($lesson, $course) { - global $CFG, $USER; + global $CFG, $USER, $DB; $cm = get_coursemodule_from_instance('lesson', $lesson->id); $context = get_context_instance(CONTEXT_MODULE, $cm->id); @@ -1589,7 +1620,7 @@ function lesson_print_progress_bar($lesson, $course) { } if (!isset($USER->modattempts[$lesson->id])) { // all of the lesson pages - if (!$pages = get_records('lesson_pages', 'lessonid', $lesson->id)) { + if (!$pages = $DB->get_records('lesson_pages', array('lessonid' => $lesson->id))) { return false; } else { foreach ($pages as $page) { @@ -1608,11 +1639,12 @@ function lesson_print_progress_bar($lesson, $course) { $viewedpageids = array(); // collect all of the correctly answered questions - if ($viewedpages = get_records_select("lesson_attempts", "lessonid = $lesson->id AND userid = $USER->id AND retry = $ntries AND correct = 1", 'timeseen DESC', 'pageid, id')) { + $params = array ("lessonid" => $lesson->id, "userid" => $USER->id, "retry" => $ntries); + if ($viewedpages = $DB->get_records_select("lesson_attempts", "lessonid = :lessonid AND userid = :userid AND retry = :retry AND correct = 1", $params, 'timeseen DESC', 'pageid, id')) { $viewedpageids = array_keys($viewedpages); } // collect all of the branch tables viewed - if ($viewedbranches = get_records_select("lesson_branch", "lessonid = $lesson->id AND userid = $USER->id AND retry = $ntries", 'timeseen DESC', 'pageid, id')) { + if ($viewedbranches = $DB->get_records_select("lesson_branch", "lessonid = :lessonid AND userid = :userid AND retry = :retry", $params, 'timeseen DESC', 'pageid, id')) { $viewedpageids = array_merge($viewedpageids, array_keys($viewedbranches)); } @@ -1681,11 +1713,12 @@ function lesson_print_progress_bar($lesson, $course) { * @return boolean 0 if the user cannot see, or $lesson->displayleft to keep displayleft unchanged **/ function lesson_displayleftif($lesson) { - global $CFG, $USER; + global $CFG, $USER, $DB; if (!empty($lesson->displayleftif)) { // get the current user's max grade for this lesson - if ($maxgrade = get_record_sql('SELECT userid, MAX(grade) AS maxgrade FROM '.$CFG->prefix.'lesson_grades WHERE userid = '.$USER->id.' AND lessonid = '.$lesson->id.' GROUP BY userid')) { + $params = array ("userid" => $USER->id, "lessonid" => $lesson->id); + if ($maxgrade = $DB->get_record_sql('SELECT userid, MAX(grade) AS maxgrade FROM {lesson_grades} WHERE userid = :userid AND lessonid = :lessonid GROUP BY userid', $params)) { if ($maxgrade->maxgrade < $lesson->displayleftif) { return 0; // turn off the displayleft } @@ -1761,11 +1794,12 @@ function lesson_print_clock_block($cmid, $lesson, $timer) { * @return void **/ function lesson_print_menu_block($cmid, $lesson) { - global $CFG; + global $CFG, $DB; if ($lesson->displayleft) { - $pageid = get_field('lesson_pages', 'id', 'lessonid', $lesson->id, 'prevpageid', 0); - $pages = get_records_select('lesson_pages', "lessonid = $lesson->id"); + $pageid = $DB->get_field('lesson_pages', 'id', array('lessonid' => $lesson->id, 'prevpageid' => 0)); + $params = array ("lessonid" => $lesson->id); + $pages = $DB->get_records_select('lesson_pages', "lessonid = :lessonid", $params); $currentpageid = optional_param('pageid', $pageid, PARAM_INT); if ($pageid and $pages) { diff --git a/mod/lesson/mediafile.php b/mod/lesson/mediafile.php index 2839c1713aa..356a140b8ab 100644 --- a/mod/lesson/mediafile.php +++ b/mod/lesson/mediafile.php @@ -22,11 +22,11 @@ print_error('Course Module ID was incorrect'); } - if (! $course = get_record('course', 'id', $cm->course)) { + if (! $course = $DB->get_record('course', array('id' => $cm->course))) { print_error('Course is misconfigured'); } - if (! $lesson = get_record('lesson', 'id', $cm->instance)) { + if (! $lesson = $DB->get_record('lesson', array('id' => $cm->instance))) { print_error('Course module is incorrect'); } diff --git a/mod/lesson/mod_form.php b/mod/lesson/mod_form.php index 57a3ba6277f..806d2360d28 100644 --- a/mod/lesson/mod_form.php +++ b/mod/lesson/mod_form.php @@ -295,6 +295,8 @@ class mod_lesson_mod_form extends moodleform_mod { * @return void **/ function data_preprocessing(&$default_values) { + global $DB; + //var_dump($default_values); if (isset($default_values['conditions'])) { $conditions = unserialize($default_values['conditions']); $default_values['timespent'] = $conditions->timespent; @@ -304,7 +306,7 @@ class mod_lesson_mod_form extends moodleform_mod { if (isset($default_values['password'])) { unset($default_values['password']); } - if (isset($default_values['add']) and $defaults = get_record('lesson_default', 'course', $default_values['course'])) { + if (isset($default_values['add']) and $defaults = $DB->get_record('lesson_default', array('course' => $default_values['course']))) { foreach ($defaults as $fieldname => $default) { switch ($fieldname) { case 'conditions': diff --git a/mod/lesson/report.php b/mod/lesson/report.php index 15cf1c82198..5775b75dd4d 100644 --- a/mod/lesson/report.php +++ b/mod/lesson/report.php @@ -17,25 +17,26 @@ $nothingtodisplay = false; list($cm, $course, $lesson) = lesson_get_basics($id); - + $params = array("lessonid" => $lesson->id); if (!empty($CFG->enablegroupings) && !empty($cm->groupingid)) { + $params["groupid"] = $cm->groupingid; $sql = "SELECT DISTINCT u.* - FROM {$CFG->prefix}lesson_attempts a - INNER JOIN {$CFG->prefix}user u ON u.id = a.userid - INNER JOIN {$CFG->prefix}groups_members gm ON gm.userid = u.id - INNER JOIN {$CFG->prefix}groupings_groups gg ON gm.groupid = {$cm->groupingid} - WHERE a.lessonid = '$lesson->id' + FROM {lesson_attempts} a + INNER JOIN {user} u ON u.id = a.userid + INNER JOIN {groups_members} gm ON gm.userid = u.id + INNER JOIN {groupings_groups} gg ON gm.groupid = :groupid + WHERE a.lessonid = :lessonid ORDER BY u.lastname"; } else { $sql = "SELECT u.* - FROM {$CFG->prefix}user u, - {$CFG->prefix}lesson_attempts a - WHERE a.lessonid = '$lesson->id' and + FROM {user} u, + {lesson_attempts} a + WHERE a.lessonid = :lessonid and u.id = a.userid ORDER BY u.lastname"; } - if (! $students = get_records_sql($sql)) { + if (! $students = $DB->get_records_sql($sql, $params)) { $nothingtodisplay = true; } @@ -63,26 +64,27 @@ $try -= $modifier; /// Clean up the timer table - $timeid = get_field_sql("SELECT id FROM {$CFG->prefix}lesson_timer - WHERE userid = $userid AND lessonid = $lesson->id - ORDER BY starttime", $try, 1); + $params = array ("userid" => $userid, "lessonid" => $lesson->id); + $timeid = $DB->get_field_sql("SELECT id FROM {lesson_timer} + WHERE userid = :userid AND lessonid = :lessonid + ORDER BY starttime", $params, $try, 1); - delete_records('lesson_timer', 'id', $timeid); + $DB->delete_records('lesson_timer', array('id' => $timeid)); /// Remove the grade from the grades and high_scores tables - $gradeid = get_field_sql("SELECT id FROM {$CFG->prefix}lesson_grades - WHERE userid = $userid AND lessonid = $lesson->id - ORDER BY completed", $try, 1); + $gradeid = $DB->get_field_sql("SELECT id FROM {lesson_grades} + WHERE userid = :userid AND lessonid = :lessonid + ORDER BY completed", $params, $try, 1); - delete_records('lesson_grades', 'id', $gradeid); - delete_records('lesson_high_scores', 'gradeid', $gradeid, 'lessonid', $lesson->id, 'userid', $userid); + $DB->delete_records('lesson_grades', array('id' => $gradeid)); + $DB->delete_records('lesson_high_scores', array('gradeid' => $gradeid, 'lessonid' => $lesson->id, 'userid' => $userid)); /// Remove attempts and update the retry number - delete_records('lesson_attempts', 'userid', $userid, 'lessonid', $lesson->id, 'retry', $try); + $DB->delete_records('lesson_attempts', array('userid' => $userid, 'lessonid' => $lesson->id, 'retry' => $try)); execute_sql("UPDATE {$CFG->prefix}lesson_attempts SET retry = retry - 1 WHERE userid = $userid AND lessonid = $lesson->id AND retry > $try", false); /// Remove seen branches and update the retry number - delete_records('lesson_branch', 'userid', $userid, 'lessonid', $lesson->id, 'retry', $try); + $DB->delete_records('lesson_branch', array('userid' => $userid, 'lessonid' => $lesson->id, 'retry' => $try)); execute_sql("UPDATE {$CFG->prefix}lesson_branch SET retry = retry - 1 WHERE userid = $userid AND lessonid = $lesson->id AND retry > $try", false); /// update central gradebook @@ -95,15 +97,15 @@ } } - if (! $attempts = get_records('lesson_attempts', 'lessonid', $lesson->id, 'timeseen')) { + if (! $attempts = $DB->get_records('lesson_attempts', array('lessonid' => $lesson->id), 'timeseen')) { $nothingtodisplay = true; } - if (! $grades = get_records('lesson_grades', 'lessonid', $lesson->id, 'completed')) { + if (! $grades = $DB->get_records('lesson_grades', array('lessonid' => $lesson->id), 'completed')) { $grades = array(); } - if (! $times = get_records('lesson_timer', 'lessonid', $lesson->id, 'starttime')) { + if (! $times = $DB->get_records('lesson_timer', array('lessonid' => $lesson->id), 'starttime')) { $times = array(); } @@ -343,10 +345,10 @@ $userid = optional_param('userid', NULL, PARAM_INT); // if empty, then will display the general detailed view $try = optional_param('try', NULL, PARAM_INT); - if (! $lessonpages = get_records("lesson_pages", "lessonid", $lesson->id)) { + if (! $lessonpages = $DB->get_records("lesson_pages", array("lessonid" => $lesson->id))) { print_error("Could not find Lesson Pages"); } - if (! $pageid = get_field("lesson_pages", "id", "lessonid", $lesson->id, "prevpageid", 0)) { + if (! $pageid = $DB->get_field("lesson_pages", "id", array("lessonid" => $lesson->id, "prevpageid" => 0))) { print_error("Could not find first page"); } @@ -355,8 +357,8 @@ $pagestats = array(); while ($pageid != 0) { // EOL $page = $lessonpages[$pageid]; - - if ($allanswers = get_records_select("lesson_attempts", "lessonid = $lesson->id AND pageid = $page->id", "timeseen")) { + $params = array ("lessonid" => $lesson->id, "pageid" => $page->id); + if ($allanswers = $DB->get_records_select("lesson_attempts", "lessonid = :lessonid AND pageid = :pageid", $params, "timeseen")) { // get them ready for processing $orderedanswers = array(); foreach ($allanswers as $singleanswer) { @@ -522,9 +524,10 @@ $useranswer = NULL; $answerdata->score = NULL; $answerdata->response = NULL; - } elseif ($useranswers = get_records_select("lesson_attempts", - "lessonid = $lesson->id AND userid = $userid AND retry = $try AND pageid = $page->id", "timeseen")) { - // get the user's answer for this page + } elseif ($useranswers = $DB->get_records_select("lesson_attempts", + "lessonid = :lessonid AND userid = :userid AND retry = :retry AND pageid = :pageid", + array("lessonid" => $lesson->id, "userid" => $userid, "retry" => $try, "pageid" => $page->id), "timeseen")) { + // get the user's answer for this page // need to find the right one $i = 0; foreach ($useranswers as $userattempt) { @@ -543,7 +546,7 @@ } // build up the answer data - if ($answers = get_records("lesson_answers", "pageid", $page->id, "id")) { + if ($answers = $DB->get_records("lesson_answers", array("pageid" => $page->id), "id")) { $i = 0; $n = 0; // go through each answer and display it properly with statistics, highlight if correct answer, @@ -835,7 +838,8 @@ $table->align = array("right", "left"); $table->class = 'generaltable userinfotable'; - if (!$grades = get_records_select("lesson_grades", "lessonid = $lesson->id and userid = $userid", "completed", "*", $try, 1)) { + $params = array ("lessonid" => $lesson->id, "userid" => $userid); + if (!$grades = $DB->get_records_select("lesson_grades", "lessonid = :lessonid and userid = :userid", $params, "completed", "*", $try, 1)) { $grade = -1; $completed = -1; } else { @@ -843,7 +847,7 @@ $completed = $grade->completed; $grade = round($grade->grade, 2); } - if (!$times = get_records_select("lesson_timer", "lessonid = $lesson->id and userid = $userid", "starttime", "*", $try, 1)) { + if (!$times = $DB->get_records_select("lesson_timer", "lessonid = :lessonid and userid = :userid", $params, "starttime", "*", $try, 1)) { $timetotake = -1; } else { $timetotake = current($times); diff --git a/mod/lesson/tabs.php b/mod/lesson/tabs.php index 4f27e65d09f..a09bed30490 100644 --- a/mod/lesson/tabs.php +++ b/mod/lesson/tabs.php @@ -22,7 +22,7 @@ $context = get_context_instance(CONTEXT_MODULE, $cm->id); } if (!isset($course)) { - $course = get_record('course', 'id', $lesson->course); + $course = $DB->get_record('course', array('id' => $lesson->course)); } $tabs = $row = $inactive = $activated = array(); diff --git a/mod/lesson/view.php b/mod/lesson/view.php index d1f5705f7db..f52a2a9ce99 100644 --- a/mod/lesson/view.php +++ b/mod/lesson/view.php @@ -85,7 +85,7 @@ } } else if ($lesson->dependency) { // check for dependencies - if ($dependentlesson = get_record('lesson', 'id', $lesson->dependency)) { + if ($dependentlesson = $DB->get_record('lesson', array('id' => $lesson->dependency))) { // lesson exists, so we can proceed $conditions = unserialize($lesson->conditions); // assume false for all @@ -94,7 +94,8 @@ $gradebetterthan = false; // check for the timespent condition if ($conditions->timespent) { - if ($attempttimes = get_records_select('lesson_timer', "userid = $USER->id AND lessonid = $dependentlesson->id")) { + $params = array ("userid" => $USER->id, "lessonid" => $dependentlesson->id); + if ($attempttimes = $DB->get_records_select('lesson_timer', "userid = :userid AND lessonid = :lessonid", $params)) { // go through all the times and test to see if any of them satisfy the condition foreach($attempttimes as $attempttime) { $duration = $attempttime->lessontime - $attempttime->starttime; @@ -109,7 +110,8 @@ // check for the gradebetterthan condition if($conditions->gradebetterthan) { - if ($studentgrades = get_records_select('lesson_grades', "userid = $USER->id AND lessonid = $dependentlesson->id")) { + $params = array ("userid" => $USER->id, "lessonid" => $dependentlesson->id); + if ($studentgrades = $DB->get_records_select('lesson_grades', "userid = :userid AND lessonid = :lessonid", $params)) { // go through all the grades and test to see if any of them satisfy the condition foreach($studentgrades as $studentgrade) { if ($studentgrade->grade >= $conditions->gradebetterthan) { @@ -174,7 +176,7 @@ $attemptflag = false; if (empty($pageid)) { // make sure there are pages to view - if (!get_field('lesson_pages', 'id', 'lessonid', $lesson->id, 'prevpageid', 0)) { + if (!$DB->get_field('lesson_pages', 'id', array('lessonid' => $lesson->id, 'prevpageid' => 0))) { if (!has_capability('mod/lesson:manage', $context)) { lesson_set_message(get_string('lessonnotready', 'lesson', $course->teacher)); // a nice message to the student } else { @@ -189,7 +191,8 @@ add_to_log($course->id, 'lesson', 'start', 'view.php?id='. $cm->id, $lesson->id, $cm->id); // if no pageid given see if the lesson has been started - if ($grades = get_records_select('lesson_grades', 'lessonid = '. $lesson->id .' AND userid = '. $USER->id, + $params = array ("lessonid" => $lesson->id, "userid" => $USER->id); + if ($grades = $DB->get_records_select('lesson_grades', 'lessonid = :lessonid AND userid = :userid', $params, 'grade DESC')) { $retries = count($grades); } else { @@ -204,18 +207,18 @@ } // if there are any questions have been answered correctly in this attempt - if ($attempts = get_records_select('lesson_attempts', - "lessonid = $lesson->id AND userid = $USER->id AND retry = $retries AND - correct = 1", 'timeseen DESC')) { + $params = array ("lessonid" => $lesson->id, "userid" => $USER->id, "retry" => $retries); + if ($attempts = $DB->get_records_select('lesson_attempts', + "lessonid = :lessonid AND userid = :userid AND retry = :retry AND + correct = 1", $params, 'timeseen DESC')) { foreach ($attempts as $attempt) { - $jumpto = get_field('lesson_answers', 'jumpto', 'id', $attempt->answerid); + $jumpto = $DB->get_field('lesson_answers', 'jumpto', array('id' => $attempt->answerid)); // convert the jumpto to a proper page id if ($jumpto == 0) { // unlikely value! $lastpageseen = $attempt->pageid; } elseif ($jumpto == LESSON_NEXTPAGE) { - if (!$lastpageseen = get_field('lesson_pages', 'nextpageid', 'id', - $attempt->pageid)) { + if (!$lastpageseen = $DB->get_field('lesson_pages', 'nextpageid', array('id' => $attempt->pageid))) { // no nextpage go to end of lesson $lastpageseen = LESSON_EOL; } @@ -228,8 +231,9 @@ $attempts = NULL; } - if ($branchtables = get_records_select('lesson_branch', - "lessonid = $lesson->id AND userid = $USER->id AND retry = $retries", 'timeseen DESC')) { + $params = array ("lessonid" => $lesson->id, "userid" => $USER->id, "retry" => $retries); + if ($branchtables = $DB->get_records_select('lesson_branch', + "lessonid = :lessonid AND userid = :userid AND retry = :retry", $params, 'timeseen DESC')) { // in here, user has viewed a branch table $lastbranchtable = current($branchtables); if ($attempts != NULL) { @@ -248,8 +252,8 @@ //if ($lastpageseen != $firstpageid) { if (isset($lastpageseen) and count_records('lesson_attempts', 'lessonid', $lesson->id, 'userid', $USER->id, 'retry', $retries) > 0) { // get the first page - if (!$firstpageid = get_field('lesson_pages', 'id', 'lessonid', $lesson->id, - 'prevpageid', 0)) { + if (!$firstpageid = $DB->get_field('lesson_pages', 'id', array('lessonid' => $lesson->id, + 'prevpageid' => 0))) { print_error('Navigation: first page not found'); } lesson_print_header($cm, $course, $lesson); @@ -308,7 +312,7 @@ } } // start at the first page - if (!$pageid = get_field('lesson_pages', 'id', 'lessonid', $lesson->id, 'prevpageid', 0)) { + if (!$pageid = $DB->get_field('lesson_pages', 'id', array('lessonid' => $lesson->id, 'prevpageid' => 0))) { print_error('Navigation: first page not found'); } /// This is the code for starting a timed test @@ -320,7 +324,7 @@ $startlesson->starttime = time(); $startlesson->lessontime = time(); - if (!insert_record('lesson_timer', $startlesson)) { + if (!$DB->insert_record('lesson_timer', $startlesson)) { print_error('Error: could not insert row into lesson_timer table'); } if ($lesson->timed) { @@ -332,16 +336,17 @@ /// This is the code updates the lessontime for a timed test if ($startlastseen = optional_param('startlastseen', '', PARAM_ALPHA)) { /// this deletes old records not totally sure if this is necessary anymore if ($startlastseen == 'no') { - if ($grades = get_records_select('lesson_grades', "lessonid = $lesson->id AND userid = $USER->id", + $params = array ("lessonid" => $lesson->id, "userid" => $USER->id); + if ($grades = $DB->get_records_select('lesson_grades', "lessonid = :lessonid AND userid = :userid", $params, 'grade DESC')) { $retries = count($grades); } else { $retries = 0; } - if (!delete_records('lesson_attempts', 'userid', $USER->id, 'lessonid', $lesson->id, 'retry', $retries)) { + if (!$DB->delete_records('lesson_attempts', array('userid' => $USER->id, 'lessonid' => $lesson->id, 'retry' => $retries))) { print_error('Error: could not delete old attempts'); } - if (!delete_records('lesson_branch', 'userid', $USER->id, 'lessonid', $lesson->id, 'retry', $retries)) { + if (!$DB->delete_records('lesson_branch', array('userid' => $USER->id, 'lessonid' => $lesson->id, 'retry' => $retries))) { print_error('Error: could not delete old seen branches'); } } @@ -349,7 +354,7 @@ add_to_log($course->id, 'lesson', 'view', 'view.php?id='. $cm->id, $pageid, $cm->id); - if (!$page = get_record('lesson_pages', 'id', $pageid)) { + if (!$page = $DB->get_record('lesson_pages', array('id' => $pageid))) { print_error('Navigation: the page record not found'); } @@ -358,14 +363,14 @@ // get new id $pageid = lesson_cluster_jump($lesson->id, $USER->id, $pageid); // get new page info - if (!$page = get_record('lesson_pages', 'id', $pageid)) { + if (!$page = $DB->get_record('lesson_pages', array('id' => $pageid))) { print_error('Navigation: the page record not found'); } add_to_log($course->id, 'lesson', 'view', 'view.php?id='. $cm->id, $pageid, $cm->id); } else { // get the next page $pageid = $page->nextpageid; - if (!$page = get_record('lesson_pages', 'id', $pageid)) { + if (!$page = $DB->get_record('lesson_pages', array('id' => $pageid))) { print_error('Navigation: the page record not found'); } } @@ -377,7 +382,7 @@ } redirect("$CFG->wwwroot/mod/lesson/view.php?id=$cm->id&pageid=$nextpageid"); } else if ($page->qtype == LESSON_ENDOFBRANCH) { // Check for endofbranches - if ($answers = get_records('lesson_answers', 'pageid', $page->id, 'id')) { + if ($answers = $DB->get_records('lesson_answers', array('pageid' => $page->id), 'id')) { // print_heading(get_string('endofbranch', 'lesson')); foreach ($answers as $answer) { // just need the first answer @@ -424,7 +429,8 @@ // get time information for this user $timer = new stdClass; if(!has_capability('mod/lesson:manage', $context)) { - if (!$timer = get_records_select('lesson_timer', "lessonid = $lesson->id AND userid = $USER->id", 'starttime')) { + $params = array ("lessonid" => $lesson->id, "userid" => $USER->id); + if (!$timer = $DB->get_records_select('lesson_timer', "lessonid = :lessonid AND userid = :userid", $params, 'starttime')) { print_error('Error: could not find records'); } else { $timer = array_pop($timer); // this will get the latest start time record @@ -463,7 +469,7 @@ // update the clock if (!has_capability('mod/lesson:manage', $context)) { $timer->lessontime = time(); - if (!update_record('lesson_timer', $timer)) { + if (!$DB->update_record('lesson_timer', $timer)) { print_error('Error: could not update lesson_timer table'); } } @@ -545,14 +551,15 @@ if (isset($USER->modattempts[$lesson->id])) { $retries = count_records('lesson_grades', "lessonid", $lesson->id, "userid", $USER->id); $retries--; - if (! $attempts = get_records_select("lesson_attempts", "lessonid = $lesson->id AND userid = $USER->id AND pageid = $page->id AND retry = $retries", "timeseen")) { + $params = array ("lessonid" => $lesson->id, "userid" => $USER->id, "pageid" => $page->id, "retry" => $retries); + if (! $attempts = $DB->get_records_select("lesson_attempts", "lessonid = :lessonid AND userid = :userid AND pageid = :pageid AND retry = :retry", $params, "timeseen")) { print_error("Previous attempt record could not be found!"); } $attempt = end($attempts); } // get the answers in a set order, the id order - if ($answers = get_records("lesson_answers", "pageid", $page->id, "id")) { + if ($answers = $DB->get_records("lesson_answers", array("pageid" => $page->id), "id")) { if ($page->qtype != LESSON_BRANCHTABLE) { // To fix XHTML problem (BT have their own forms) echo "

"; echo '
'; @@ -771,7 +778,7 @@ // ...first get number of retakes $nretakes = count_records("lesson_grades", "lessonid", $lesson->id, "userid", $USER->id); // ...then get the page ids (lessonid the 5th param is needed to make get_records play) - $allpages = get_records("lesson_pages", "lessonid", $lesson->id, "id", "id,lessonid"); + $allpages = $DB->get_records("lesson_pages", array("lessonid" => $lesson->id), "id", "id,lessonid"); shuffle ($allpages); $found = false; if ($lesson->nextpagedefault == LESSON_UNSEENPAGE) { @@ -805,7 +812,7 @@ } } else { // in normal lesson mode... - if (!$newpageid = get_field("lesson_pages", "nextpageid", "id", $pageid)) { + if (!$newpageid = $DB->get_field("lesson_pages", "nextpageid", array("id" => $pageid))) { // this is the last page - flag end of lesson $newpageid = LESSON_EOL; } @@ -828,14 +835,15 @@ // Update the clock / get time information for this user if (!has_capability('mod/lesson:manage', $context)) { unset($USER->startlesson[$lesson->id]); - if (!$timer = get_records_select('lesson_timer', "lessonid = $lesson->id AND userid = $USER->id", 'starttime')) { + $params = array ("lessonid" => $lesson->id, "userid" => $USER->id); + if (!$timer = $DB->get_records_select('lesson_timer', "lessonid = :lessonid AND userid = :userid", $params, 'starttime')) { print_error('Error: could not find records'); } else { $timer = array_pop($timer); // this will get the latest start time record } $timer->lessontime = time(); - if (!update_record("lesson_timer", $timer)) { + if (!$DB->update_record("lesson_timer", $timer)) { print_error("Error: could not update lesson_timer table"); } } @@ -888,21 +896,22 @@ $grade->completed = time(); if (!$lesson->practice) { if (isset($USER->modattempts[$lesson->id])) { // if reviewing, make sure update old grade record - if (!$grades = get_records_select("lesson_grades", "lessonid = $lesson->id and userid = $USER->id", "completed")) { + $params = array ("lessonid" => $lesson->id, "userid" => $USER->id); + if (!$grades = $DB->get_records_select("lesson_grades", "lessonid = :lessonid and userid = :userid", $params, "completed")) { print_error("Could not find Grade Records"); } $oldgrade = end($grades); $grade->id = $oldgrade->id; - if (!$update = update_record("lesson_grades", $grade)) { + if (!$update = $DB->update_record("lesson_grades", $grade)) { print_error("Navigation: grade not updated"); } } else { - if (!$newgradeid = insert_record("lesson_grades", $grade)) { + if (!$newgradeid = $DB->insert_record("lesson_grades", $grade)) { print_error("Navigation: grade not inserted"); } } } else { - if (!delete_records("lesson_attempts", "lessonid", $lesson->id, "userid", $USER->id, "retry", $ntries)) { + if (!$DB->delete_records("lesson_attempts", array("lessonid" => $lesson->id, "userid" => $USER->id, "retry" => $ntries))) { print_error("Could not delete lesson attempts"); } } @@ -915,7 +924,7 @@ $grade->grade = 0; $grade->completed = time(); if (!$lesson->practice) { - if (!$newgradeid = insert_record("lesson_grades", $grade)) { + if (!$newgradeid = $DB->insert_record("lesson_grades", $grade)) { print_error("Navigation: grade not inserted"); } } @@ -944,9 +953,10 @@ // high scores code if ($lesson->highscores && !has_capability('mod/lesson:manage', $context) && !$lesson->practice) { echo "

"; - if ($grades = get_records_select("lesson_grades", "lessonid = $lesson->id", "completed")) { + $params = array ("lessonid" => $lesson->id); + if ($grades = $DB->get_records_select("lesson_grades", "lessonid = :lessonid", $params, "completed")) { $madeit = false; - if ($highscores = get_records_select("lesson_high_scores", "lessonid = $lesson->id")) { + if ($highscores = $DB->get_records_select("lesson_high_scores", "lessonid = :lessonid", $params)) { // get all the high scores into an array $topscores = array(); $uniquescores = array(); @@ -989,7 +999,8 @@ // look at the attempt records to find the first QUESTION page that the user answered, then use that page id // to pass to view again. This is slick cause it wont call the empty($pageid) code // $ntries is decremented above - if (!$attempts = get_records_select("lesson_attempts", "lessonid = $lesson->id AND userid = $USER->id AND retry = $ntries", "timeseen")) { + $params = array ("lessonid" => $lesson->id, "userid" => $USER->id, "retry" => $ntries); + if (!$attempts = $DB->get_records_select("lesson_attempts", "lessonid = :lessonid AND userid = :userid AND retry = :retry", $params, "timeseen")) { $attempts = array(); } $firstattempt = current($attempts); @@ -1004,9 +1015,9 @@ } if ($lesson->activitylink) { - if ($module = get_record('course_modules', 'id', $lesson->activitylink)) { - if ($modname = get_field('modules', 'name', 'id', $module->module)) - if ($instance = get_record($modname, 'id', $module->instance)) { + if ($module = $DB->get_record('course_modules', array('id' => $lesson->activitylink))) { + if ($modname = $DB->get_field('modules', 'name', array('id' => $module->module))) + if ($instance = $DB->get_record($modname, array('id' => $module->instance))) { echo "\n";