Custom block for display of scorm interactions

Custom block for display of scorm interactions

by Betty Grazia -
Number of replies: 4

Hi team

I have developed custom block which extract scorm interactions, elements like x.start.time, core.cmi.lesson_status 

My question is whether the result is displayed for logged in users only. Here is my code.

class block_scormtest extends block_base {

function init() {
    $this->title = get_string('pluginname', 'block_scormtest');
}
function get_content()  {
    global $DB;

    if ($this->content  !== NULL) {
        return $this->content;
    }

    $content = '';
  
    $courses = $DB->get_records('scorm_scoes_track', ['element' => 'cmi.core.lesson_status']);
    foreach ($courses as $course) {
        $content  = $course->attempt.  '     '.userdate($course->timemodified, get_string('strftimerecentfull')). '  '. $course->value. '<br>';
    }

 $this->content = new stdClass;
$this->content->text = $content;
        
}
         
}

Average of ratings: -
In reply to Betty Grazia

Re: Custom block for display of scorm interactions

by Michael Hughes -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers
At the moment, that will be dependent on who can see the block, as it's not doing anything to check if the current user should see anything.

If you only want a logged in user to see it you should verify that using isloggedin().

A better option really would be to check that the user holds a capability (e.g. has_capability("block/yourblock:displayscormtracks", $this->context).

The capabiltiy can be given to the "logged in user" role via the db/access.php file but then it allows Admins decide which roles should get this, because they may decide that staff shouldn't see this or different roles in see different things if the block is in a different place.
In reply to Michael Hughes

Re: Custom block for display of scorm interactions

by Betty Grazia -

Thanks for this info.

Will it be possible to show the scorm scores of the only current user in this custom block?

As this is not a report, we just want that users can see their scorm interactions in the Dashboard.

In reply to Betty Grazia

Re: Custom block for display of scorm interactions

by Michael Hughes -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers
*anything* is *possible*, but it would be down to understanding the data structures to pull the relevant data out., and I'm afraid *I'm* not too familiar with the SCORM module.

Typically if you're wanting the current user data, you'll generally want to look at using the $USER global object (and $USER->id to identify the current user), but how you would use that specifically will depend.

Thing to watch out for here is when you user $USER it's the current user, which *may* not be what you want in cases where your code is displaying a different user's data to the current user (e.g. member of staff viewing a student).
In reply to Michael Hughes

Re: Custom block for display of scorm interactions

by Betty Grazia -
Can you please let me know how to get interaction details only for a logged-in user in the custom block?