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

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

by Carlos Eduardo Angarita Marquez -
Number of replies: 1

Hello 

I what to check all the items in a course (resourse or activity) and for each one to get your:

1. section member

2. Type of items (Example: Page, questionarie, chat, etc)

3. Item´s URL.

¿Some body know what API function can I to use?


Thanks


Average of ratings: -
In reply to Carlos Eduardo Angarita Marquez

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

by Darko Miletić -

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}";
}