Skip to content

Commit

Permalink
Added new {ifingroup id|idnumber}{/ifingroup} tags.
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-milette committed Oct 9, 2020
1 parent 04eff2c commit 3471283
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Change Log
All notable changes to this project will be documented in this file.

## [2.0.3] dev-2020-10-07
## [2.0.4] dev-2020-10-09
### Added
- New {ifingroup id|idnumber}{/ifingroup} tags.
- New {filtercodes} tag. Note: Only works for teachers and above.
- New {alert style}{/alert} tags (ALPHA).
- New {ifincohort idname|idnumber}{/ifincohort} tags.
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ FilterCodes are meant to be entered as regular text in the Moodle WYSIWYG editor
* {courseidnumber} : Display a course's ID number.
* {sectionid} : Display the section ID (not to be confused with the section number).

Also see Courses section below.

### Categories

* {categoryid} : If in a course, the ID of the course's parent category, the category ID of a course category page, otherwise 0.
Expand Down Expand Up @@ -224,6 +226,7 @@ Note: {if`rolename`} and {ifmin`rolename`} type tags are based on role archetype
* {ifincourse}{/ifincourse} : Will display the enclosed content only if the user is in a course other than the Front page.
* {ifinsection}{/ifinsection} : Will display the enclosed content only if the user is in a section of a course which is not the Front Page.
* {ifnotinsection}{/ifnotinsection} : Will display the enclosed content only if the user is not in a section of a course.
* {ifingroup id|idnumber}{/ifingroup} : Display content if the user is part of the specified course group ID or group ID number.

#### Roles

Expand Down Expand Up @@ -660,6 +663,7 @@ Create a Page on your Moodle site, preferably in a course, so that those tags wo
* Is your tenant id 1? [{iftenant 1}]Yes[{/iftenant}] : {iftenant 1}Yes{/iftenant} Note: In Moodle classic, tenant id is assumed to be 1.
* Is this Moodle Workplace? [{ifworkplace}]Yes[{/ifworkplace}] : {ifworkplace}Yes{/ifworkplace}
* This is FilterCodes version [{filtercodes}] : {filtercodes} Note: Will be blank if you do not have the ability to edit this tag.
* Are you a member of the ATEAM group [{ifingroup ATEAM}]Yes[{/ifingroup}] ? : {ifingroup ATEAM}Yes{/ifingroup} Note: Only works in courses.

You can switch to different roles to see how each will affect the content being displayed.

Expand Down
27 changes: 27 additions & 0 deletions filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -1732,6 +1732,33 @@ function ($matches) use($mycohorts) {
}
}

// Tag: {ifingroup id|idnumber}.
if (stripos($text, '{ifingroup') !== false) {
static $mygroups;
if (!isset($mygroups)) { // Fetch my groups.
$mygroups = groups_get_all_groups($PAGE->course->id, $USER->id);
}
$re = '/{ifingroup\s+(.*?)\}(.*?)\{\/ifingroup\}/ims';
$found = preg_match_all($re, $text, $matches);
if ($found > 0) {
foreach ($matches[1] as $groupid) {
$key = '/{ifingroup\s+' . $groupid . '\}(.*?)\{\/ifingroup\}/ims';
$ismember = false;
foreach ($mygroups as $group) {
if ($groupid == $group->id || $groupid == $group->idnumber) {
$ismember = true;
break;
}
}
if ($ismember) { // Just remove the tags.
$replace[$key] = '$1';
} else { // Remove the ifingroup tags and content.
$replace[$key] = '';
}
}
}
}

// Tag: {iftenant idnumber|tenantid}. Only for Moodle Workplace
if (stripos($text, '{iftenant') !== false) {
if (class_exists('tool_tenant\tenancy')) {
Expand Down

0 comments on commit 3471283

Please sign in to comment.