Skip to content

Commit

Permalink
MDL-27829 blocks: added some brains to generate_page_type_patterns() …
Browse files Browse the repository at this point in the history
…so that it can handle special cases like course reports
  • Loading branch information
andyjdavis committed Jun 22, 2011
1 parent 3552484 commit b822fc8
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 10 deletions.
2 changes: 1 addition & 1 deletion course/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -4230,4 +4230,4 @@ function course_pagetypelist($pagetype, $parentcontext, $currentcontext) {
'mod-*'=>get_string('page-mod-x', 'pagetype')
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

$string['completion:view'] = 'View course completion report';
$string['completiondate']='Completion date';
$string['pluginpagetype'] = 'Any completion course report';
$string['pluginname']='Course completion';
46 changes: 46 additions & 0 deletions course/report/lib.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* This file contains functions used by the outline report
*
* @since 2.1
* @package course-report
* @copyright 2011 Andrew Davis
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

/**
* Return a list of page types
* @param string $pagetype current page type
* @param stdClass $parentcontext Block's parent context
* @param stdClass $currentcontext Current context of block
*/
function coursereport_pagetypelist($pagetype, $parentcontext, $currentcontext) {
$array = array('*'=>get_string('page-x', 'pagetype'),
'course-report-*'=>get_string('page-course-report-x', 'pagetype')
);

//extract course-report-outline from course-report-outline-index
$bits = explode('-', $pagetype);
if (count($bits >= 3)) {
$report = array_slice($bits, 2, 1);
$array['course-report-'.$report[0].'-*'] = get_string('pluginpagetype', 'coursereport_'.$report);
}

return $array;
}
1 change: 1 addition & 0 deletions course/report/log/lang/en/coursereport_log.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@
$string['log:view'] = 'View course logs';
$string['log:viewlive'] = 'View live logs';
$string['log:viewtoday'] = 'View today\'s logs';
$string['pluginpagetype'] = 'Any log course report';
$string['pluginname'] = 'Logs';
1 change: 1 addition & 0 deletions course/report/outline/lang/en/coursereport_outline.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
*/

$string['outline:view'] = 'View course activity report';
$string['pluginpagetype'] = 'Any outline course report';
$string['pluginname'] = 'Course activity';
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
*/

$string['participation:view'] = 'View course participation report';
$string['pluginpagetype'] = 'Any participation course report';
$string['pluginname'] = 'Course participation';
1 change: 1 addition & 0 deletions course/report/progress/lang/en/coursereport_progress.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
*/

$string['pluginname'] = 'Activity completion';
$string['pluginpagetype'] = 'Any progress course report';
$string['progress:view'] = 'View activity completion reports';
1 change: 1 addition & 0 deletions course/report/stats/lang/en/coursereport_stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
*/

$string['pluginname'] = 'Course statistics';
$string['pluginpagetype'] = 'Any stats course report';
$string['stats:view'] = 'View course statistics report';
1 change: 1 addition & 0 deletions lang/en/pagetype.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

$string['page-course-view-x'] = 'Any type of course main page';
$string['page-course-x'] = 'Any course page';
$string['page-course-report-x'] = 'Any course report';
$string['page-mod-x'] = 'Any activity module page';
$string['page-mod-x-view'] = 'Any main activity module page';
$string['page-my-index'] = 'My home page';
Expand Down
41 changes: 32 additions & 9 deletions lib/blocklib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1563,28 +1563,51 @@ function generate_page_type_patterns($pagetype, $parentcontext = null, $currentc

$bits = explode('-', $pagetype);

$component = clean_param(reset($bits), PARAM_ALPHANUMEXT);
$function = 'default_pagetypelist';

$core = get_core_subsystems();
$plugins = get_plugin_types();

// First check to see if the initial component is a core component
// if its not check to see if it is a plugin component.
if (array_key_exists($component, $core) && !empty($core[$component])) {
$libfile = $CFG->dirroot.'/'.$core[$component].'/lib.php';
//progressively strip pieces off the page type looking for a match
//eg: for pagetype "course-report-outline-index" try coursereportoutlineindex
// then coursereportoutline then coursereport then course
$componentarray = null;
for($i = count($bits); $i > 0; $i--) {
$componentarray = array_slice($bits, 0, $i);
$component = implode($componentarray);

// Look for special case components like course reports
$libfile = $CFG->dirroot.'/'.implode('/', $componentarray).'/lib.php';
if (file_exists($libfile)) {
require_once($libfile);
if (function_exists($component.'_pagetypelist')) {
$function = $component.'_pagetypelist';
break;
}
}

// Then check to see if the component is a core component
if (array_key_exists($component, $core) && !empty($core[$component])) {
$libfile = $CFG->dirroot.'/'.$core[$component].'/lib.php';
if (file_exists($libfile)) {
require_once($libfile);
if (function_exists($component.'_pagetypelist')) {
$function = $component.'_pagetypelist';
break;
}
}
}
} else if (array_key_exists($component, $plugins) && !empty($plugins[$component])) {
$function = 'plugin_pagetypelist';
if (function_exists($component.'_pagetypelist')) {
$function = $component.'_pagetypelist';

// If its not a special or core component check to see if it is a plugin component
if (array_key_exists($component, $plugins) && !empty($plugins[$component])) {
$function = 'plugin_pagetypelist';
if (function_exists($component.'_pagetypelist')) {
$function = $component.'_pagetypelist';
break;
}
}
}

// Call the most appropriate function we could determine
$patterns = $function($pagetype, $parentcontext, $currentcontext);
if (empty($patterns)) {
Expand Down

0 comments on commit b822fc8

Please sign in to comment.