¿Is possible to get the url from all items in a course?

Re: ¿Is possible to get the url from all items in a course?

by Darko Miletić -
Number of replies: 0

This code will do the trick:

global $DB, $CFG;
$sql = "
SELECT cm.id,
       cm.section,
       mdl.name
FROM       {course_modules} AS cm
INNER JOIN {context} AS ctx ON ctx.contextlevel = :ctxlevel AND ctx.instanceid = cm.id
INNER JOIN {modules} AS mdl ON cm.module = mdl.id
";
$items = $DB->get_records_sql($sql, array('ctxlevel' => CONTEXT_MODULE));
foreach ($items as &$item) {
    $item->url = "{$CFG->wwwroot}/mod/{$item->name}/view.php/id={$item->id}";
}