Moodle version 3.1.4
I add simple text file to a course, as a File resource module. For that module, in the 'Common module settings' section, I assign 'ID number' to a value that is unique within that course.
In a local plugin I have developed, I can find that File resource module, given the ID of the course that contains that module and the module ID number. For example:
global $DB; $courseId = 6; $moduleIdNumber = '12345'; $sql = "SELECT cm.id, cm.course AS course_id, m.name AS module_type, cm.instance AS module_instance_id"; $sql .= " FROM {course_modules} cm"; $sql .= " INNER JOIN {modules} m ON m.id = cm.module"; $sql .= " WHERE cm.course = :course_id AND cm.idnumber = :module_idnumber"; $params = array( 'course_id' => $courseId, 'module_idnumber' => $moduleIdNumber ); $recs = $DB->get_records_sql( $sql, $params ); $module = reset( $modules );
Now I have a course_modules record.
Does that help me to access that text file and read its contents?