Skip to content

Commit

Permalink
Add section filter to overview
Browse files Browse the repository at this point in the history
  • Loading branch information
DegrangeM committed Jun 15, 2020
1 parent 42bbe97 commit 7b9593a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class block_completion_progress_edit_form extends block_edit_form {

protected function specific_definition($mform) {
global $COURSE, $OUTPUT;
$activities = block_completion_progress_get_activities($COURSE->id, null, 'orderbycourse');
$activities = block_completion_progress_get_activities($COURSE->id, null, null, 'orderbycourse');
$numactivies = count($activities);

// The My home version is not configurable.
Expand Down
1 change: 1 addition & 0 deletions lang/en/block_completion_progress.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

$string['allsections'] = 'All sections';
$string['completed_colour'] = '#73A839';
$string['completed_colour_descr'] = 'HTML Colour code for elements that have been completed';
$string['completed_colour_title'] = 'Completed colour';
Expand Down
5 changes: 3 additions & 2 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ function block_completion_progress_modules_with_alternate_links() {
* @param string forceorder An override for the course order setting
* @return array Activities with completion settings in the course
*/
function block_completion_progress_get_activities($courseid, $config = null, $forceorder = null) {
function block_completion_progress_get_activities($courseid, $config = null, $section = null, $forceorder = null) {
$modinfo = get_fast_modinfo($courseid, -1);
$sections = $modinfo->get_sections();
$activities = array();
Expand All @@ -182,7 +182,8 @@ function block_completion_progress_get_activities($courseid, $config = null, $fo
!isset($config->activitiesincluded) || (
$config->activitiesincluded != 'selectedactivities' ||
!empty($config->selectactivities) &&
in_array($module.'-'.$cm->instance, $config->selectactivities))))
in_array($module.'-'.$cm->instance, $config->selectactivities)))) && (
empty($section) || $cm->section == $section)
) {
$activities[] = array (
'type' => $module,
Expand Down
20 changes: 19 additions & 1 deletion overview.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
$page = optional_param('page', 0, PARAM_INT); // Which page to show.
$perpage = optional_param('perpage', DEFAULT_PAGE_SIZE, PARAM_INT); // How many per page.
$group = optional_param('group', 0, PARAM_ALPHANUMEXT); // Group selected.
$section = optional_param('section', 0, PARAM_INT); // Section selected.

// Determine course and context.
$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
Expand Down Expand Up @@ -83,6 +84,7 @@
'page' => $page,
'perpage' => $perpage,
'group' => $group,
'section' => $section,
'sesskey' => sesskey(),
'role' => $roleselected,
)
Expand All @@ -105,7 +107,7 @@
echo $OUTPUT->container_start('block_completion_progress');

// Check if activities/resources have been selected in config.
$activities = block_completion_progress_get_activities($courseid, $config);
$activities = block_completion_progress_get_activities($courseid, $config, $section);
if ($activities == null) {
echo get_string('no_activities_message', 'block_completion_progress');
echo $OUTPUT->container_end();
Expand Down Expand Up @@ -169,6 +171,22 @@
}
echo ' ' . get_string('role') . ' ';
echo $OUTPUT->single_select($PAGE->url, 'role', $rolestodisplay, $roleselected);

// Output the sections menu.
$sql = "SELECT DISTINCT s.id, s.section
FROM {course_sections} s
WHERE s.course = :courseid
AND s.sequence <> ''";
$params = array('courseid' => $courseid);
$sectionrecords = $DB->get_records_sql($sql, $params);
$sections = array_values($sectionrecords);
$numberofsections = count($sections);
$sectionstodisplay = array(0 => get_string('allsections', 'block_completion_progress'));
for ($i = 0; $i < $numberofsections; $i++) {
$sectionstodisplay[$sections[$i]->id] = get_section_name($courseid, $sections[$i]->section);
}
echo '&nbsp;' .get_string('section') . '&nbsp;';
echo $OUTPUT->single_select($PAGE->url, 'section', $sectionstodisplay, $section);
echo $OUTPUT->container_end();

// Apply group restrictions.
Expand Down

0 comments on commit 7b9593a

Please sign in to comment.