Skip to content

Instantly share code, notes, and snippets.

@guillaumewuip
Last active November 30, 2016 05:44
Show Gist options
  • Save guillaumewuip/aa5764c92c80efce1873f9f01cadf0d3 to your computer and use it in GitHub Desktop.
Save guillaumewuip/aa5764c92c80efce1873f9f01cadf0d3 to your computer and use it in GitHub Desktop.
Moodle files access
DROP PROCEDURE IF EXISTS getLogsForModule;
DELIMITER $$
CREATE PROCEDURE getLogsForModule(module VARCHAR(255))
BEGIN
-- on doit passer par un concat car le nom d'une table doit être statique
SET @request = CONCAT("SELECT l.*, i.*, c.*, category_path(c.category) as category_path, u.*
FROM mdl_logstore_standard_log l
LEFT OUTER JOIN mdl_", module, " i ON i.id = l.objectid
LEFT OUTER JOIN mdl_course c ON c.id = l.courseid
LEFT OUTER JOIN mdl_user u ON u.id = l.userid
WHERE l.eventname LIKE '%", module, "%'
AND l.eventname LIKE '%course_module_viewed%';");
PREPARE stmt FROM @request;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END $$
DELIMITER ;
--
call getLogsForModule('resource')
call getLogsForModule('forum')
-- etc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment