Mapear notas das atividades do curso no Moodle filtrando pela sessão (course_sections) do Curso.
SELECT
cm.id moduleid,
cm.module,
cm.`SECTION` as sectionid,
m.name AS modulename,
cm.instance,
cur.id as courseid,
cur.fullname as curso,
coalesce(cs.name, cs.summary) as sessao,
i.itemname as nome_atividade,
g.userid,
us.firstname as aluno,
i.itemtype,
g.finalgrade,
g.timemodified AS gradedate
FROM
mdl_course_modules cm
JOIN mdl_modules m ON m.id = cm.module
JOIN mdl_course cur ON cur.id = cm.course
join mdl_course_sections cs ON (cs.course = cur.id and cs.id = cm.`SECTION`)
LEFT JOIN mdl_grade_items i ON i.itemmodule = m.name
LEFT JOIN mdl_grade_grades g ON g.itemid = i.id
LEFT JOIN mdl_user us ON us.id = g.userid
WHERE
cur.id = :courseid
and
us.id = :userid
and
cm.id = :actid
and
i.itemtype = 'mod'
and
g.finalgrade is not null
ORDER BY
cm.course,
cs.`SECTION`,
us.firstname
;
Onde você pode parametrizar por:
- courseid: id do curso;
- userid: id do usuário;
- actid: id da atividade (course_module)