Displaying course Dedication time in hours

Displaying course Dedication time in hours

by Vinit Prajapati -
Number of replies: 2

Hello Everyone,

I am using New plugin: Custom reports for Total time spent on particular courses.

But it is displaying in 1 days, 2o hours

So, Can anyone tell me how can display course dedication time in Hours only.

Vinit

Average of ratings: -
In reply to Vinit Prajapati

Re: Displaying course Dedication time in hours

by Juan Leyva -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

Hi Vinit,

unfortunatelly you can configure it, you can change the source code:

this file:

https://github.com/jleyva/moodle-block_configurablereports/blob/MOODLE_21_STABLE/components/columns/userstats/plugin.class.php

Look for the format_time function, if you change this line with:

return $totaldedication/3600;

you will get the dedication in hours

In reply to Juan Leyva

Re: Displaying course Dedication time in hours

by Vinit Prajapati -

Hello Juan,

I mean to say, instead of 1 day, 20 hours it shold display 44 hours.

So I made new function in moodlelib.php

    function format_hours_time($totalsecs){
        $totalsecs = abs($totalsecs);

        $hours     = floor($totalsecs/HOURSECS);
        $remainder = $totalsecs - ($hours*HOURSECS);
        $mins      = floor($remainder/MINSECS);
        $secs      = $remainder - ($mins*MINSECS);
        
        $ss = ($secs == 1)  ? 'Second'  : 'Seconds';
        $sm = ($mins == 1)  ? 'Minute'  : 'Minutes';
        $sh = ($hours == 1) ? 'Hour' : 'Hours';

        $ohours = '';
        $omins = '';
        $osecs = '';

        if ($hours) $ohours = $hours .' '. $sh;
        if ($mins)  $omins  = $mins .' '. $sm;
        if ($secs)  $osecs  = $secs .' '. $ss;

        if ($hours) return trim($ohours .' '. $omins);
        if ($mins)  return trim($omins .' '. $osecs);
        if ($secs)  return $osecs;
        return get_string('now');
    }

 

And called this function.

Thank you very much.

Vinit