General developer forum

How to show dynamic data on course page related to custom activity module?

 
Picture of Niraj Chourasia
How to show dynamic data on course page related to custom activity module?
 

Hello All,

I m new in moodle, as per my requirement i made a activity module mod_lessonvideo under mod directory.

The concept behind this module is post vimeo & youtube video as resource activity in course.

When user click on activity link it opens video in jquery UI and start tracking progress of the video and save one of table with user id.

But i think because of course cache i can not display correct progress data to correct user.

This is my code in module lib.php

function lessonvideo_get_coursemodule_info($coursemodule) {
    global $CFG, $DB,$USER;

    require_once("$CFG->dirroot/mod/lessonvideo/locallib.php");

    if (!$lessonvideo = $DB->get_record('lessonvideo', array('id'=>$coursemodule->instance),
            'id, name,vurl,vtype,vid')) {
        return NULL;
    }

    $info = new cached_cm_info();
    $info->name = $lessonvideo->name;
    $info->vurl = $lessonvideo->vurl;
    $info->vtype = $lessonvideo->vtype;
    $info->vid = $lessonvideo->vid;
    $id = $lessonvideo->id;
    $vid = $info->vid;

   // this is the video tracking table from where we are getting the record for current user and video activity


    $trackData = $DB->get_record('lessonvideo_track', array('vid'=>$id,'uid'=>$USER->id));


    /*$trackData = lesson_get_track_record( $vid );
    print_r($trackData);die;*/
    if ($info->vtype) {
        $info->extraclasses = "myyoutube";
        $info->onclick = "pickYoutube('$vid','$id'); return false;";
    }else {
        $info->extraclasses = "myvimeo";
        $info->onclick = "pickVimeo('$vid','$id'); return false;";
    }
    // here we are setting the progress bar that should be different for different user according to the track table

if($trackData) {
        $info->progress = $trackData->watch_percent;
        $info->content = '<div class="progress"><div class="progress-bar progress-bar-info" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: '.$info->progress.'%;">'.$info->progress.'%</div></div>';
    }else {
        $info->content = '<div class="progress"><div class="progress-bar progress-bar-info" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%;">0%</div></div>';
    }
  
    return $info;
}


Please advice how i can resolve this.

Thanks,

Nik


 
Average of ratings: -
Picture of sam marshall
Re: How to show dynamic data on course page related to custom activity module?
Core developersParticularly helpful MoodlersPlugin developersTesters

Hi,

Try the _cm_info_view callback instead of _get_coursemodule_info. get_coursemodule_info is intended for cached data that only changes if you change the settings of the activity.

_cm_info_view is what shows if there are unread messages in a forum, for instance (look in mod/forum/lib.php to see this).

This dev docs page is super useful: https://docs.moodle.org/dev/Callbacks - it lists all the callbacks available. (There are several other sketchier ways of achieving what you want with different callbacks! But cm_info_view is probably the right one here unless I'm missing something.)

--sam
 
Average of ratings: -
Picture of Niraj Chourasia
Re: How to show dynamic data on course page related to custom activity module?
 

Hello Sam ,

Thanks for reply.

Hope you understood my problem and what i m looking to achieve .

I tried with that as well.

But how i can get the id of each activity link and again make query on database and create progress bar on this _cm_info_view.

Let me know plz.


 
Average of ratings: -