From 9573270d4b11813f2051c4bd0f8fa4956f14b703 Mon Sep 17 00:00:00 2001 From: Justus Dieckmann Date: Tue, 30 Apr 2024 13:02:27 +0200 Subject: [PATCH] Update for Moodle 4.4 and Codestyle --- .github/workflows/moodle-ci.yml | 85 +++++-------------- .../moodle2/backup_groupmembers_stepslib.php | 9 +- ...store_groupmembers_activity_task.class.php | 13 +-- .../moodle2/restore_groupmembers_stepslib.php | 17 ++-- classes/event/course_module_viewed.php | 2 +- classes/groups.php | 8 +- db/access.php | 26 +++--- db/events.php | 2 +- db/upgrade.php | 2 - index.php | 6 +- lang/de/groupmembers.php | 36 ++++---- lang/en/groupmembers.php | 36 ++++---- lib.php | 6 +- mod_form.php | 28 +++--- renderer.php | 24 +++--- settings.php | 20 ++--- tests/groups_datastructure_test.php | 16 ++-- view.php | 4 +- 18 files changed, 157 insertions(+), 183 deletions(-) diff --git a/.github/workflows/moodle-ci.yml b/.github/workflows/moodle-ci.yml index e2cdd07..28b6f3d 100644 --- a/.github/workflows/moodle-ci.yml +++ b/.github/workflows/moodle-ci.yml @@ -9,7 +9,7 @@ jobs: strategy: matrix: php: ['8.2'] - moodle-branch: ['MOODLE_403_STABLE'] + moodle-branch: ['MOODLE_404_STABLE'] database: ['pgsql'] steps: @@ -17,7 +17,7 @@ jobs: run: docker run -p 5432:5432 -e POSTGRES_USER=postgres -e POSTGRES_HOST_AUTH_METHOD=trust -d postgres:14 - name: Check out repository code - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: path: plugin @@ -28,29 +28,9 @@ jobs: ini-values: max_input_vars=5000 coverage: none - - name: Get composer cache directory - id: composer-cache - run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - - - name: Composer cache - uses: actions/cache@v3 - with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-composer- - - - name: npm cache - uses: actions/cache@v3 - with: - path: ~/.npm - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-node- - - name: Initialise moodle-plugin-ci run: | - composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3 + composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^4 echo $(cd ci/bin; pwd) >> $GITHUB_PATH echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH sudo locale-gen en_AU.UTF-8 @@ -67,10 +47,6 @@ jobs: if: ${{ always() }} run: moodle-plugin-ci phplint - - name: PHP Copy/Paste Detector - if: ${{ always() }} - run: moodle-plugin-ci phpcpd - - name: PHP Mess Detector if: ${{ always() }} run: moodle-plugin-ci phpmd @@ -82,7 +58,6 @@ jobs: - name: Moodle PHPDoc Checker if: ${{ always() }} run: moodle-plugin-ci phpdoc - continue-on-error: true - name: Validating if: ${{ always() }} @@ -108,30 +83,20 @@ jobs: fail-fast: false matrix: php: ['8.0', '8.1', '8.2'] - moodle-branch: ['MOODLE_401_STABLE', 'MOODLE_402_STABLE', 'MOODLE_403_STABLE'] + moodle-branch: ['MOODLE_401_STABLE', 'MOODLE_402_STABLE', 'MOODLE_403_STABLE', 'MOODLE_404_STABLE'] database: ['mariadb', 'pgsql'] exclude: + - php: '8.0' + moodle-branch: 'MOODLE_404_STABLE' - php: '8.2' moodle-branch: 'MOODLE_401_STABLE' include: - php: '7.4' - moodle-branch: 'MOODLE_39_STABLE' - database: 'mariadb' - - php: '7.4' - moodle-branch: 'MOODLE_39_STABLE' - database: 'pgsql' - - php: '8.0' - moodle-branch: 'MOODLE_311_STABLE' - database: 'mariadb' - - php: '8.0' - moodle-branch: 'MOODLE_311_STABLE' + moodle-branch: 'MOODLE_401_STABLE' database: 'pgsql' - - php: '8.0' - moodle-branch: 'MOODLE_400_STABLE' + - php: '7.4' + moodle-branch: 'MOODLE_401_STABLE' database: 'mariadb' - - php: '8.0' - moodle-branch: 'MOODLE_400_STABLE' - database: 'pgsql' steps: - name: Start MariaDB @@ -143,7 +108,7 @@ jobs: run: docker run -p 5432:5432 -e POSTGRES_USER=postgres -e POSTGRES_HOST_AUTH_METHOD=trust -d postgres:14 - name: Check out repository code - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: path: plugin @@ -154,24 +119,6 @@ jobs: ini-values: max_input_vars=5000 coverage: none - - name: Get composer cache directory - id: composer-cache - run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - - name: Composer cache - uses: actions/cache@v3 - with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-composer- - - name: npm cache - uses: actions/cache@v3 - with: - path: ~/.npm - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-node- - - name: Initialise moodle-plugin-ci run: | composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3 @@ -194,3 +141,15 @@ jobs: - name: Behat features if: ${{ always() }} run: moodle-plugin-ci behat --profile chrome --auto-rerun 0 + + # This step allows to upload Behat faildump (screenshots) as workflow artifact, + # so it can be downloaded and inspected. You don't need this step if you + # are not running Behat test. Artifact will be retained for 7 days. + - name: Upload Behat Faildump + if: ${{ failure() && steps.behat.outcome == 'failure' }} + uses: actions/upload-artifact@v4 + with: + name: Behat Faildump (${{ join(matrix.*, ', ') }}) + path: ${{ github.workspace }}/moodledata/behat_dump + retention-days: 7 + if-no-files-found: ignore diff --git a/backup/moodle2/backup_groupmembers_stepslib.php b/backup/moodle2/backup_groupmembers_stepslib.php index 8829212..e58a124 100644 --- a/backup/moodle2/backup_groupmembers_stepslib.php +++ b/backup/moodle2/backup_groupmembers_stepslib.php @@ -27,17 +27,20 @@ */ class backup_groupmembers_activity_structure_step extends backup_activity_structure_step { + /** + * Define structure for backup step. + */ protected function define_structure() { // To know if we are including userinfo. $userinfo = $this->get_setting_value('userinfo'); // Define each element separated. - $groupmembers = new backup_nested_element('groupmembers', array('id'), - array('name', 'intro', 'introformat', 'listgroupingid', 'showgroups', 'showemail', 'timemodified')); + $groupmembers = new backup_nested_element('groupmembers', ['id'], + ['name', 'intro', 'introformat', 'listgroupingid', 'showgroups', 'showemail', 'timemodified']); // Define sources. - $groupmembers->set_source_table('groupmembers', array('id' => backup::VAR_ACTIVITYID)); + $groupmembers->set_source_table('groupmembers', ['id' => backup::VAR_ACTIVITYID]); // Define id annotations. diff --git a/backup/moodle2/restore_groupmembers_activity_task.class.php b/backup/moodle2/restore_groupmembers_activity_task.class.php index 62b1533..666ae2f 100644 --- a/backup/moodle2/restore_groupmembers_activity_task.class.php +++ b/backup/moodle2/restore_groupmembers_activity_task.class.php @@ -15,6 +15,9 @@ // along with Moodle. If not, see . /** + * Groupmembers restore task that provides all the settings and steps to perform one + * complete restore of the activity + * * @package mod_groupmembers * @copyright 2019 Justus Dieckmann WWU * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later @@ -49,9 +52,9 @@ protected function define_my_steps() { * processed by the link decoder */ public static function define_decode_contents() { - $contents = array(); + $contents = []; - $contents[] = new restore_decode_content('groupmembers', array('intro'), 'groupmembers'); + $contents[] = new restore_decode_content('groupmembers', ['intro'], 'groupmembers'); return $contents; } @@ -61,7 +64,7 @@ public static function define_decode_contents() { * to the activity to be executed by the link decoder */ public static function define_decode_rules() { - $rules = array(); + $rules = []; $rules[] = new restore_decode_rule('GROUPMEMBERVIEWBYID', '/mod/groupmember/view.php?id=$1', 'course_module'); $rules[] = new restore_decode_rule('GROUPMEMBERINDEX', '/mod/groupmember/index.php?id=$1', 'course'); @@ -77,7 +80,7 @@ public static function define_decode_rules() { * of {@link restore_log_rule} objects */ public static function define_restore_log_rules() { - $rules = array(); + $rules = []; $rules[] = new restore_log_rule('groupmembers', 'view', 'view.php?id={course_module}', '{groupmembers}'); @@ -95,7 +98,7 @@ public static function define_restore_log_rules() { * activity level. All them are rules not linked to any module instance (cmid = 0) */ public static function define_restore_log_rules_for_course() { - $rules = array(); + $rules = []; $rules[] = new restore_log_rule('groupmembers', 'view all', 'index.php?id={course}', null); diff --git a/backup/moodle2/restore_groupmembers_stepslib.php b/backup/moodle2/restore_groupmembers_stepslib.php index e1df6b5..2b0cd53 100644 --- a/backup/moodle2/restore_groupmembers_stepslib.php +++ b/backup/moodle2/restore_groupmembers_stepslib.php @@ -15,29 +15,33 @@ // along with Moodle. If not, see . /** + * Structure step to restore one groupmembers activity * @package mod_groupmembers * @copyright 2019 Justus Dieckmann WWU * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -/** - * Define all the restore steps that will be used by the restore_groupmembers_activity_task - */ - /** * Structure step to restore one groupmembers activity */ class restore_groupmembers_activity_structure_step extends restore_activity_structure_step { + /** + * Define structure of restore step. + */ protected function define_structure() { - $paths = array(); + $paths = []; $paths[] = new restore_path_element('groupmembers', '/activity/groupmembers'); // Return the paths wrapped into standard activity structure. return $this->prepare_activity_structure($paths); } + /** + * Restore groupmember activity. + * @param $data + */ protected function process_groupmembers($data) { global $DB; @@ -50,6 +54,9 @@ protected function process_groupmembers($data) { $this->apply_activity_instance($newitemid); } + /** + * Restore related files after execute. + */ protected function after_execute() { // Add groupmembers related files, no need to match by itemname (just internally handled context). $this->add_related_files('mod_groupmembers', 'intro', null); diff --git a/classes/event/course_module_viewed.php b/classes/event/course_module_viewed.php index 71c3501..561dfee 100644 --- a/classes/event/course_module_viewed.php +++ b/classes/event/course_module_viewed.php @@ -55,6 +55,6 @@ protected function init() { * @return array Mapping according to the definition above */ public static function get_objectid_mapping() { - return array('db' => 'groupmembers', 'restore' => 'groupmembers'); + return ['db' => 'groupmembers', 'restore' => 'groupmembers']; } } diff --git a/classes/groups.php b/classes/groups.php index 4d6a36d..f23b41e 100644 --- a/classes/groups.php +++ b/classes/groups.php @@ -47,7 +47,7 @@ class groups { * 'group' => \stdClass, 'members' => array[\stdClass], 'ismember' => bool ] */ public static function get_groups_and_members($courseid, $groupingid, $userid, $onlyown) { - $groupsandmembers = array(); + $groupsandmembers = []; // Fetch relevant groups. if ($onlyown) { @@ -66,11 +66,11 @@ public static function get_groups_and_members($courseid, $groupingid, $userid, $ // Get members of group. $members = groups_get_members($group->id); - $groupsandmembers[] = array( + $groupsandmembers[] = [ 'group' => $group, 'members' => $members, - 'ismember' => $ismember - ); + 'ismember' => $ismember, + ]; } return $groupsandmembers; diff --git a/db/access.php b/db/access.php index 6bd93c5..59bab7e 100644 --- a/db/access.php +++ b/db/access.php @@ -25,30 +25,30 @@ defined('MOODLE_INTERNAL') || die(); -$capabilities = array( +$capabilities = [ - 'mod/groupmembers:view' => array( + 'mod/groupmembers:view' => [ 'captype' => 'read', 'contextlevel' => CONTEXT_MODULE, - 'archetypes' => array( + 'archetypes' => [ 'guest' => CAP_ALLOW, 'student' => CAP_ALLOW, 'teacher' => CAP_ALLOW, 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ) - ), + 'manager' => CAP_ALLOW, + ], + ], - 'mod/groupmembers:addinstance' => array( + 'mod/groupmembers:addinstance' => [ 'riskbitmask' => RISK_XSS, 'captype' => 'write', 'contextlevel' => CONTEXT_COURSE, - 'archetypes' => array( + 'archetypes' => [ 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW - ), - 'clonepermissionsfrom' => 'moodle/course:manageactivities' - ), -); + 'manager' => CAP_ALLOW, + ], + 'clonepermissionsfrom' => 'moodle/course:manageactivities', + ], +]; diff --git a/db/events.php b/db/events.php index e904108..b706563 100644 --- a/db/events.php +++ b/db/events.php @@ -25,7 +25,7 @@ defined('MOODLE_INTERNAL') || die(); -$handlers = array(); +$handlers = []; /* List of events thrown from groupmembers module diff --git a/db/upgrade.php b/db/upgrade.php index 2facef9..11a4712 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -23,8 +23,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -defined('MOODLE_INTERNAL') || die(); - /** * Upgrade script (no-op) * @param int $oldversion Version number before update diff --git a/index.php b/index.php index ac9b926..3051565 100644 --- a/index.php +++ b/index.php @@ -27,14 +27,14 @@ require_once(__DIR__. '/lib.php'); $id = required_param('id', PARAM_INT); // Course ID. -$PAGE->set_url('/mod/groupmembers/index.php', array('id' => $id)); +$PAGE->set_url('/mod/groupmembers/index.php', ['id' => $id]); $course = $DB->get_record('course', ['id' => $id], '*', MUST_EXIST); require_course_login($course); $PAGE->set_pagelayout('incourse'); -$eventdata = array('context' => context_course::instance($id)); +$eventdata = ['context' => context_course::instance($id)]; $event = \mod_groupmembers\event\course_module_instance_list_viewed::create($eventdata); $event->add_record_snapshot('course', $course); $event->trigger(); @@ -54,7 +54,7 @@ -$linklist = array(); +$linklist = []; foreach ($instances as $instance) { $linklist[] = html_writer::link(new moodle_url('/mod/groupmembers/view.php', ['id' => $instance->coursemodule]), $instance->name); diff --git a/lang/de/groupmembers.php b/lang/de/groupmembers.php index 64e59b7..159f0ef 100644 --- a/lang/de/groupmembers.php +++ b/lang/de/groupmembers.php @@ -23,16 +23,20 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -$string['modulename'] = 'Gruppenmitglieder'; -$string['modulenameplural'] = 'Gruppenmitglieder'; -$string['modulename_help'] = 'Mit dem Gruppenmitglieder-Modul lassen sich die Mitglieder aller Gruppen einer Gruppierung auflisten.'; -$string['pluginname'] = 'Gruppenmitglieder'; -$string['pluginadministration'] = 'Gruppenmitglieder-Administration'; +$string['description'] = 'Beschreibung'; $string['groupmembers:addinstance'] = 'Neue Gruppenmitglieder-Aktivität hinzufügen'; $string['groupmembers:view'] = 'Gruppenmitglieder anzeigen'; $string['groupmembersname'] = 'Name der Mitgliederliste'; -$string['description'] = 'Beschreibung'; $string['listgrouping'] = 'Gruppierung'; +$string['mailhidden'] = 'E-Mail-Kontakt deaktiviert'; +$string['modulename'] = 'Gruppenmitglieder'; +$string['modulename_help'] = 'Mit dem Gruppenmitglieder-Modul lassen sich die Mitglieder aller Gruppen einer Gruppierung auflisten.'; +$string['modulenameplural'] = 'Gruppenmitglieder'; +$string['nogroupsavailable'] = 'Es sind derzeit keine Gruppen zur Anzeige hinterlegt.'; +$string['noowngroupsavailable'] = 'Du bist derzeit keiner Gruppe zugewiesen.'; +$string['pluginadministration'] = 'Gruppenmitglieder-Administration'; +$string['pluginname'] = 'Gruppenmitglieder'; +$string['privacy:metadata'] = 'Das Gruppenmitgliedermodul zeigt lediglich Informationen über Gruppen und Gruppierungen an, die an anderer Stelle unabhängig vom Modul gespeichert werden.'; $string['setting_adminsettingsheading'] = 'Einstellungen'; $string['setting_defaultsheading'] = 'Standardmäßige Voreinstellungen'; $string['setting_showdeptinstdefault'] = 'Abteilungen und Institutionen anzeigen'; @@ -47,32 +51,28 @@ $string['setting_showemaildefault_desc'] = 'Mit dieser Einstellung kontrollieren Sie die Voreinstellung von "E-Mail-Adressen anzeigen" innerhalb einer Aktivität.
Diese Einstellung wird nur berücksichtigt, wenn die Einstellung "E-Mail-Adressen anzeigen aktivieren" auch aktiviert ist.'; $string['setting_showemailenable'] = 'E-Mail-Adressen anzeigen aktivieren'; $string['setting_showemailenable_desc'] = 'Mit dieser Einstellung kontrollieren Sie ob die Anzeige von E-Mail-Adressen innerhalb einer Aktivität möglich ist oder nicht.'; +$string['setting_showgroupsdefault'] = 'Anzuzeigende Gruppen'; +$string['setting_showgroupsdefault_desc'] = 'Mit dieser Einstellung kontrollieren Sie die Voreinstellung von "Anzuzeigende Gruppen" innerhalb einer Aktivität.'; $string['setting_showphonedefault'] = 'Telefonnummern anzeigen'; $string['setting_showphonedefault_desc'] = 'Mit dieser Einstellung kontrollieren Sie die Voreinstellung von "Telefonnummern anzeigen" innerhalb einer Aktivität.
Diese Einstellung wird nur berücksichtigt, wenn die Einstellung "E-Mail-Adressen anzeigen aktivieren" auch aktiviert ist.'; $string['setting_showphoneenable'] = 'ETelefonnummern anzeigen aktivieren'; $string['setting_showphoneenable_desc'] = 'Mit dieser Einstellung kontrollieren Sie ob die Anzeige von Telefonnummern innerhalb einer Aktivität möglich ist oder nicht.'; -$string['setting_showgroupsdefault'] = 'Anzuzeigende Gruppen'; -$string['setting_showgroupsdefault_desc'] = 'Mit dieser Einstellung kontrollieren Sie die Voreinstellung von "Anzuzeigende Gruppen" innerhalb einer Aktivität.'; -$string['showgroups'] = 'Anzuzeigende Gruppen'; -$string['showgroups:all'] = 'Alle Gruppen der Gruppierung'; -$string['showgroups:own'] = 'Nur die eigene Gruppe'; $string['showdeptinst'] = 'Abteilungen und Institutionen anzeigen'; $string['showdesc'] = 'Beschreibungen anzeigen'; $string['showemail'] = 'E-Mail-Adressen anzeigen'; +$string['showemail:allgroups'] = 'Für alle Gruppen anzeigen'; $string['showemail:no'] = 'Nein, nur interne Nachrichten'; $string['showemail:owngroup'] = 'Für die eigene Gruppe anzeigen'; -$string['showemail:allgroups'] = 'Für alle Gruppen anzeigen'; +$string['showfield:allgroups'] = 'Für alle Gruppen anzeigen'; $string['showfield:no'] = 'Nein'; $string['showfield:owngroup'] = 'Für die eigene Gruppe anzeigen'; -$string['showfield:allgroups'] = 'Für alle Gruppen anzeigen'; +$string['showgroups'] = 'Anzuzeigende Gruppen'; +$string['showgroups:all'] = 'Alle Gruppen der Gruppierung'; +$string['showgroups:own'] = 'Nur die eigene Gruppe'; $string['showphone'] = 'Telefonnummern anzeigen'; -$string['user:fullname'] = 'Vorname / Nachname'; $string['user:contact'] = 'Kontakt'; $string['user:deptinst'] = 'Abteilung und Institution'; $string['user:desc'] = 'Beschreibung'; $string['user:descsummary'] = 'Beschreibung von {$a}'; +$string['user:fullname'] = 'Vorname / Nachname'; $string['user:phone'] = 'Telefon'; -$string['noowngroupsavailable'] = 'Du bist derzeit keiner Gruppe zugewiesen.'; -$string['nogroupsavailable'] = 'Es sind derzeit keine Gruppen zur Anzeige hinterlegt.'; -$string['mailhidden'] = 'E-Mail-Kontakt deaktiviert'; -$string['privacy:metadata'] = 'Das Gruppenmitgliedermodul zeigt lediglich Informationen über Gruppen und Gruppierungen an, die an anderer Stelle unabhängig vom Modul gespeichert werden.'; diff --git a/lang/en/groupmembers.php b/lang/en/groupmembers.php index 849e9ea..69d6c1a 100644 --- a/lang/en/groupmembers.php +++ b/lang/en/groupmembers.php @@ -23,16 +23,20 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -$string['modulename'] = 'Group Members'; -$string['modulenameplural'] = 'Group Members'; -$string['modulename_help'] = 'Use the Group Members module to list the members of all groups in one selected grouping.'; -$string['pluginname'] = 'Group Members'; -$string['pluginadministration'] = 'Group Members administration'; +$string['description'] = 'Description'; $string['groupmembers:addinstance'] = 'Add a new list of group members'; $string['groupmembers:view'] = 'View group members'; $string['groupmembersname'] = 'Name of members list'; -$string['description'] = 'Description'; $string['listgrouping'] = 'Grouping'; +$string['mailhidden'] = 'Mail contact disabled'; +$string['modulename'] = 'Group Members'; +$string['modulename_help'] = 'Use the Group Members module to list the members of all groups in one selected grouping.'; +$string['modulenameplural'] = 'Group Members'; +$string['nogroupsavailable'] = 'There are currently no groups to be displayed.'; +$string['noowngroupsavailable'] = 'You are currently not assigned to any group.'; +$string['pluginadministration'] = 'Group Members administration'; +$string['pluginname'] = 'Group Members'; +$string['privacy:metadata'] = 'The Group Members Activity only displays information about groups, but does not effect or store any personal data. The existing groups and groupings data is stored in other locations.'; $string['setting_adminsettingsheading'] = 'Group Members settings'; $string['setting_defaultsheading'] = 'Group Members default settings'; $string['setting_showdeptinstdefault'] = 'Show department and institution'; @@ -47,32 +51,28 @@ $string['setting_showemaildefault_desc'] = 'With this setting, you control the default value of the "Show e-mail addresses" module instance setting.
This setting will only be processed, if the "Enable showing e-mail addresses" is enabled.'; $string['setting_showemailenable'] = 'Enable showing e-mail addresses'; $string['setting_showemailenable_desc'] = 'With this setting, you control if showing e-mail addresses can be enabled within a module instance or not.'; +$string['setting_showgroupsdefault'] = 'Show groups'; +$string['setting_showgroupsdefault_desc'] = 'With this setting, you control the default value of the "Show groups" module instance setting.'; $string['setting_showphonedefault'] = 'Show phone numbers'; $string['setting_showphonedefault_desc'] = 'With this setting, you control the default value of the "Show phone numbers" module instance setting.
This setting will only be processed, if the "Enable showing phone numbers" is enabled.'; $string['setting_showphoneenable'] = 'Enable showing phone numbers'; $string['setting_showphoneenable_desc'] = 'With this setting, you control if showing phone numbers can be enabled within a module instance or not.'; -$string['setting_showgroupsdefault'] = 'Show groups'; -$string['setting_showgroupsdefault_desc'] = 'With this setting, you control the default value of the "Show groups" module instance setting.'; -$string['showgroups'] = 'Show groups'; -$string['showgroups:all'] = 'All groups of grouping'; -$string['showgroups:own'] = 'Only own group'; $string['showdeptinst'] = 'Show department and institution'; $string['showdesc'] = 'Show description'; $string['showemail'] = 'Show e-mail addresses'; +$string['showemail:allgroups'] = 'For all groups'; $string['showemail:no'] = 'No, only internal messages'; $string['showemail:owngroup'] = 'Only for own group'; -$string['showemail:allgroups'] = 'For all groups'; +$string['showfield:allgroups'] = 'For all groups'; $string['showfield:no'] = 'No'; $string['showfield:owngroup'] = 'Only for own group'; -$string['showfield:allgroups'] = 'For all groups'; +$string['showgroups'] = 'Show groups'; +$string['showgroups:all'] = 'All groups of grouping'; +$string['showgroups:own'] = 'Only own group'; $string['showphone'] = 'Show phone numbers'; -$string['user:fullname'] = 'First name / Surname'; $string['user:contact'] = 'Contact'; $string['user:deptinst'] = 'Department & Institution'; $string['user:desc'] = 'Description'; $string['user:descsummary'] = '{$a}\'s Description'; +$string['user:fullname'] = 'First name / Surname'; $string['user:phone'] = 'Phone'; -$string['noowngroupsavailable'] = 'You are currently not assigned to any group.'; -$string['nogroupsavailable'] = 'There are currently no groups to be displayed.'; -$string['mailhidden'] = 'Mail contact disabled'; -$string['privacy:metadata'] = 'The Group Members Activity only displays information about groups, but does not effect or store any personal data. The existing groups and groupings data is stored in other locations.'; diff --git a/lib.php b/lib.php index 8b1dedb..4622f69 100644 --- a/lib.php +++ b/lib.php @@ -148,10 +148,10 @@ function groupmembers_get_groupmembers($groupmembersid) { function groupmembers_view($groupmembers, $course, $cm, $context) { // Trigger course_module_viewed event. - $params = array( + $params = [ 'context' => $context, - 'objectid' => $groupmembers->id - ); + 'objectid' => $groupmembers->id, + ]; $event = \mod_groupmembers\event\course_module_viewed::create($params); $event->add_record_snapshot('course_modules', $cm); diff --git a/mod_form.php b/mod_form.php index 92a4856..2e1c73c 100644 --- a/mod_form.php +++ b/mod_form.php @@ -51,7 +51,7 @@ protected function definition() { // ------------------------------------------------------------------------------- $mform->addElement('header', 'general', get_string('general', 'form')); - $mform->addElement('text', 'name', get_string('groupmembersname', 'groupmembers'), array('size' => '64')); + $mform->addElement('text', 'name', get_string('groupmembersname', 'groupmembers'), ['size' => '64']); if (!empty($CFG->formatstringstriptags)) { $mform->setType('name', PARAM_TEXT); } else { @@ -66,33 +66,33 @@ protected function definition() { $mform->addElement('header', 'general', get_string('modulename', 'groupmembers')); // Groupings selector - used to select grouping for groups in activity. - $options = array(); - if ($groupings = $DB->get_records('groupings', array('courseid' => $COURSE->id))) { + $options = []; + if ($groupings = $DB->get_records('groupings', ['courseid' => $COURSE->id])) { foreach ($groupings as $grouping) { $options[$grouping->id] = format_string($grouping->name); } } core_collator::asort($options); - $options = array(0 => get_string('none')) + $options; + $options = [0 => get_string('none')] + $options; $mform->addElement('select', 'listgroupingid', get_string('listgrouping', 'groupmembers'), $options); $mform->addRule('listgroupingid', null, 'required', null, 'client'); // Group visibility selector - used to decide which groups to show in listing. - $options = array( + $options = [ GROUPMEMBERS_SHOWGROUPS_ALL => get_string('showgroups:all', 'groupmembers'), GROUPMEMBERS_SHOWGROUPS_OWN => get_string('showgroups:own', 'groupmembers'), - ); + ]; $mform->addElement('select', 'showgroups', get_string('showgroups', 'groupmembers'), $options); $mform->addRule('showgroups', null, 'required', null, 'client'); $mform->setDefault('showgroups', $config->showgroupsdefault); // E-Mail visibility selector - used to decide whether e-mail adresses should be shown to other users. if ($config->showemailenable) { - $options = array( + $options = [ GROUPMEMBERS_SHOWEMAIL_NO => get_string('showemail:no', 'groupmembers'), GROUPMEMBERS_SHOWEMAIL_OWNGROUP => get_string('showemail:owngroup', 'groupmembers'), GROUPMEMBERS_SHOWEMAIL_ALLGROUPS => get_string('showemail:allgroups', 'groupmembers'), - ); + ]; $mform->addElement('select', 'showemail', get_string('showemail', 'groupmembers'), $options); $mform->addRule('showemail', null, 'required', null, 'client'); $mform->setDefault('showemail', $config->showemaildefault); @@ -100,11 +100,11 @@ protected function definition() { // Phone visibility selector - used to decide whether phone numbers should be shown to other users. if ($config->showphoneenable) { - $options = array( + $options = [ GROUPMEMBERS_SHOWFIELD_NO => get_string('showfield:no', 'groupmembers'), GROUPMEMBERS_SHOWFIELD_OWNGROUP => get_string('showfield:owngroup', 'groupmembers'), GROUPMEMBERS_SHOWFIELD_ALLGROUPS => get_string('showfield:allgroups', 'groupmembers'), - ); + ]; $mform->addElement('select', 'showphone', get_string('showphone', 'groupmembers'), $options); $mform->addRule('showphone', null, 'required', null, 'client'); $mform->setDefault('showphone', $config->showphonedefault); @@ -112,11 +112,11 @@ protected function definition() { // Department & Institution visibility selector - used to decide whether dept. and inst. should be shown to other users. if ($config->showdeptinstenable) { - $options = array( + $options = [ GROUPMEMBERS_SHOWFIELD_NO => get_string('showfield:no', 'groupmembers'), GROUPMEMBERS_SHOWFIELD_OWNGROUP => get_string('showfield:owngroup', 'groupmembers'), GROUPMEMBERS_SHOWFIELD_ALLGROUPS => get_string('showfield:allgroups', 'groupmembers'), - ); + ]; $mform->addElement('select', 'showdeptinst', get_string('showdeptinst', 'groupmembers'), $options); $mform->addRule('showdeptinst', null, 'required', null, 'client'); $mform->setDefault('showdeptinst', $config->showdeptinstdefault); @@ -124,11 +124,11 @@ protected function definition() { // Department & Institution visibility selector - used to decide whether dept. and inst. should be shown to other users. if ($config->showdescenable) { - $options = array( + $options = [ GROUPMEMBERS_SHOWFIELD_NO => get_string('showfield:no', 'groupmembers'), GROUPMEMBERS_SHOWFIELD_OWNGROUP => get_string('showfield:owngroup', 'groupmembers'), GROUPMEMBERS_SHOWFIELD_ALLGROUPS => get_string('showfield:allgroups', 'groupmembers'), - ); + ]; $mform->addElement('select', 'showdesc', get_string('showdesc', 'groupmembers'), $options); $mform->addRule('showdesc', null, 'required', null, 'client'); $mform->setDefault('showdesc', $config->showdescdefault); diff --git a/renderer.php b/renderer.php index 76554f8..906f00e 100644 --- a/renderer.php +++ b/renderer.php @@ -60,11 +60,11 @@ public function render_allgroups(array $groups, $showemail, $showphone, $showdep $showdesc = GROUPMEMBERS_SHOWFIELD_NO; } - $data = array( - 'groups' => [] - ); + $data = [ + 'groups' => [], + ]; foreach ($groups as $group) { - $members = array(); + $members = []; foreach ($group['members'] as $member) { $memberemail = null; $memberemailtext = null; @@ -108,10 +108,10 @@ public function render_allgroups(array $groups, $showemail, $showphone, $showdep // Get data for additional fields if not hidden. if ($showphone > 0) { - $memberphone = implode(', ', array_filter(array($member->phone1, $member->phone2))); + $memberphone = implode(', ', array_filter([$member->phone1, $member->phone2])); } if ($showdeptinst > 0) { - $memberdeptinst = implode(', ', array_filter(array($member->department, $member->institution))); + $memberdeptinst = implode(', ', array_filter([$member->department, $member->institution])); } if ($showdesc > 0 && $member->description) { $memberdesc = $member->description; @@ -121,7 +121,7 @@ public function render_allgroups(array $groups, $showemail, $showphone, $showdep } } - $members[] = array( + $members[] = [ 'id' => $member->id, 'picture' => $this->output->user_picture($member), 'displayname' => fullname($member), @@ -133,19 +133,19 @@ public function render_allgroups(array $groups, $showemail, $showphone, $showdep 'memberphone' => $memberphone, 'memberdeptinst' => $memberdeptinst, 'memberdesc' => $memberdesc, - 'membersummary' => $membersummary - ); + 'membersummary' => $membersummary, + ]; } - $data['groups'][] = array( + $data['groups'][] = [ 'id' => $group['group']->id, 'name' => $group['group']->name, 'members' => $members, 'ismember' => $group['ismember'], 'showphone' => $showphone, 'showdeptinst' => $showdeptinst, - 'showdesc' => $showdesc - ); + 'showdesc' => $showdesc, + ]; } return $this->render_from_template('mod_groupmembers/allgroups', $data); } diff --git a/settings.php b/settings.php index 9050785..0d14c19 100644 --- a/settings.php +++ b/settings.php @@ -73,10 +73,10 @@ $name = 'mod_groupmembers/showgroupsdefault'; $title = get_string('setting_showgroupsdefault', 'mod_groupmembers', null, true); $description = get_string('setting_showgroupsdefault_desc', 'mod_groupmembers', null, true); - $options = array( + $options = [ GROUPMEMBERS_SHOWGROUPS_ALL => get_string('showgroups:all', 'groupmembers'), GROUPMEMBERS_SHOWGROUPS_OWN => get_string('showgroups:own', 'groupmembers'), - ); + ]; $setting = new admin_setting_configselect($name, $title, $description, GROUPMEMBERS_SHOWGROUPS_ALL, $options); $settings->add($setting); @@ -84,11 +84,11 @@ $name = 'mod_groupmembers/showemaildefault'; $title = get_string('setting_showemaildefault', 'mod_groupmembers', null, true); $description = get_string('setting_showemaildefault_desc', 'mod_groupmembers', null, true); - $options = array( + $options = [ GROUPMEMBERS_SHOWEMAIL_NO => get_string('showemail:no', 'groupmembers'), GROUPMEMBERS_SHOWEMAIL_OWNGROUP => get_string('showemail:owngroup', 'groupmembers'), GROUPMEMBERS_SHOWEMAIL_ALLGROUPS => get_string('showemail:allgroups', 'groupmembers'), - ); + ]; $setting = new admin_setting_configselect($name, $title, $description, GROUPMEMBERS_SHOWEMAIL_NO, $options); $settings->add($setting); @@ -96,11 +96,11 @@ $name = 'mod_groupmembers/showphonedefault'; $title = get_string('setting_showphonedefault', 'mod_groupmembers', null, true); $description = get_string('setting_showphonedefault_desc', 'mod_groupmembers', null, true); - $options = array( + $options = [ GROUPMEMBERS_SHOWFIELD_NO => get_string('showfield:no', 'groupmembers'), GROUPMEMBERS_SHOWFIELD_OWNGROUP => get_string('showfield:owngroup', 'groupmembers'), GROUPMEMBERS_SHOWFIELD_ALLGROUPS => get_string('showfield:allgroups', 'groupmembers'), - ); + ]; $setting = new admin_setting_configselect($name, $title, $description, GROUPMEMBERS_SHOWFIELD_NO, $options); $settings->add($setting); @@ -108,11 +108,11 @@ $name = 'mod_groupmembers/showdeptinstdefault'; $title = get_string('setting_showdeptinstdefault', 'mod_groupmembers', null, true); $description = get_string('setting_showdeptinstdefault_desc', 'mod_groupmembers', null, true); - $options = array( + $options = [ GROUPMEMBERS_SHOWFIELD_NO => get_string('showfield:no', 'groupmembers'), GROUPMEMBERS_SHOWFIELD_OWNGROUP => get_string('showfield:owngroup', 'groupmembers'), GROUPMEMBERS_SHOWFIELD_ALLGROUPS => get_string('showfield:allgroups', 'groupmembers'), - ); + ]; $setting = new admin_setting_configselect($name, $title, $description, GROUPMEMBERS_SHOWFIELD_NO, $options); $settings->add($setting); @@ -120,11 +120,11 @@ $name = 'mod_groupmembers/showdescdefault'; $title = get_string('setting_showdescdefault', 'mod_groupmembers', null, true); $description = get_string('setting_showdescdefault_desc', 'mod_groupmembers', null, true); - $options = array( + $options = [ GROUPMEMBERS_SHOWFIELD_NO => get_string('showfield:no', 'groupmembers'), GROUPMEMBERS_SHOWFIELD_OWNGROUP => get_string('showfield:owngroup', 'groupmembers'), GROUPMEMBERS_SHOWFIELD_ALLGROUPS => get_string('showfield:allgroups', 'groupmembers'), - ); + ]; $setting = new admin_setting_configselect($name, $title, $description, GROUPMEMBERS_SHOWFIELD_NO, $options); $settings->add($setting); diff --git a/tests/groups_datastructure_test.php b/tests/groups_datastructure_test.php index 78148e6..33fd096 100644 --- a/tests/groups_datastructure_test.php +++ b/tests/groups_datastructure_test.php @@ -23,7 +23,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -defined('MOODLE_INTERNAL') || die(); +namespace mod_groupmembers; /** * Test logic used by the renderer whether to show/hide particular elements @@ -33,14 +33,15 @@ * @copyright 2017 Jan C. Dageförde, WWU Münster * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class mod_groupmembers_groups_datastructure_testcase extends advanced_testcase { +final class groups_datastructure_test extends advanced_testcase { /** * Test pair: * - show only own groups * - show regardless of grouping + * @covers \mod_groupmembers\groups::get_groups_and_members */ - public function test_only_own_nogrouping() { + public function test_only_own_nogrouping(): void { $this->resetAfterTest(); $dg = static::getDataGenerator(); @@ -60,8 +61,9 @@ public function test_only_own_nogrouping() { * Test pair: * - show only own groups * - limit to particular grouping + * @covers \mod_groupmembers\groups::get_groups_and_members */ - public function test_only_own_withgrouping() { + public function test_only_own_withgrouping(): void { $this->resetAfterTest(); $dg = static::getDataGenerator(); list($courseid, $userid, $groupid, $groupingid) = $this->prepare_basic_data($dg); @@ -84,8 +86,9 @@ public function test_only_own_withgrouping() { * Test pair: * - show all groups * - show regardless of grouping + * @covers \mod_groupmembers\groups::get_groups_and_members */ - public function test_all_nogrouping() { + public function test_all_nogrouping(): void { $this->resetAfterTest(); $dg = static::getDataGenerator(); list($courseid, $userid, $groupid) = $this->prepare_basic_data($dg); @@ -115,8 +118,9 @@ public function test_all_nogrouping() { * Test pair: * - show all groups * - limit to particular grouping + * @covers \mod_groupmembers\groups::get_groups_and_members */ - public function test_all_withgrouping() { + public function test_all_withgrouping(): void { $this->resetAfterTest(); $dg = static::getDataGenerator(); list($courseid, $userid) = $this->prepare_basic_data($dg); diff --git a/view.php b/view.php index 0d3551a..bf54b31 100644 --- a/view.php +++ b/view.php @@ -27,7 +27,7 @@ require_once(__DIR__. '/lib.php'); $id = required_param('id', PARAM_INT); // Course Module ID. -$PAGE->set_url(new moodle_url('/mod/groupmembers/view.php', array('id' => $id))); +$PAGE->set_url(new moodle_url('/mod/groupmembers/view.php', ['id' => $id])); // Load course module. if (! $cm = get_coursemodule_from_id('groupmembers', $id)) { @@ -35,7 +35,7 @@ } // Load corresponding course. -if (! $course = $DB->get_record('course', array('id' => $cm->course))) { +if (! $course = $DB->get_record('course', ['id' => $cm->course])) { throw new moodle_exception('coursemisconf'); }