From 3471283871c38c8d1f6f7da7916b0d8f61b43faf Mon Sep 17 00:00:00 2001 From: Michael Milette Date: Fri, 9 Oct 2020 06:01:49 -0400 Subject: [PATCH] Added new {ifingroup id|idnumber}{/ifingroup} tags. --- CHANGELOG.md | 3 ++- README.md | 4 ++++ filter.php | 27 +++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab46750..e01f5e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/README.md b/README.md index c073536..01d6871 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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 @@ -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. diff --git a/filter.php b/filter.php index bb4e846..6d6e49f 100644 --- a/filter.php +++ b/filter.php @@ -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')) {