"; print_r($badiuccotent->getListcontent()); echo ""; class badiu_coursecontent { private $listcontent=null; function __construct($courseid,$section=null) { $this->listcontent=$this->get_list($courseid,$section); } public function get_list($courseid,$section=null) { if(empty($courseid)){return null;} global $DB; global $CFG; $wsql=""; if($section > 0 ){$wsql=" AND s.section=$section";} $sql = "SELECT cm.id,m.name AS module,cm.instance,cm.idnumber,s.id AS topicid,s.section,s.sequence AS activitysequence,cm.visible,cm.visible,cm.visibleold,cm.groupmode,cm.completion,cm.completiongradeitemnumber,cm.completionview,cm.added FROM {$CFG->prefix}course_modules cm INNER JOIN {$CFG->prefix}modules m ON m.id=cm.module INNER JOIN {$CFG->prefix}course_sections s ON s.id=cm.section WHERE s.course=cm.course AND cm.course=$courseid $wsql ORDER BY s.section "; $listcontent = $DB->get_records_sql($sql); $listcontent=$this->add_info_tolist($listcontent,$courseid,$section); $listcontent=$this->oder_list($listcontent); return $listcontent; } private function add_info_tolist($listcontent,$courseid,$section=null) { if(empty($listcontent)) {return null;} $listcontentnew=array(); $listplugins=array(); foreach ($listcontent as $d) { $name=$d->module; $listplugins[$name]= $name; } $listcontentname=array(); foreach ($listplugins as $plugin) { $instacelist=$this->get_name($plugin,$courseid); foreach ($instacelist as $linfo) { $id=$linfo->id; $key="$plugin/$id"; $listcontentname[$key]=$linfo; } } foreach ( $listcontent as $lcontent) { $instance=$lcontent->instance; $module=$lcontent->module; $key="$module/$instance"; if(array_key_exists($key,$listcontentname)){ $info=$listcontentname[$key]; $lcontent->name=$info->name; $lcontent->intro=$info->intro; } array_push($listcontentnew,$lcontent); } return $listcontentnew; } private function oder_list($listcontent) { if(empty($listcontent)) {return null;} $newlistcontent=array(); $listbykey=array(); $sectionsequences=array(); foreach ($listcontent as $lc) { $key= $lc->section."/".$lc->id; $listbykey[$key]=$lc; $seq=array(); $pos=stripos($lc->activitysequence, ","); if($pos=== false){ $seq=array($lc->activitysequence); }else{ $seq=explode(",",$lc->activitysequence); } $sectionsequences[$lc->section]=$seq; } foreach ( $sectionsequences as $skey => $listidativity) { foreach ($listidativity as $ativityid) { $ativkey=$skey."/".$ativityid; if (array_key_exists($ativkey,$listbykey)){ $itemativity=$listbykey[$ativkey]; array_push($newlistcontent,$itemativity); } } } return $newlistcontent; } private function get_name($plugin,$courseid) { global $DB; global $CFG; $sql="SELECT id,name,intro FROM {$CFG->prefix}$plugin WHERE course=$courseid"; $rows = $DB->get_records_sql($sql); return $rows; } function getListcontent() { return $this->listcontent; } function setListcontent($listcontent) { $this->listcontent = $listcontent; } } ?>