Hello,
I want the functions in PHP. I don't know what is this you showed me above.
Thank you
Hello,
I want the functions in PHP. I don't know what is this you showed me above.
Thank you
Hello,
Yes it seems that this is the function i want. I used it like this:
$info = get_fast_modinfo($theCourse);
And the output was
course_modinfo Object |
The question is how i can get inside the object course:course_modinfo:private ???
I tried $info->{'course:course_modinfo'} but doesnt work.
You could always try looking at some of the functions included in the class course_modinfo - https://github.com/moodle/moodle/blob/master/lib/modinfolib.php
Or, possibly, search through the Moodle core code for examples of where get_fast_modinfo is already in use ...
I'm encountering the same issue. I'm at a loss at how to burrow down into course_modinfo.
Were you able to come up with a solution?
Use get_course_mods API.
require ("/path/to/config.php");
global $USER, $DB;
$mods = get_course_mods($courseid);
foreach($mods as $cm) {
if (coursemodule_visible_for_user($cm, $USER->id)) {
$modrec = $DB->get_record($cm->modname, array('id' => $cm->instance));
echo $cm->modname, " : ", $modrec->fullname, PHP_EOL;
}
}
Also a more simpler version:
$list = get_array_of_activities($courseid);
// to see the structure
var_dump($list);
Both get_array_of_activities and get_course_mods are to be avoided, if possible, as both require extra database queries in order to work (and only return limited data from particular database tables), whereas get_fast_modinfo generally accesses the data already in memory, or via the cache, before starting on any database queries (and contains lots of extra data about completion, availability, groupings, user visibility etc.).
Once you've called '$modinfo = get_fast_modinfo($courseobj)' you have a number of options (all documented in lib/modinfolib.php).
In your case, you can call $modinfo->get_used_module_names() to get a list of all the module types (in the form of an array [pluginname] => [human readable name] - e.g. assign => Assignment).
You can then loop through the 'pluginname' in the list and call $modinfo->get_instances_of($pluginname)
This will return an array containing cm_info objects representing each instance of that activity in the course.
cm_info objects are very helpful as they tell you everything you need to know about an activity, including:
@"Black Dream", What I showed you is one of the standard "blocks" that you can add to any course in Moodle. It seems that you are wanting to re-invent the wheel.