From e57bc529daa07fddac9a9233aa441428646f09b5 Mon Sep 17 00:00:00 2001 From: jerome Date: Mon, 9 Jun 2008 02:08:59 +0000 Subject: [PATCH] MDL-15112 lesson dml conversion --- mod/lesson/essay.php | 6 ++---- mod/lesson/highscores.php | 7 +++---- mod/lesson/lib.php | 12 ++---------- mod/lesson/locallib.php | 9 +++------ 4 files changed, 10 insertions(+), 24 deletions(-) diff --git a/mod/lesson/essay.php b/mod/lesson/essay.php index bec46d05b68..cf0ae5f7418 100644 --- a/mod/lesson/essay.php +++ b/mod/lesson/essay.php @@ -32,10 +32,8 @@ 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; + $params["groupinid"] = $cm->groupingid; $sql = "SELECT DISTINCT u.* FROM {lesson_attempts} a INNER JOIN {user} u ON u.id = a.userid @@ -51,7 +49,7 @@ u.id = a.userid ORDER BY u.lastname"; } - if (!$users = $DB->get_records_sql($sql, $paras)) { + if (!$users = $DB->get_records_sql($sql, $params)) { $mode = 'none'; // not displaying anything lesson_set_message(get_string('noonehasanswered', 'lesson')); } diff --git a/mod/lesson/highscores.php b/mod/lesson/highscores.php index 2e113e749c5..d352732f228 100644 --- a/mod/lesson/highscores.php +++ b/mod/lesson/highscores.php @@ -53,16 +53,16 @@ if ($mode == 'add') { break; } - $params = array ("lessonid" => $lesson->id); + $params = array ("lessonid" => $lesson->id, "userid" => $USER->id); if (!$grades = $DB->get_records_select('lesson_grades', "lessonid = :lessonid", $params, 'completed')) { print_error('Error: could not find grades'); } - $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)) { + ORDER BY completed DESC", $params, true)) { print_error('Error: could not find newest grade'); } @@ -72,7 +72,6 @@ } // Find out if we need to delete any records - $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 diff --git a/mod/lesson/lib.php b/mod/lesson/lib.php index 5e475cf4081..ea1d7c6671c 100644 --- a/mod/lesson/lib.php +++ b/mod/lesson/lib.php @@ -325,25 +325,17 @@ function lesson_cron () { function lesson_get_user_grades($lesson, $userid=0) { global $CFG, $DB; - $params = array(); + $params = array("lessonid" => $lesson->id); 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 { + $user=""; $fuser=""; } - - $params["lessonid"] = $lesson->id; if ($lesson->retake) { if ($lesson->usemaxgrade) { diff --git a/mod/lesson/locallib.php b/mod/lesson/locallib.php index 6efc88d02fa..a6c12b2adef 100644 --- a/mod/lesson/locallib.php +++ b/mod/lesson/locallib.php @@ -1081,8 +1081,7 @@ function lesson_cluster_jump($lessonid, $userid, $pageid) { } // get the lesson pages - $parameters = array ("lessonid" => $lessonid); - if (!$lessonpages = $DB->get_records_select("lesson_pages", "lessonid = :lessonid", $parameters)) { + if (!$lessonpages = $DB->get_records_select("lesson_pages", "lessonid = :lessonid", $params)) { print_error("Error: could not find records in lesson_pages table"); } // find the start of the cluster @@ -1213,8 +1212,7 @@ function lesson_unseen_question_jump($lesson, $user, $pageid) { } // get the lesson pages - $parameters = array ("lessonid" => $lesson); - if (!$lessonpages = $DB->get_records_select("lesson_pages", "lessonid = :lessonid", $parameters)) { + if (!$lessonpages = $DB->get_records_select("lesson_pages", "lessonid = :lessonid", $params)) { print_error("Error: could not find records in lesson_pages table"); } @@ -1279,8 +1277,7 @@ function lesson_unseen_branch_jump($lessonid, $userid) { } // get the lesson pages - $parameters = array ("lessonid" => $lessonid); - if (!$lessonpages = $DB->get_records_select("lesson_pages", "lessonid = :lessonid", $parameters)) { + if (!$lessonpages = $DB->get_records_select("lesson_pages", "lessonid = :lessonid", $params)) { print_error("Error: could not find records in lesson_pages table"); }