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;
}
}
You'll need to specify the user id if you want a specific user
Add the global $USER
object at the top eg:
global $DB, $USER;
Then use something like this for the SQL - this is for elements containing cmi.core.lesson_status
or x.start.time
[$elemsql, $elemparams] = $DB->get_in_or_equal(['cmi.core.lesson_status', 'x.start.time'], SQL_PARAMS_NAMED);
$sql = "SELECT sst.id, c.id AS courseid, c.fullname AS coursename, s.id AS scormid, s.name AS scormname, sst.attempt, sst.element, sst.value
FROM {scorm_scoes_track} sst
JOIN {scorm} s ON s.id = sst.scormid
JOIN {course} c ON c.id = s.course
WHERE sst.userid = :userid
AND sst.element {$elemsql}";
$params = array_merge(['userid' => $USER->id], $elemparams);
$scoes = $DB->get_records_sql($sql, $params);