Skip to content

Instantly share code, notes, and snippets.

@frumbert
Created August 12, 2017 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frumbert/bde8da383c3e0530559b54ccf21096c2 to your computer and use it in GitHub Desktop.
Save frumbert/bde8da383c3e0530559b54ccf21096c2 to your computer and use it in GitHub Desktop.
In moodle, get a list of activities that are available and their index (order from the top down)
<?php
require('../../config.php'); // adjust as needed
require_once($CFG->dirroot.'/course/format/lib.php');
require_once($CFG->libdir.'/modinfolib.php');
$courseid = 26; // the numerical id of the course we are looking in
$index = 1;
$course = get_course($courseId); // in course/format/lib.php
$modinfo = get_fast_modinfo($course); // in lib/modinfolib.php
foreach ($modinfo->get_cms() as $cmid => $cm) {
if ($cm->uservisible && $cm->available) {
echo PHP_EOL . $index, ". ", $cmid, " name=", $cm->modname, ", name=" . $cm->name;// $cm is a cm_info;
// $url = new moodle_url("/mod/" . $cm->modname . "/view.php", array("id" => $cmid));
$index++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment