Custom block for display of scorm interactions

Custom block for display of scorm interactions

by Betty Grazia -
Number of replies: 2


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


Average of ratings: -
In reply to Betty Grazia

Re: Custom block for display of scorm interactions

by Betty Grazia -
I did this, but it does not display total as per the user interactions that they have made.

class block_total_score extends block_base {

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

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

$content = '';

$sql=("SELECT mu.id, mu.firstname, mu.lastname, SUM(msst.value) AS Loan_amount
FROM {user} mu
LEFT JOIN {scorm_scoes_track} msst ON mu.id= msst.userid
WHERE msst.element= 'cmi.interactions_0.student_response'
GROUP BY 'mu.id'");

$scoes = $DB->get_records_sql($sql);

foreach ($scoes as $scoe) {

$content = $scoe->firstname. ' '. $scoe->lastname.' '. '
'. $scoe->Loan_amount. '
';

}

$this->content = new stdClass;

$this->content->text = $content;



}}
In reply to Betty Grazia

Re: Custom block for display of scorm interactions

by Dominique Palumbo -
Picture of Particularly helpful Moodlers Picture of Plugin developers
Hi,

I think that in the loop the variable $content is initialise each time. At the end, I think that you'll only get the last record.

If I have correctly read the code.

Hope it's helped.

Dominque.