Skip to content

Commit

Permalink
lib MDL-25981 Improved modinfo
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sammarshallou committed Jan 26, 2011
1 parent 8cdc85a commit 0d8b6a6
Show file tree
Hide file tree
Showing 14 changed files with 1,412 additions and 407 deletions.
3 changes: 2 additions & 1 deletion blocks/activity_modules/block_activity_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ function get_content() {
$archetypes = array();

foreach($modinfo->cms as $cm) {
if (!$cm->uservisible or $cm->modname === 'label') {
// Exclude activities which are not visible or have no link (=label)
if (!$cm->uservisible or !$cm->has_view()) {
continue;
}
if (array_key_exists($cm->modname, $modfullnames)) {
Expand Down
42 changes: 15 additions & 27 deletions blocks/site_main_menu/block_site_main_menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,19 @@ function get_content() {
if (!$cm->uservisible) {
continue;
}
if ($cm->modname == 'label') {
$this->content->items[] = format_text($cm->extra, FORMAT_HTML, $options);

list($content, $instancename) =
get_print_section_cm_text($cm, $course);

if (!($url = $cm->get_url())) {
$this->content->items[] = $content;
$this->content->icons[] = '';
} else {
$linkcss = $cm->visible ? '' : ' class="dimmed" ';
$instancename = format_string($cm->name, true, $course->id);
//Accessibility: incidental image - should be empty Alt text
if (!empty($cm->icon)) {
$icon = $OUTPUT->pix_url($cm->icon);
} else {
$icon = $OUTPUT->pix_url('icon', $cm->modname);
}
$icon = '<img src="'.$icon.'" class="icon" alt="" />&nbsp;';
$icon = '<img src="' . $cm->get_icon_url() . '" class="icon" alt="" />&nbsp;';
$this->content->items[] = '<a title="'.$cm->modplural.'" '.$linkcss.' '.$cm->extra.
' href="'.$CFG->wwwroot.'/mod/'.$cm->modname.'/view.php?id='.$cm->id.'">'.$icon.$instancename.'</a>';
' href="' . $url . '">' . $icon . $instancename . '</a>';
}
}
}
Expand Down Expand Up @@ -114,28 +112,18 @@ function get_content() {
'<img style="height:16px; width:80px; border:0px" src="'.$OUTPUT->pix_url('movehere') . '" alt="'.$strmovehere.'" /></a>';
$this->content->icons[] = '';
}
$instancename = $modinfo->cms[$modnumber]->name;
$instancename = format_string($instancename, true, $course->id);
list($content, $instancename) =
get_print_section_cm_text($modinfo->cms[$modnumber], $course);
$linkcss = $mod->visible ? '' : ' class="dimmed" ';
if (!empty($modinfo->cms[$modnumber]->extra)) {
$extra = $modinfo->cms[$modnumber]->extra;
} else {
$extra = '';
}
if (!empty($modinfo->cms[$modnumber]->icon)) {
$icon = $OUTPUT->pix_url($modinfo->cms[$modnumber]->icon);
} else {
$icon = $OUTPUT->pix_url('icon', $mod->modname);
}

if ($mod->modname == 'label') {
$this->content->items[] = format_text($extra, FORMAT_HTML,$options).$editbuttons;
if (!($url = $mod->get_url())) {
$this->content->items[] = $content . $editbuttons;
$this->content->icons[] = '';
} else {
//Accessibility: incidental image - should be empty Alt text
$icon = '<img src="'.$icon.'" class="icon" alt="" />&nbsp;';
$this->content->items[] = '<a title="'.$mod->modfullname.'" '.$linkcss.' '.$extra.
' href="'.$CFG->wwwroot.'/mod/'.$mod->modname.'/view.php?id='.$mod->id.'">'.$icon.$instancename.'</a>'.$editbuttons;
$icon = '<img src="' . $mod->get_icon_url() . '" class="icon" alt="" />&nbsp;';
$this->content->items[] = '<a title="' . $mod->modfullname . '" ' . $linkcss . ' ' . $mod->extra .
' href="' . $url . '">' . $icon . $instancename . '</a>' . $editbuttons;
}
}
}
Expand Down
43 changes: 16 additions & 27 deletions blocks/social_activities/block_social_activities.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,19 @@ function get_content() {
if (!$cm->uservisible) {
continue;
}
if ($cm->modname == 'label') {
$this->content->items[] = format_text($cm->extra, FORMAT_HTML, $options);

list($content, $instancename) =
get_print_section_cm_text($cm, $course);

if (!($url = $cm->get_url())) {
$this->content->items[] = $content;
$this->content->icons[] = '';
} else {
$linkcss = $cm->visible ? '' : ' class="dimmed" ';
$instancename = format_string($cm->name, true, $course->id);
//Accessibility: incidental image - should be empty Alt text
if (!empty($cm->icon)) {
$icon = $OUTPUT->pix_url($cm->icon);
} else {
$icon = $OUTPUT->pix_url('icon', $cm->modname);
}
$icon = '<img src="'.$icon.'" class="icon" alt="" />&nbsp;';
$icon = '<img src="' . $cm->get_icon_url() . '" class="icon" alt="" />&nbsp;';
$this->content->items[] = '<a title="'.$cm->modplural.'" '.$linkcss.' '.$cm->extra.
' href="'.$CFG->wwwroot.'/mod/'.$cm->modname.'/view.php?id='.$cm->id.'">'.$icon.$instancename.'</a>';
' href="' . $url . '">' . $icon . $instancename . '</a>';
}
}
}
Expand Down Expand Up @@ -123,28 +121,19 @@ function get_content() {
'<img style="height:16px; width:80px; border:0px" src="'.$OUTPUT->pix_url('movehere') . '" alt="'.$strmovehere.'" /></a>';
$this->content->icons[] = '';
}
$instancename = $modinfo->cms[$modnumber]->name;
$instancename = format_string($instancename, true, $course->id);
list($content, $instancename) =
get_print_section_cm_text($modinfo->cms[$modnumber], $course);

$linkcss = $mod->visible ? '' : ' class="dimmed" ';
if (!empty($modinfo->cms[$modnumber]->extra)) {
$extra = $modinfo->cms[$modnumber]->extra;
} else {
$extra = '';
}
if (!empty($modinfo->cms[$modnumber]->icon)) {
$icon = $OUTPUT->pix_url($modinfo->cms[$modnumber]->icon);
} else {
$icon = $OUTPUT->pix_url('icon', $mod->modname);
}

if ($mod->modname == 'label') {
$this->content->items[] = format_text($extra, FORMAT_HTML, $options).$editbuttons;
if (!($url = $mod->get_url())) {
$this->content->items[] = $content . $editbuttons;
$this->content->icons[] = '';
} else {
//Accessibility: incidental image - should be empty Alt text
$icon = '<img src="'.$icon.'" class="icon" alt="" />&nbsp;';
$this->content->items[] = '<a title="'.$mod->modfullname.'" '.$linkcss.' '.$extra.
' href="'.$CFG->wwwroot.'/mod/'.$mod->modname.'/view.php?id='.$mod->id.'">'.$icon.$instancename.'</a>'.$editbuttons;
$icon = '<img src="' . $mod->get_icon_url() . '" class="icon" alt="" />&nbsp;';
$this->content->items[] = '<a title="' . $mod->modfullname . '" ' . $linkcss . ' ' . $mod->extra .
' href="' . $url . '">' . $icon . $instancename . '</a>' . $editbuttons;
}
}
}
Expand Down
Loading

0 comments on commit 0d8b6a6

Please sign in to comment.