MDL-15112 converted some skipped dml stuff

This commit is contained in:
skodak 2008-06-09 12:29:40 +00:00
parent dfee5a9a8a
commit 318e374544
8 changed files with 45 additions and 46 deletions

View File

@ -553,7 +553,7 @@
$newpageid = $pageid; // display same page again
$feedback = get_string('noanswer', 'lesson');
} else {
$nretakes = count_records("lesson_grades", "lessonid", $lesson->id, "userid", $USER->id);
$nretakes = $DB->count_records("lesson_grades", array("lessonid"=>$lesson->id, "userid"=>$USER->id));
if (!has_capability('mod/lesson:manage', $context)) {
// record student's attempt
$attempt = new stdClass;
@ -580,7 +580,7 @@
if (!$correctanswer and ($newpageid == 0)) {
// wrong answer and student is stuck on this page - check how many attempts
// the student has had at this page/question
$nattempts = count_records("lesson_attempts", "pageid", $pageid, "userid", $USER->id,
$nattempts = $DB->count_records("lesson_attempts", array("pageid"=>$pageid, "userid"=>$USER->id),
"retry", $nretakes);
// retreive the number of attempts left counter for displaying at bottom of feedback page
@ -600,14 +600,13 @@
} elseif ($newpageid == LESSON_NEXTPAGE) {
if ($lesson->nextpagedefault) {
// in Flash Card mode...
// ... first get the page ids (lessonid the 5th param is needed to make get_records play)
// ... first get the page ids (lessonid the 5th param is needed to make $DB->get_records play)
$allpages = $DB->get_records("lesson_pages", array("lessonid" => $lesson->id), "id", "id,lessonid,qtype");
shuffle ($allpages);
$found = false;
if ($lesson->nextpagedefault == LESSON_UNSEENPAGE) {
foreach ($allpages as $thispage) {
if (!count_records("lesson_attempts", "pageid", $thispage->id, "userid",
$USER->id, "retry", $nretakes)) {
if (!$DB->count_records("lesson_attempts", array("pageid"=>$thispage->id, "userid"=>$USER->id, "retry"=>$nretakes))) {
$found = true;
break;
}
@ -615,14 +614,12 @@
} elseif ($lesson->nextpagedefault == LESSON_UNANSWEREDPAGE) {
foreach ($allpages as $thispage) {
if ($thispage->qtype == LESSON_ESSAY) {
if (!count_records_select("lesson_attempts", "pageid = $thispage->id AND
userid = $USER->id AND retry = $nretakes")) {
if (!$DB->count_records("lesson_attempts", array('pageid'=>$thispage->id, 'userid'=>$USER->id, 'retry'=>$nretakes))) {
$found = true;
break;
}
} else {
if (!count_records_select("lesson_attempts", "pageid = $thispage->id AND
userid = $USER->id AND correct = 1 AND retry = $nretakes")) {
if (!$DB->count_records("lesson_attempts", array('pageid'=>$thispage->id, 'userid'=>$USER->id, 'correct'=>1, 'retry'=>$nretakes))) {
$found = true;
break;
}
@ -633,8 +630,8 @@
$newpageid = $thispage->id;
if ($lesson->maxpages) {
// check number of pages viewed (in the lesson)
if (count_records("lesson_attempts", "lessonid", $lesson->id, "userid", $USER->id,
"retry", $nretakes) >= $lesson->maxpages) {
if ($DB->count_records("lesson_attempts", array("lessonid"=>$lesson->id, "userid"=>$USER->id,
"retry"=>$nretakes)) >= $lesson->maxpages) {
$newpageid = LESSON_EOL;
}
}
@ -675,8 +672,8 @@
// print_heading($title);
//}
if ($lesson->review and !$correctanswer and !$isessayquestion) {
$nretakes = count_records("lesson_grades", "lessonid", $lesson->id, "userid", $USER->id);
$qattempts = count_records("lesson_attempts", "userid", $USER->id, "retry", $nretakes, "pageid", $pageid);
$nretakes = $DB->count_records("lesson_grades", array("lessonid"=>$lesson->id, "userid"=>$USER->id));
$qattempts = $DB->count_records("lesson_attempts", array("userid"=>$USER->id, "retry"=>$nretakes, "pageid"=>$pageid));
if ($qattempts == 1) {
$feedback = get_string("firstwrong", "lesson");
} else {

View File

@ -268,7 +268,7 @@
$essaylinks = array();
// Number of attempts on the lesson
$attempts = count_records('lesson_grades', 'userid', $userid, 'lessonid', $lesson->id);
$attempts = $DB->count_records('lesson_grades', array('userid'=>$userid, 'lessonid'=>$lesson->id));
// Go through each essay page
foreach ($studentessays[$userid] as $page => $tries) {

View File

@ -461,13 +461,14 @@ function lesson_create_objects($pageobjects, $lessonid) {
Creates objects an chapter object that is to be inserted into the database
*/
function book_create_objects($pageobjects, $bookid) {
global $DB;
$chapters = array();
$chapter = new stdClass;
// same for all chapters
$chapter->bookid = $bookid;
$chapter->pagenum = count_records('book_chapters', 'bookid', $bookid)+1;
$chapter->pagenum = $DB->count_records('book_chapters', array('bookid'=>$bookid))+1;
$chapter->timecreated = time();
$chapter->timemodified = time();
$chapter->subchapter = 0;
@ -475,7 +476,7 @@ function book_create_objects($pageobjects, $bookid) {
$i = 1;
foreach ($pageobjects as $pageobject) {
$page = prep_page($pageobject, $i); // get title and contents
$chapter->importsrc = addslashes($pageobject->source); // add the source
$chapter->importsrc = $pageobject->source; // add the source
$chapter->title = $page->title;
$chapter->content = $page->contents;
$chapters[] = $chapter;
@ -495,7 +496,7 @@ function prep_page($pageobject, $count) {
if ($pageobject->title == '') {
$page->title = "Page $count"; // no title set so make a generic one
} else {
$page->title = addslashes($pageobject->title);
$page->title = $pageobject->title;
}
$page->contents = '';
@ -506,7 +507,7 @@ function prep_page($pageobject, $count) {
$image = str_replace("\r", '', $image);
$image = str_replace("'", '"', $image); // imgstyle
$page->contents .= addslashes($image);
$page->contents .= $image;
}
// go through the contents array and put <p> tags around each element and strip out \n which I have found to be uneccessary
foreach ($pageobject->contents as $content) {
@ -514,7 +515,7 @@ function prep_page($pageobject, $count) {
$content = str_replace("\r", '', $content);
$content = str_replace('&#13;', '', $content); // puts in returns?
$content = '<p>'.$content.'</p>';
$page->contents .= addslashes($content);
$page->contents .= $content;
}
return $page;
}

View File

@ -132,7 +132,7 @@ function lesson_delete_instance($id) {
function lesson_delete_course($course, $feedback=true) {
global $DB;
$count = count_records('lesson_default', 'course', $course->id);
$count = $DB->count_records('lesson_default', array('course'=>$course->id));
$DB->delete_records('lesson_default', array('course' => $course->id));
//Inform about changes performed if feedback is enabled
@ -251,7 +251,7 @@ function lesson_user_complete($course, $user, $mod, $lesson) {
* @param array $htmlarray Store overview output array( course ID => 'lesson' => HTML output )
*/
function lesson_print_overview($courses, &$htmlarray) {
global $USER, $CFG;
global $USER, $CFG, $DB;
if (!$lessons = get_all_instances_in_courses('lesson', $courses)) {
return;
@ -283,11 +283,11 @@ function lesson_print_overview($courses, &$htmlarray) {
// Attempt information
if (has_capability('mod/lesson:manage', get_context_instance(CONTEXT_MODULE, $lesson->coursemodule))) {
// Number of user attempts
$attempts = count_records('lesson_attempts', 'lessonid', $lesson->id);
$attempts = $DB->count_records('lesson_attempts', array('lessonid'=>$lesson->id));
$str .= print_box(get_string('xattempts', 'lesson', $attempts), 'info', '', true);
} else {
// Determine if the user has attempted the lesson or not
if (count_records('lesson_attempts', 'lessonid', $lesson->id, 'userid', $USER->id)) {
if ($DB->count_records('lesson_attempts', array('lessonid'=>$lesson->id, 'userid'=>$USER->id))) {
$str .= print_box($strattempted, 'info', '', true);
} else {
$str .= print_box($strnotattempted, 'info', '', true);

View File

@ -1066,7 +1066,7 @@ function lesson_cluster_jump($lessonid, $userid, $pageid) {
global $DB;
// get the number of retakes
if (!$retakes = count_records("lesson_grades", "lessonid", $lessonid, "userid", $userid)) {
if (!$retakes = $DB->count_records("lesson_grades", array("lessonid"=>$lessonid, "userid"=>$userid))) {
$retakes = 0;
}
@ -1197,7 +1197,7 @@ 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)) {
if (!$retakes = $DB->count_records("lesson_grades", array("lessonid"=>$lesson, "userid"=>$user))) {
$retakes = 0;
}
@ -1266,7 +1266,7 @@ function lesson_unseen_question_jump($lesson, $user, $pageid) {
function lesson_unseen_branch_jump($lessonid, $userid) {
global $DB;
if (!$retakes = count_records("lesson_grades", "lessonid", $lessonid, "userid", $userid)) {
if (!$retakes = $DB->count_records("lesson_grades", array("lessonid"=>$lessonid, "userid"=>$userid))) {
$retakes = 0;
}
@ -1541,14 +1541,15 @@ function lesson_grade($lesson, $ntries, $userid = 0) {
* @return void
**/
function lesson_print_ongoing_score($lesson) {
global $USER;
global $USER, $DB;
$cm = get_coursemodule_from_instance('lesson', $lesson->id);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
if (has_capability('mod/lesson:manage', $context)) {
echo "<p align=\"center\">".get_string('teacherongoingwarning', 'lesson').'</p>';
} else {
$ntries = count_records("lesson_grades", "lessonid", $lesson->id, "userid", $USER->id);
$ntries = $DB->count_records("lesson_grades", array("lessonid"=>$lesson->id, "userid"=>$USER->id));
if (isset($USER->modattempts[$lesson->id])) {
$ntries--;
}
@ -1602,6 +1603,7 @@ function lesson_qtype_menu($qtypes, $selected="", $link="", $onclick="") {
**/
function lesson_print_progress_bar($lesson, $course) {
global $CFG, $USER, $DB;
$cm = get_coursemodule_from_instance('lesson', $lesson->id);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
@ -1629,7 +1631,7 @@ function lesson_print_progress_bar($lesson, $course) {
}
// current attempt number
if (!$ntries = count_records("lesson_grades", "lessonid", $lesson->id, "userid", $USER->id)) {
if (!$ntries = $DB->count_records("lesson_grades", array("lessonid"=>$lesson->id, "userid"=>$USER->id))) {
$ntries = 0; // may not be necessary
}

View File

@ -81,11 +81,11 @@
/// Remove attempts and update the retry number
$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);
$DB->execute("UPDATE {lesson_attempts} SET retry = retry - 1 WHERE userid = ? AND lessonid = ? AND retry > ?", array($userid, $lesson->id, $try));
/// Remove seen branches and update the retry number
$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);
$DB->execute("UPDATE {lesson_branch} SET retry = retry - 1 WHERE userid = ? AND lessonid = ? AND retry > ?", array($userid, $lesson->id, $try));
/// update central gradebook
lesson_update_grades($lesson, $userid);

View File

@ -29,7 +29,7 @@
/// user attempt count for reports link hover (completed attempts - much faster)
$counts = new stdClass;
$counts->attempts = count_records('lesson_grades', 'lessonid', $lesson->id);
$counts->attempts = $DB->count_records('lesson_grades', array('lessonid'=>$lesson->id));
$counts->student = $course->student;
$row[] = new tabobject('view', "$CFG->wwwroot/mod/lesson/view.php?id=$cm->id", get_string('preview', 'lesson'), get_string('previewlesson', 'lesson', format_string($lesson->name)));

View File

@ -125,7 +125,7 @@
// check for the completed condition
if ($conditions->completed) {
if (count_records('lesson_grades', 'userid', $USER->id, 'lessonid', $dependentlesson->id)) {
if ($DB->count_records('lesson_grades', array('userid'=>$USER->id, 'lessonid'=>$dependentlesson->id))) {
$completed = true;
}
} else {
@ -180,7 +180,7 @@
if (!has_capability('mod/lesson:manage', $context)) {
lesson_set_message(get_string('lessonnotready', 'lesson', $course->teacher)); // a nice message to the student
} else {
if (!count_records('lesson_pages', 'lessonid', $lesson->id)) {
if (!$DB->count_records('lesson_pages', array('lessonid'=>$lesson->id))) {
redirect("$CFG->wwwroot/mod/lesson/edit.php?id=$cm->id"); // no pages - redirect to add pages
} else {
lesson_set_message(get_string('lessonpagelinkingbroken', 'lesson')); // ok, bad mojo
@ -250,7 +250,7 @@
}
}
//if ($lastpageseen != $firstpageid) {
if (isset($lastpageseen) and count_records('lesson_attempts', 'lessonid', $lesson->id, 'userid', $USER->id, 'retry', $retries) > 0) {
if (isset($lastpageseen) and $DB->count_records('lesson_attempts', array('lessonid'=>$lesson->id, 'userid'=>$USER->id, 'retry'=>$retries)) > 0) {
// get the first page
if (!$firstpageid = $DB->get_field('lesson_pages', 'id', array('lessonid' => $lesson->id,
'prevpageid' => 0))) {
@ -486,7 +486,7 @@
if ($page->qtype == LESSON_BRANCHTABLE) {
if ($lesson->minquestions and !has_capability('mod/lesson:manage', $context)) {
// tell student how many questions they have seen, how many are required and their grade
$ntries = count_records("lesson_grades", "lessonid", $lesson->id, "userid", $USER->id);
$ntries = $DB->count_records("lesson_grades", array("lessonid"=>$lesson->id, "userid"=>$USER->id));
$gradeinfo = lesson_grade($lesson, $ntries);
@ -549,7 +549,7 @@
// this is for modattempts option. Find the users previous answer to this page,
// and then display it below in answer processing
if (isset($USER->modattempts[$lesson->id])) {
$retries = count_records('lesson_grades', "lessonid", $lesson->id, "userid", $USER->id);
$retries = $DB->count_records('lesson_grades', array("lessonid"=>$lesson->id, "userid"=>$USER->id));
$retries--;
$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")) {
@ -776,23 +776,22 @@
if ($lesson->nextpagedefault) {
// in Flash Card mode...
// ...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)
$nretakes = $DB->count_records("lesson_grades", array("lessonid"=>$lesson->id, "userid"=>$USER->id));
// ...then get the page ids (lessonid the 5th param is needed to make $DB->get_records play)
$allpages = $DB->get_records("lesson_pages", array("lessonid" => $lesson->id), "id", "id,lessonid");
shuffle ($allpages);
$found = false;
if ($lesson->nextpagedefault == LESSON_UNSEENPAGE) {
foreach ($allpages as $thispage) {
if (!count_records("lesson_attempts", "pageid", $thispage->id, "userid",
$USER->id, "retry", $nretakes)) {
if (!$DB->count_records("lesson_attempts", array("pageid"=>$thispage->id, "userid"=>$USER->id, "retry"=>$nretakes))) {
$found = true;
break;
}
}
} elseif ($lesson->nextpagedefault == LESSON_UNANSWEREDPAGE) {
foreach ($allpages as $thispage) {
if (!count_records_select("lesson_attempts", "pageid = $thispage->id AND
userid = $USER->id AND correct = 1 AND retry = $nretakes")) {
if (!$DB->count_records_select("lesson_attempts", array('pageid'=>$thispage->id,
'userid'=>$USER->id, 'correct'=>1, 'retry'=>$nretakes))) {
$found = true;
break;
}
@ -802,8 +801,8 @@
$newpageid = $thispage->id;
if ($lesson->maxpages) {
// check number of pages viewed (in the lesson)
if (count_records("lesson_attempts", "lessonid", $lesson->id, "userid", $USER->id,
"retry", $nretakes) >= $lesson->maxpages) {
if ($DB->count_records("lesson_attempts", array("lessonid"=>$lesson->id, "userid"=>$USER->id,
"retry"=>$nretakes)) >= $lesson->maxpages) {
$newpageid = LESSON_EOL;
}
}
@ -853,7 +852,7 @@
lesson_print_header($cm, $course, $lesson, 'view');
print_heading(get_string("congratulations", "lesson"));
print_simple_box_start("center");
$ntries = count_records("lesson_grades", "lessonid", $lesson->id, "userid", $USER->id);
$ntries = $DB->count_records("lesson_grades", array("lessonid"=>$lesson->id, "userid"=>$USER->id));
if (isset($USER->modattempts[$lesson->id])) {
$ntries--; // need to look at the old attempts :)
}