Moodle | Fetch activities in same order in which they are listed on Course Page

Author - Neha Mishra
10.02.2016
|
0 Comments
||

There is a functionality on Moodle course page that activities can be dragged up and down to change their order after turning on the edit button. If in the code you need to pull the activities in same order for a course then following code can help you :

$mods = $modinfo->get_cms();
$sections = $modinfo->get_section_info_all();
$modlist=array();
$modorder=array();
foreach ($modinfo->sections as $section)
{
foreach ($section as $modid)
{
$modorder[]=$modid;
}
}
 $modlist=array();	
 foreach($mods as $mod)
{ 			 
$modcopy = new stdClass();$modcopy->id = $mod->id;
$modcopy->name = $mod->modname;
$modcopy->course = $courseObj->id;
$modcopy->module = $mod->module;
$modcopy->modname = $mod->name;
$modcopy->completionstate = '';
$modcopy->instance = $mod->instance;
$modlist[array_search($mod->id,$modorder)]=$modcopy;
}

By this we have obtained an array “$modlist“ that comprises of all the activities based on the section order present on the course page.

Webner Solutions is a Software Development company focused on developing Insurance Agency Management Systems, Learning Management Systems and Salesforce apps. Contact us at dev@webners.com for your Insurance, eLearning and Salesforce applications.

Leave a Reply

Your email address will not be published. Required fields are marked *