"Time spent" prerequisite and multiple attempts

"Time spent" prerequisite and multiple attempts

by Wendi Daniels -
Number of replies: 12

I have my lessons set to be available after a set number of minutes (using the prerequisite option). However, every time a student leaves the lesson and comes back, they have to start all over with the time. How do we fix this. Also, is there a way to have a visible timer for the students? Please, no cheeky, smart-ass replies.

(Title Edited by Joseph Rézeau - original submission Thursday, 17 July 2014, 9:56 PM)

Average of ratings: -
In reply to Wendi Daniels

Re: "Time spent" prerequisite and multiple attempts

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

You are right, time spent in successive attempts at a lesson is not cumulative. It starts at zero with each new attempt.

The best solution to this problem would be the development of a new "stop-watch/chronometer" feature, as described in this other discussion: .Measuring "Time spent" in Lesson

EDIT.- Just found out a very simple hack to make time spent in successive attempts at a lesson cumulative. This is for current version 2.7 of Moodle, but should work in previous versions too.

In file yourmoodle/mod/lesson/view.php, around line 105, locate this comment: "// check for the timespent condition". A few lines below, replace line:

$duration = $attempttime->lessontime - $attempttime->starttime;

with:

$duration += $attempttime->lessontime - $attempttime->starttime;

That's it! Of course, usual warning applies that it may be risky to hack a moodle core file and cause problems when updating your moodle site. So use at own rixk.

In reply to Joseph Rézeau

Re: "Time spent" prerequisite and multiple attempts

by Wendi Daniels -
Joseph, THANK YOU! MERCI BEAUCOUP! Thank you so much for your knowledge and hard work. Merci Beaucoup, Merci Beaucoup, Merci Beaucoup!!!

Per your forewarning and the forewarning of others, I will make an alternate file called mod/lesson/vieworiginal.php to keep a copy of the original so I always have a "hack-free" version of all files, and I keep an additional log of all hacks on a separate sheet....this is meant as a forewarning to others more than anything else.

Thanks, again, Joseph! I am very grateful!  :D
In reply to Wendi Daniels

Re: "Time spent" prerequisite and multiple attempts

by Wendi Daniels -

I did this...are we sure it works? I have not had time to test my site, but two others have, and they said it does not work. I will be able to test it myself,  tomorrow, but it's worth asking.

In reply to Wendi Daniels

Re: "Time spent" prerequisite and multiple attempts

by Wendi Daniels -
So, Joseph, this is what the code reads in mod/lesson/view...

*******************************************************
   // check for the timespent condition
            if ($conditions->timespent) {
                $timespent = false;
                if ($attempttimes = $DB->get_records('lesson_timer', array("userid"=>$USER->id, "lessonid"=>$dependentlesson->id))) {
                    // 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;
                        if ($conditions->timespent < $duration/60) {
                            $timespent = true;
                        }
                    }
                }
                if (!$timespent) {
                    $errors[] = get_string('timespenterror', 'lesson', $conditions->timespent);
*****************************************************

Are there other changes I have missed that would make this work?
In reply to Wendi Daniels

Re: "Time spent" prerequisite and multiple attempts

by Wendi Daniels -
It does not seem to work, Joseph...  sad  I have 2.6.1

What about mod/lesson/timer.js  ?  I know you said it was old, and it was apparently modified, and then made obsolete. The information in the script says it was converted into a countdown timer from the original plan...do we know what the original was, and if we could get it back? It was once called "Live Clock Lite"
In reply to Wendi Daniels

Re: "Time spent" prerequisite and multiple attempts

by Wendi Daniels -
Joseph, do you have a response to this?
In reply to Wendi Daniels

Re: "Time spent" prerequisite and multiple attempts

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

The hack I gave does work for me.Tried and tested on a moodle 2.6.4 site.

And it has nothing to do with the mod/lesson/timer.js script.

Lesson02 settings:

screenshot #1

In Lesson 01

Student 's first attempt: spends 42 seconds in lesson 01
Student 's 2nd attempt: spends 1 min 19 seconds in lesson 01
Total time spent = 2 mins 1 second.

screenshot #2

Then, cumulative time spent is greater than the required 2 minutes, student is allowed to take Lesson 02.

Joseph

In reply to Joseph Rézeau

Re: "Time spent" prerequisite and multiple attempts

by Wendi Daniels -

Joseph, you said the code was 

$duration += $attempttime->lessontime - $attempttime->starttime;


are you sure it was not supposed to be

$duration + = $attempttime->lessontime - $attempttime->starttime; 


or


$duration+ = $attempttime->lessontime - $attempttime->starttime;


The difference in is the spacing.

In reply to Wendi Daniels

Re: "Time spent" prerequisite and multiple attempts

by Jean-Michel Védrine -

Hello Wendi,

Joseph has stopped using Moodle and I don't think he is still reading this forum.

At first glance his code is right and should work and your "variations" in spacing are definitely wrong.

In reply to Jean-Michel Védrine

Re: "Time spent" prerequisite and multiple attempts

by Wendi Daniels -

Thank you.  smile

In reply to Wendi Daniels

Re: "Time spent" prerequisite and multiple attempts

by Wendi Daniels -

There may be a problem with this code. This is the error message I get at the end of the questions at the end of the lesson:

***************************************************

Notice: Undefined variable: duration in /home/(ny id)/public_html/(my domain)/mod/lesson/view.php on line 111 This page should automatically redirect. If nothing is happening please use the continue link below.

This page should automatically redirect. If nothing is happening please use the continue link below.

Error output, so disabling automatic redirect.

***********************************************************

Any ideas?