Using the modinfo column in the course table

Using the modinfo column in the course table

Ashley Sands -
回帖数:3
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
回复Ashley Sands

Re: Using the modinfo column in the course table

Frank Ralf -
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
回复Ashley Sands

Re: Using the modinfo column in the course table

sam marshall -
Core developers的头像 Peer reviewers的头像 Plugin developers的头像
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


回复sam marshall

Re: Using the modinfo column in the course table

Ashley Sands -
Thanks for the replies Frank and Sam.

The get_fast_modinfo function really has helped me out.


Ashley