Reputation: 33
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;
}
}
Upvotes: 0
Views: 153
Reputation: 33
I am new to this LMS development, so I am trying to figure out a few custom blocks. My question again is related to scorm interactions. I have added this sql query
SELECT scc.userid AS User, sct.name AS Name, scc.scoid AS SCORM_ID, sct.module AS Module, scc.value AS Sale_amount, sct.value AS Loan_amount
FROM
(SELECT u.id AS userid, st.scoid AS scoid, st.value AS value
FROM prefix_course AS c
LEFT JOIN prefix_scorm AS sc ON sc.course=c.id
LEFT JOIN prefix_scorm_scoes_track AS st ON st.scormid=sc.id
LEFT JOIN prefix_user AS u ON u.id=st.userid
WHERE st.element='cmi.interactions_0.student_response') AS scc
LEFT JOIN
(SELECT c.fullname Course, sc.name AS module, st.scoid AS scoid, u.id AS userid, u.firstname name, st.attempt as Attempt, st.value AS value
FROM prefix_course AS c
LEFT JOIN prefix_scorm AS sc ON sc.course=c.id
LEFT JOIN prefix_scorm_scoes_track AS st ON st.scormid=sc.id
LEFT JOIN prefix_user AS u ON u.id=st.userid
WHERE st.element='cmi.interactions_1.student_response') AS sct
ON sct.scoid=scc.scoid
AND sct.userid=scc.userid
ORDER BY scc.userid
to generate reports on loan amounts and sale amounts. Now I want to display it in the form of custom block showing only the total loan amount and sale amount by the user that they have made. This is a little tricky. For example: here in this screenshot, for the admin user, the total loan amount should be 17800 and sale amount: 116000
Is this possible in any way by using SELECT sum(value) WHERE element='cmi.interactions_0.student_response' sale amount= sum of student response
Upvotes: 0
Reputation: 33
thanks for this Russell.
I'm looking to edit the logic so that the logged in user can only see the records that they themselves have created for scorm interactions(x.start.time, cmi.interactions_0.student_response, cmi.interactions_1.student_response, cmi.core.lesson_status)
Thanks again for looking into it.
Upvotes: 0
Reputation: 10241
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);
Upvotes: 1