Skip to content

Commit

Permalink
MDL-76578 core_course: One section per page summary information
Browse files Browse the repository at this point in the history
  • Loading branch information
Amaia Anabitarte committed Dec 26, 2022
1 parent 37e16d4 commit 293bc2d
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 5 deletions.
Expand Up @@ -68,13 +68,14 @@ public function __construct(course_format $format, section_info $section) {
*/
public function export_for_template(\renderer_base $output): stdClass {

list($mods, $complete, $total) = $this->calculate_section_stats();
list($mods, $complete, $total, $showcompletion) = $this->calculate_section_stats();

if (empty($mods)) {
return new stdClass();
}

$data = (object)[
'showcompletion' => $showcompletion,
'total' => $total,
'complete' => $complete,
'mods' => array_values($mods),
Expand Down Expand Up @@ -104,6 +105,7 @@ private function calculate_section_stats(): array {
$cmids = $modinfo->sections[$section->section] ?? [];

$cancomplete = isloggedin() && !isguestuser();
$showcompletion = false;
foreach ($cmids as $cmid) {
$thismod = $modinfo->cms[$cmid];

Expand All @@ -116,6 +118,7 @@ private function calculate_section_stats(): array {
$mods[$thismod->modname]['count'] = 1;
}
if ($cancomplete && $completioninfo->is_enabled($thismod) != COMPLETION_TRACKING_NONE) {
$showcompletion = true;
$total++;
$completiondata = $completioninfo->get_data($thismod, true);
if ($completiondata->completionstate == COMPLETION_COMPLETE ||
Expand All @@ -126,6 +129,6 @@ private function calculate_section_stats(): array {
}
}

return [$mods, $complete, $total];
return [$mods, $complete, $total, $showcompletion];
}
}
Expand Up @@ -21,6 +21,7 @@
Example context (json):
{
"showcompletion": true,
"mods": [
{
"name": "Forums",
Expand All @@ -39,6 +40,8 @@
<span class="activity-count">{{name}}: {{count}}</span>
{{/mods}}
</div>
<div class="section-summary-activities pr-2 mdl-right">
<span class="activity-count">{{modprogress}}</span>
</div>
{{#showcompletion}}
<div class="section-summary-activities pr-2 mdl-right">
<span class="activity-count">{{modprogress}}</span>
</div>
{{/showcompletion}}
72 changes: 72 additions & 0 deletions course/tests/behat/paged_course_information.feature
@@ -0,0 +1,72 @@
@core @core_course
Feature: Course paged mode information
In order to split the course in parts
As a teacher
I need to display the proper section information in a paged mode course

@javascript
Scenario Outline: Section summary information for teachers and students in paged courses
Given the following "courses" exist:
| fullname | shortname | category | format | numsections | coursedisplay | enablecompletion |
| Course 1 | C1 | 0 | <courseformat> | 3 | 1 | <completion> |
And the following "activities" exist:
| activity | course | name | section | completion |
| chat | C1 | Chat room | 1 | <completion> |
| data | C1 | Database | 1 | <completion> |
| forum | C1 | First forum | 2 | <completion> |
| forum | C1 | Second forum | 2 | <completion> |
And the following "users" exist:
| username | firstname | lastname | email |
| student1 | Student | First | student1@example.com |
| teacher1 | Teacher | First | teacher1@example.com |
And the following "course enrolments" exist:
| user | course | role |
| student1 | C1 | student |
| teacher1 | C1 | editingteacher |
When I log in as "<user>"
And I am on "Course 1" course homepage
Then I should see "Chat: 1" in the "#section-1" "css_element"
And I should see "Database: 1" in the "#section-1" "css_element"
And I should <show> "Progress:" in the "#section-1" "css_element"
And I should see "Forums: 2" in the "#section-2" "css_element"
And I should <show> "Progress:" in the "#section-2" "css_element"

Examples:
| user | courseformat | completion | show |
| student1 | topics | 0 | not see |
| student1 | weeks | 0 | not see |
| student1 | topics | 1 | see |
| student1 | weeks | 1 | see |
| teacher1 | topics | 0 | not see |
| teacher1 | weeks | 0 | not see |
| teacher1 | topics | 1 | see |
| teacher1 | weeks | 1 | see |

@javascript
Scenario Outline: Section summary information for guest in paged courses
Given the following "courses" exist:
| fullname | shortname | category | format | numsections | coursedisplay | enablecompletion |
| Course 1 | C1 | 0 | <courseformat> | 3 | 1 | <completion> |
And the following "activities" exist:
| activity | course | name | section | completion |
| chat | C1 | Chat room | 1 | <completion> |
| data | C1 | Database | 1 | <completion> |
| forum | C1 | First forum | 2 | <completion> |
| forum | C1 | Second forum | 2 | <completion> |
And I am on the "Course 1" "enrolment methods" page logged in as admin
And I click on "Enable" "link" in the "Guest access" "table_row"
And I log out
When I log in as "guest"
And I am on "Course 1" course homepage
Then I should see "Chat: 1" in the "#section-1" "css_element"
And I should see "Database: 1" in the "#section-1" "css_element"
And I should not see "Progress:" in the "#section-1" "css_element"
And I should see "Forums: 2" in the "#section-2" "css_element"
And I should not see "Progress:" in the "#section-2" "css_element"

Examples:
| courseformat | completion |
| topics | 0 |
| weeks | 0 |
| topics | 1 |
| weeks | 1 |

0 comments on commit 293bc2d

Please sign in to comment.