Localizar curso do Moodle com mais de um tutor inscrito com comando SQL

Localizar curso do Moodle com mais de um tutor inscrito com comando SQL

por Lino Vaz Moniz -
Número de respostas: 0

Para pesquisar curso no Moodle com mais de um tutor inscrito, execute o seguinte comando SQL

SELECT DISTINCT c.id,c.fullname,COUNT(rs.id) AS countenrol FROM mdl_role_assignments rs INNER JOIN mdl_role r ON rs.roleid=r.id INNER JOIN mdl_context e ON rs.contextid=e.id INNER JOIN mdl_enrol en ON e.instanceid=en.courseid INNER JOIN mdl_course c ON c.id=en.courseid INNER JOIN mdl_user_enrolments ue ON en.id=ue.enrolid WHERE e.contextlevel=50 AND rs.userid=ue.userid  AND c.id=e.instanceid AND ue.status = 0 AND en.status = 0 AND r.shortname='editingteacher' GROUP BY c.id,c.fullname HAVING COUNT(rs.id) > 1

 

Para restringir o filtro apenas inscrições dentro de período de validade, execute o seguinte comando SQL

 SELECT DISTINCT c.id,c.fullname,COUNT(rs.id) AS countenrol FROM mdl_role_assignments rs INNER JOIN mdl_role r ON rs.roleid=r.id INNER JOIN mdl_context e ON rs.contextid=e.id INNER JOIN mdl_enrol en ON e.instanceid=en.courseid INNER JOIN mdl_course c ON c.id=en.courseid INNER JOIN mdl_user_enrolments ue ON en.id=ue.enrolid WHERE e.contextlevel=50 AND rs.userid=ue.userid  AND c.id=e.instanceid AND ue.status = 0 AND en.status = 0 AND r.shortname='editingteacher' AND (ue.timestart IS NULL OR ue.timestart = 0 OR ue.timestart <= ? ) AND (ue.timeend IS NULL OR ue.timeend = 0 OR ue.timeend >= ? ) GROUP BY c.id,c.fullname HAVING COUNT(rs.id) > 1

Passe parâmetro data atual em formato timestamp   ue.timestart <= ? e  ue.timeend >= ?