From b16c511492724f88144d63cdebc64d5a78083c0c Mon Sep 17 00:00:00 2001 From: Artem Andreev Date: Thu, 3 Mar 2011 16:59:36 +0300 Subject: [PATCH] Fixed bug when link to individual lesson page gives error 'Error: could not find records' if student didn't visit lesson before. --- mod/lesson/view.php | 14 +++++++++++++- 1 files changed, 13 insertions(+), 1 deletions(-) diff --git a/mod/lesson/view.php b/mod/lesson/view.php index 6145230..eaaec91 100644 --- a/mod/lesson/view.php +++ b/mod/lesson/view.php @@ -427,7 +427,19 @@ $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')) { - error('Error: could not find records'); + $USER->startlesson[$lesson->id] = true; + $startlesson = new stdClass; + $startlesson->lessonid = $lesson->id; + $startlesson->userid = $USER->id; + $startlesson->starttime = time(); + $startlesson->lessontime = time(); + + $id =insert_record('lesson_timer', $startlesson); + if (!id) { + error('Error: could not insert row into lesson_timer table'); + } + $timer = $startlesson; + $timer->id = $id; } else { $timer = array_pop($timer); // this will get the latest start time record } -- 1.6.5.1.1367.gcd48