Hi,
I am trying to get all the modules associated with a given course. I think that the modinfo column contains such information, yet I have no idea what it means.
Here is an example:
[modinfo] => a:2:{i:1;O:8:"stdClass":10:{s:2:"id";s:1:"1";s:2:"cm";i:1;s:3:"mod";s:5:"scorm";s:7:"section";s:1:"0";s:7:"visible";s:1:"1";s:9:"groupmode";s:1:"0";s:10:"groupingid";s:1:"0";s:16:"groupmembersonly";s:1:"0";s:5:"extra";s:0:"";s:4:"name";s:11:"Test+Module";}i:2;O:8:"stdClass":10:{s:2:"id";s:1:"1";s:2:"cm";i:2;s:3:"mod";s:5:"forum";s:7:"section";s:1:"0";s:7:"visible";s:1:"1";s:9:"groupmode";s:1:"0";s:10:"groupingid";s:1:"0";s:16:"groupmembersonly";s:1:"0";s:5:"extra";s:0:"";s:4:"name";s:10:"News+forum";}} )
Please write any SQL code required to understand the modinfo column.
Thanks,
Ashley
Hi Ashley,
A good idea is to first have a look at Moodle's standard libraries. As it happens, there is already a function "get_all_instances_in_courses()":
"Returns an array of all the active instances of a particular module in given courses, sorted in the order they are defined."
http://xref.moodle.org/lib/datalib.php.html#get_all_instances_in_courses
You will find a short overview of the available libraries in the "Introduction to Moodle Programming" course (http://dev.moodle.org/mod/resource/view.php?id=36).
hth
Frank
A good idea is to first have a look at Moodle's standard libraries. As it happens, there is already a function "get_all_instances_in_courses()":
"Returns an array of all the active instances of a particular module in given courses, sorted in the order they are defined."
http://xref.moodle.org/lib/datalib.php.html#get_all_instances_in_courses
You will find a short overview of the available libraries in the "Introduction to Moodle Programming" course (http://dev.moodle.org/mod/resource/view.php?id=36).
hth
Frank
Hi Ashley,
That's PHP serialised format (which is pretty ugly). However, don't try to access this column directly. Instead, call $modinfo = get_fast_modinfo($course). This returns an array containing all the information; and it will come from cache if available, thus potentially increasing performance. In addition it will work correctly if for some reason the modinfo has not yet been generated for that course.
If you want to see the format of the array (iirc it is organised in two ways, by course-module id or by module type then instance id), do print_object($modinfo); This should give you all the info you need.
--sam
That's PHP serialised format (which is pretty ugly). However, don't try to access this column directly. Instead, call $modinfo = get_fast_modinfo($course). This returns an array containing all the information; and it will come from cache if available, thus potentially increasing performance. In addition it will work correctly if for some reason the modinfo has not yet been generated for that course.
If you want to see the format of the array (iirc it is organised in two ways, by course-module id or by module type then instance id), do print_object($modinfo); This should give you all the info you need.
--sam