2.8.3 Live timer on the lesson page

Re: 2.8.3 Live timer on the lesson page

by Rick Dennis -
Number of replies: 12

Wendi,

Did you get an answer to this question or figure out a way yourself? I have a similar situation.

Let me know.

Thanks.


I am using V 2.9

In reply to Rick Dennis

Re: 2.8.3 Live timer on the lesson page

by Wendi Daniels -

Does anyone have an answer for this? Some of us need a visual clock that shows the mandated time ticking away. Is there a way to make this happen?

In reply to Wendi Daniels

Re: 2.8.3 Live timer on the lesson page

by Wendi Daniels -

I see there is a timer.js called "LiveClock". Is there a way to activate it? I see the code that is used to activate it, but I do not know where to put that code. Please advise.

In reply to Wendi Daniels

Re: 2.8.3 Live timer on the lesson page

by Wendi Daniels -

Here are the instructions in the ftp file:   



 Below is the code that is used to call this page:


    echo "<script type=\"text/javascript\">\n";
        echo "var starttime = ". $timer->starttime . ";\n";
        echo "var servertime = ". time() . ";\n";
        echo "var testlength = ". $lesson->timelimit .";\n";
        echo "document.write('<script type=\"text/javascript\" src=\"liveclock_lite.js\"><\/script>');\n";
        echo "window.onload = function () { show_clock(); }";
    echo "</script>\n";

In reply to Wendi Daniels

Re: 2.8.3 Live timer on the lesson page

by Wendi Daniels -

Does anyone have an idea as to where this is to be installed in the ftp files?

In reply to Wendi Daniels

Re: 2.8.3 Live timer on the lesson page

by Wendi Daniels -

Anyone?????

In reply to Wendi Daniels

Re: 2.8.3 Live timer on the lesson page

by Wendi Daniels -

We need a visual clock to go along with the "time spent" in lesson.

In reply to Wendi Daniels

Re: 2.8.3 Live timer on the lesson page

by Wendi Daniels -

Here is the code for the timer. It uses "timespent" in the code, but we need the clock to count down as it does, and reflect the minimum time spent before progressing on to the next lesson. Right now it is linked to timelimit, and it reflects the maximum time you have to complete the course. How do we change this?


____________________________________________________________________________________

/*/////////////////////////////////////////////////////////
// This code is based off of
// "Live Clock Lite" script - Version 1.0
// By Mark Plachetta (astroboy@zip.com.au)
//
// The original script displayed a clock.
// Mark Nielsen modified it to be a countdown timer
// for the lesson module in moodle.
//
//    Below is the code that is used to call this page.
//    echo "<script type=\"text/javascript\">\n";
//        echo "var starttime = ". $timer->starttime . ";\n";
//        echo "var servertime = ". time() . ";\n";
//        echo "var testlength = ". $lesson->timespent .";\n";
//        echo "document.write('<script type=\"text/javascript\" src=\"liveclock_lite.js\"><\/script>');\n";
//        echo "window.onload = function () { show_clock(); }";
//    echo "</script>\n";
//
//////////////////////////////////////////////////////////*/

    var stopclock = 0;
    var myclock = '';
    var timespent, hours, minutes, secs;
    var javatimeDate = new Date();
    var javatime = javatimeDate.getTime();
    javatime = Math.floor(javatime / 1000);

    if (typeof(clocksettings) != 'undefined') {
        if (clocksettings.starttime) {
            starttime = parseInt(clocksettings.starttime);
        }
        if (clocksettings.servertime) {
            servertime = parseInt(clocksettings.servertime);
        }
        if (clocksettings.timespent) {
            timespent = parseInt(clocksettings.timespent);
        }
    }

    difference = javatime - servertime;
    starttime = starttime + difference;

    /*function leave() {  // feable attempt to run a script when someone leaves a timed test early, failed so far
        window.onunload = window.open('http://www.google.com','','toolbar=no,menubar=no,location=no,height=500,width=500');
    }
    leave();*/

    function show_clock() {

        currentDate = new Date();
        current = currentDate.getTime();
        current = Math.floor(current / 1000);

        var mytime = '',
            myclock = document.getElementById("lesson-timer");
        if (current > starttime + timespent) {
            mytime += M.util.get_string('timespent', 'lesson');
            stopclock = 1;
        } else {
            timespent = starttime + timespent - current;
            if (timespent < 60) {
                myclock.className = "timeleft1";
            }
            hours = Math.floor(timespent / 3600);
            timespent = timespent - (hours * 3600);
            minutes = Math.floor(timespent / 60);
            secs = timespent - (minutes * 60);

            if (secs < 10) {
                secs = "0" + secs;
            }
            if (minutes < 10) {
                minutes = "0" + minutes;
            }
            mytime += hours + ":" + minutes + ":" + secs;
        }

        myclock.innerHTML = mytime;

        if (stopclock == 0) {
            setTimeout("show_clock()", 1000);
        }
}

In reply to Wendi Daniels

Re: 2.8.3 Live timer on the lesson page

by Jean-Michel Védrine -

Hello,

Sorry I have no time to work on this feature, and as I am not very good at javascript language it would take me some time to implement this feature.

In reply to Jean-Michel Védrine

Re: 2.8.3 Live timer on the lesson page

by Wendi Daniels -

I have a programmer who is working on it now, and she says the function does not seem to read from timer.js. The timer is for the "time limit" function in availability is what we are trying to redirect (to timespent). Could you tell us which files are involved in the timelimit timer?

In reply to Wendi Daniels

Re: 2.8.3 Live timer on the lesson page

by Wendi Daniels -

Jean -Michel, do you know which files are involved?

In reply to Wendi Daniels

Re: 2.8.3 Live timer on the lesson page

by Jean-Michel Védrine -

Hello Wendi,

Sorry, as I said I have no time for Moodle coding currently (and I really don't know how to do what you want, I may be wrong but I think it seems rather complicated to do), so I can't help here.

The only clue I can give is that your programmer could use a code similar to the one I introduced in mod/lesson/view.php to get the time already spent by the student in the lesson

            $duration = $DB->get_field_sql(

                            "SELECT SUM(lessontime - starttime)

                               FROM {lesson_timer}

                              WHERE lessonid = :lessonid

                                AND userid = :userid",

                            array('userid' => $USER->id, 'lessonid' => $lesson->id));

            if (!$duration) {

                $duration = 0;

            }

In reply to Jean-Michel Védrine

Re: 2.8.3 Live timer on the lesson page

by Wendi Daniels -

Yeah, I think we've already given up on this fight.   :/