lib MDL-25981 Improved modinfo

This commit:
a) moves modinfo code into new library modinfolib.php
b) uses classes instead of stdClass objects, allowing a huge amount of documentation (and IDE completion)
c) adds hooks so that plugins other than forum can display messages like forum's 'unread', and plugins other than label can display html (apart from/as well as their view.php link) on the course view page
d) removes current hacks for forum and label (mainly in print_section but also across the code), replacing with new 'content' and similar variables [this is the reason for the changes in blocks, etc]
e) reduces size of modinfo in database (only when rebuilt) by excluding empty fields

The change is intended to be backward compatible and does not affect the format of modinfo in database.
This commit is contained in:
sam marshall
2011-01-26 10:29:16 +00:00
parent 8cdc85ac62
commit 0d8b6a69ce
14 changed files with 1415 additions and 410 deletions
+17 -11
View File
@@ -1026,10 +1026,14 @@ class global_navigation extends navigation_node {
if ($course->id !== SITEID) {
// Find the section for the $CM associated with the page and collect
// its section number.
foreach ($sections as $section) {
if ($section->id == $cm->section) {
$cm->sectionnumber = $section->section;
break;
if (isset($cm->sectionnum)) {
$cm->sectionnumber = $cm->sectionnum;
} else {
foreach ($sections as $section) {
if ($section->id == $cm->section) {
$cm->sectionnumber = $section->section;
break;
}
}
}
@@ -1429,10 +1433,10 @@ class global_navigation extends navigation_node {
*
* @param navigation_node $sectionnode
* @param int $sectionnumber
* @param stdClass $modinfo Object returned from {@see get_fast_modinfo()}
* @param course_modinfo $modinfo Object returned from {@see get_fast_modinfo()}
* @return array Array of activity nodes
*/
protected function load_section_activities(navigation_node $sectionnode, $sectionnumber, $modinfo) {
protected function load_section_activities(navigation_node $sectionnode, $sectionnumber, course_modinfo $modinfo) {
if (!array_key_exists($sectionnumber, $modinfo->sections)) {
return true;
}
@@ -1449,11 +1453,12 @@ class global_navigation extends navigation_node {
} else {
$icon = new pix_icon('icon', get_string('modulename', $cm->modname), $cm->modname);
}
$url = new moodle_url('/mod/'.$cm->modname.'/view.php', array('id'=>$cm->id));
$url = $cm->get_url();
$activitynode = $sectionnode->add(format_string($cm->name), $url, navigation_node::TYPE_ACTIVITY, null, $cm->id, $icon);
$activitynode->title(get_string('modulename', $cm->modname));
$activitynode->hidden = (!$cm->visible);
if ($cm->modname == 'label') {
if (!$url) {
// Do not show activities that don't have links!
$activitynode->display = false;
} else if ($this->module_extends_navigation($cm->modname)) {
$activitynode->nodetype = navigation_node::NODETYPE_BRANCH;
@@ -1482,11 +1487,12 @@ class global_navigation extends navigation_node {
} else {
$icon = new pix_icon('icon', get_string('modulename', $cm->modname), $cm->modname);
}
$url = new moodle_url('/mod/'.$cm->modname.'/view.php', array('id'=>$cm->id));
$url = $cm->get_url();
$activitynode = $coursenode->add(format_string($cm->name), $url, navigation_node::TYPE_ACTIVITY, null, $cm->id, $icon);
$activitynode->title(get_string('modulename', $cm->modname));
$activitynode->hidden = (!$cm->visible);
if ($cm->modname == 'label') {
if (!$url) {
// Don't show activities that don't have links!
$activitynode->display = false;
} else if ($this->module_extends_navigation($cm->modname)) {
$activitynode->nodetype = navigation_node::NODETYPE_BRANCH;
@@ -1509,7 +1515,7 @@ class global_navigation extends navigation_node {
* @param navigation_node $activity
* @return bool
*/
protected function load_activity(stdClass $cm, stdClass $course, navigation_node $activity) {
protected function load_activity($cm, stdClass $course, navigation_node $activity) {
global $CFG, $DB;
$activity->make_active();