Skip to content

Commit

Permalink
MDL-78200 course: Add group mode information to course page
Browse files Browse the repository at this point in the history
  • Loading branch information
Amaia Anabitarte committed Jul 3, 2023
1 parent 8dbb618 commit 85e554b
Show file tree
Hide file tree
Showing 13 changed files with 358 additions and 35 deletions.
2 changes: 2 additions & 0 deletions course/externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ public static function get_course_contents($courseid, $options = array()) {
$module['downloadcontent'] = $cm->downloadcontent;
$module['noviewlink'] = plugin_supports('mod', $cm->modname, FEATURE_NO_VIEW_LINK, false);
$module['dates'] = $activitydates;
$module['groupmode'] = $cm->groupmode;

// Check module completion.
$completion = $completioninfo->is_enabled($cm);
Expand Down Expand Up @@ -488,6 +489,7 @@ public static function get_course_contents_returns() {
VALUE_DEFAULT,
[]
),
'groupmode' => new external_value(PARAM_INT, 'Group mode value', VALUE_OPTIONAL),
'contents' => new external_multiple_structure(
new external_single_structure(
array(
Expand Down
38 changes: 38 additions & 0 deletions course/format/classes/output/local/content/cm.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public function export_for_template(renderer_base $output): stdClass {
$haspartials['alternative'] = $this->add_alternative_content_data($data, $output);
$haspartials['completion'] = $this->add_completion_data($data, $output);
$haspartials['editor'] = $this->add_editor_data($data, $output);
$haspartials['groupmode'] = $this->add_groupmode_data($data, $output);
$this->add_format_data($data, $haspartials, $output);

// Calculated fields.
Expand Down Expand Up @@ -267,6 +268,7 @@ protected function add_format_data(stdClass &$data, array $haspartials, renderer
$this->mod->has_custom_cmlist_item() &&
!$haspartials['availability'] &&
!$haspartials['completion'] &&
!$haspartials['groupmode'] &&
!isset($data->modhiddenfromstudents) &&
!isset($data->modstealth) &&
!$this->format->show_editor()
Expand Down Expand Up @@ -304,6 +306,42 @@ protected function add_editor_data(stdClass &$data, renderer_base $output): bool
return true;
}

/**
* Add group mode information to the data structure.
*
* @param stdClass $data the current cm data reference
* @param renderer_base $output typically, the renderer that's calling this function
* @return bool the module has group mode information
*/
protected function add_groupmode_data(stdClass &$data, renderer_base $output): bool {
if (!plugin_supports('mod', $this->mod->modname, FEATURE_GROUPS, false)) {
return false;
}

if (!has_capability('moodle/course:manageactivities', $this->mod->context)) {
return false;
}

switch ($this->mod->effectivegroupmode) {
case SEPARATEGROUPS:
$groupicon = 'i/groups';
$groupalt = get_string('groupsseparate', 'group');
break;
case VISIBLEGROUPS:
$groupicon = 'i/groupv';
$groupalt = get_string('groupsvisible', 'group');
break;
default:
return false;
}

$data->groupmodeinfo = (object) [
'groupicon' => $groupicon,
'groupalt' => $groupalt,
];
return true;
}

/**
* Returns the CSS classes for the activity name/content
*
Expand Down
9 changes: 9 additions & 0 deletions course/format/templates/local/content/cm/activity.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@
{{> core_courseformat/local/content/cm/badges }}
{{/ core_courseformat/local/content/cm/badges }}

{{! Group mode }}
{{#groupmodeinfo}}
<div class="activity-groupmode-info align-self-start mr-sm-2">
{{$ core_courseformat/local/content/cm/groupmode_info}}
{{> core_courseformat/local/content/cm/groupmode_info}}
{{/ core_courseformat/local/content/cm/groupmode_info}}
</div>
{{/groupmodeinfo}}

{{! Completion }}
{{#activityinfo}}
{{#hascompletion}}
Expand Down
39 changes: 39 additions & 0 deletions course/format/templates/local/content/cm/groupmode_info.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{{!
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/>.
}}
{{!
@template core_courseformat/local/content/cm/groupmode_info
Container to display group mode information on the course page.
Example context (json):
{
"activityname": "Course announcements",
"groupicon": "i/groupv",
"groupalt": "Visible groups"
}
}}
<div data-region="groupmode-information"
data-activityname="{{activityname}}"
class="groupmode-information d-flex align-items-center"
>
{{#groupicon}}
{{#pix}}{{groupicon}}, core, {{groupalt}}{{/pix}}
{{/groupicon}}
{{#groupalt}}
<div class="groupmode-icon-info">{{groupalt}}</div>
{{/groupalt}}
</div>
162 changes: 162 additions & 0 deletions course/tests/behat/activity_groupmode.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
@core @core_course @javascript
Feature: Activities group mode icons behavior in course page

Scenario Outline: Teachers should see group mode icons in both view and edit mode
Given the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
And the following "courses" exist:
| fullname | shortname | format |
| Course 1 | C1 | <courseformat> |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
And the following "activities" exist:
| activity | name | intro | course | idnumber | groupmode |
| forum | No groups forum | Forum with groupmode = 0 | C1 | forum1 | 0 |
| data | Visible groups database | Database with groupmode = 2 | C1 | data1 | 2 |
| assign | Separate groups assignment | Assignment with groupmode = 1 | C1 | assign1 | 1 |
And I log in as "teacher1"
When I am on "Course 1" course homepage with editing mode <editmode>
Then "Separate groups" "icon" should not exist in the "No groups forum" "activity"
And "Visible groups" "icon" should not exist in the "No groups forum" "activity"
And "Separate groups" "icon" should not exist in the "Visible groups database" "activity"
And "Visible groups" "icon" should exist in the "Visible groups database" "activity"
And "Separate groups" "icon" should exist in the "Separate groups assignment" "activity"
And "Visible groups" "icon" should not exist in the "Separate groups assignment" "activity"

Examples:
| editmode | courseformat |
| off | topics |
| on | topics |
| off | weeks |
| on | weeks |

Scenario Outline: Students should not see group mode icons in both view and edit mode
Given the following "users" exist:
| username | firstname | lastname | email |
| student1 | Student | 1 | student1@example.com |
And the following "courses" exist:
| fullname | shortname | format |
| Course 1 | C1 | <courseformat> |
And the following "course enrolments" exist:
| user | course | role |
| student1 | C1 | student |
And the following "activities" exist:
| activity | name | intro | course | idnumber | groupmode |
| forum | No groups forum | Forum with groupmode = 0 | C1 | forum1 | 0 |
| data | Visible groups database | Database with groupmode = 2 | C1 | data1 | 2 |
| assign | Separate groups assignment | Assignment with groupmode = 1 | C1 | assign1 | 1 |
When I am on the "C1" "Course" page logged in as "student1"
Then "Separate groups" "icon" should not exist in the "No groups forum" "activity"
And "Visible groups" "icon" should not exist in the "No groups forum" "activity"
And "Separate groups" "icon" should not exist in the "Visible groups database" "activity"
And "Visible groups" "icon" should not exist in the "Visible groups database" "activity"
And "Separate groups" "icon" should not exist in the "Separate groups assignment" "activity"
And "Visible groups" "icon" should not exist in the "Separate groups assignment" "activity"
# Giving moodle/course:manageactivities capability would let them see the icons.
And the following "role capability" exists:
| role | student |
| moodle/course:manageactivities | allow |
And I am on the "C1" "Course" page
And "Visible groups" "icon" should exist in the "Visible groups database" "activity"
And "Separate groups" "icon" should exist in the "Separate groups assignment" "activity"

Examples:
| courseformat |
| topics |
| weeks |

Scenario Outline: Resources don't support group mode never show groupmode icon in the course page
Given the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
And the following "courses" exist:
| fullname | shortname | format |
| Course 1 | C1 | <courseformat> |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
And the following "activities" exist:
| activity | name | intro | course | idnumber | groupmode |
| page | No groups page | Page with groupmode = 0 | C1 | page0 | 0 |
| page | Visible groups page | Page with groupmode = 2 | C1 | page2 | 2 |
| page | Separate groups page | Page with groupmode = 1 | C1 | page1 | 1 |
And I log in as "teacher1"
When I am on "Course 1" course homepage with editing mode on
Then "Separate groups" "icon" should not exist in the "No groups page" "activity"
And "Visible groups" "icon" should not exist in the "No groups page" "activity"
And "Separate groups" "icon" should not exist in the "Visible groups page" "activity"
And "Visible groups" "icon" should not exist in the "Visible groups page" "activity"
And "Separate groups" "icon" should not exist in the "Separate groups page" "activity"
And "Visible groups" "icon" should not exist in the "Separate groups page" "activity"

Examples:
| courseformat |
| topics |
| weeks |

Scenario Outline: Group mode icon behavior in the course page when forcing group mode in course settings
Given the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
And the following "courses" exist:
| fullname | shortname | format | groupmodeforce | groupmode |
| Course 1 | C1 | <courseformat> | 1 | <groupmode> |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
And the following "activities" exist:
| activity | name | intro | course | idnumber | groupmode |
| forum | No groups forum | Forum with groupmode = 0 | C1 | forum1 | 0 |
| data | Visible groups database | Database with groupmode = 2 | C1 | data1 | 2 |
| assign | Separate groups assignment | Assignment with groupmode = 1 | C1 | assign1 | 1 |
| page | No groups page | Doesn't support groupmode | C1 | page | 1 |
And I log in as "teacher1"
When I am on "Course 1" course homepage with editing mode on
Then "Separate groups" "icon" <separate> in the "No groups forum" "activity"
And "Visible groups" "icon" <visible> in the "No groups forum" "activity"
And "Separate groups" "icon" <separate> in the "Visible groups database" "activity"
And "Visible groups" "icon" <visible> in the "Visible groups database" "activity"
And "Separate groups" "icon" <separate> in the "Separate groups assignment" "activity"
And "Visible groups" "icon" <visible> in the "Separate groups assignment" "activity"
And "Separate groups" "icon" should not exist in the "No groups page" "activity"
And "Visible groups" "icon" should not exist in the "No groups page" "activity"

Examples:
| courseformat | groupmode | separate | visible |
| topics | 0 | should not exist | should not exist |
| topics | 1 | should exist | should not exist |
| topics | 2 | should not exist | should exist |
| weeks | 0 | should not exist | should not exist |
| weeks | 1 | should exist | should not exist |
| weeks | 2 | should not exist | should exist |

Scenario Outline: Group mode icon in the course page in small devices
Given the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
And the following "courses" exist:
| fullname | shortname | format |
| Course 1 | C1 | <courseformat> |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
And the following "activities" exist:
| activity | name | intro | course | idnumber | groupmode |
| forum | Forum | Forum with groupmode = 0 | C1 | forum1 | 0 |
| data | Database | Database with groupmode = 2 | C1 | data1 | 2 |
| assign | Assignment | Assignment with groupmode = 1 | C1 | assign1 | 1 |
| page | Page | Doesn't support groupmode | C1 | page | 1 |
And I log in as "teacher1"
When I am on "Course 1" course homepage with editing mode on
And I should not see "Separate groups"
And I should not see "Visible groups"
And I change viewport size to "480x800"
And I should see "Separate groups"
And I should see "Visible groups"

Examples:
| courseformat |
| topics |
| weeks |
2 changes: 0 additions & 2 deletions lib/classes/output/icon_system_fontawesome.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,6 @@ public function get_core_icon_map() {
'core:i/groupevent' => 'fa-group',
'core:i/groupn' => 'fa-user',
'core:i/group' => 'fa-users',
'core:i/groups' => 'fa-user-circle',
'core:i/groupv' => 'fa-user-circle-o',
'core:i/home' => 'fa-home',
'core:i/hide' => 'fa-eye',
'core:i/hierarchylock' => 'fa-lock',
Expand Down
Binary file modified pix/i/groups.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 11 additions & 3 deletions pix/i/groups.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified pix/i/groupv.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 85e554b

Please sign in to comment.