Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add section filter to overview #60

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
24 changes: 21 additions & 3 deletions 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,14 +107,14 @@
echo $OUTPUT->container_start('block_completion_progress');

// Check if activities/resources have been selected in config.
$activities = block_completion_progress_get_activities($courseid, $config);
if ($activities == null) {
$activities = block_completion_progress_get_activities($courseid, $config, $section);
if ($activities == null && empty($section)) {
echo get_string('no_activities_message', 'block_completion_progress');
echo $OUTPUT->container_end();
echo $OUTPUT->footer();
die();
}
if (empty($activities)) {
if (empty($activities) && empty($section)) {
echo get_string('no_visible_activities_message', 'block_completion_progress');
echo $OUTPUT->container_end();
echo $OUTPUT->footer();
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);
Comment on lines +176 to +189
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest using this instead:

// Output the sections menu.
$format = course_get_format($COURSE);
if ($format->uses_sections()) {
    $sections = [ -1 => get_string('allsections', 'block_completion_progress') ];
    foreach ($format->get_sections() as $sectinfo) {
        $sections[$sectinfo->section] = $format->get_section_name($sectinfo);
    }
    echo '&nbsp;' . get_string('section') . '&nbsp;';
    echo $OUTPUT->single_select($PAGE->url, 'section', $sections, $section);
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other adjustments as a consequence of using the section number instead of its record ID are obviously necessary with that change.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks I will check that :)

echo $OUTPUT->container_end();

// Apply group restrictions.
Expand Down