mirror of
https://github.com/moodle/moodle.git
synced 2025-03-14 12:40:01 +01:00
MDL-78551 core_group: Add hooks api for group and membership
This commit is contained in:
parent
757be30c39
commit
ae8cae6d9a
41
group/classes/hook/after_group_created.php
Normal file
41
group/classes/hook/after_group_created.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
// 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/>.
|
||||
|
||||
namespace core_group\hook;
|
||||
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* Hook after group creation.
|
||||
*
|
||||
* @package core_group
|
||||
* @copyright 2024 Safat Shahin <safat.shahin@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
#[\core\attribute\label('Allows plugins or features to perform actions after a group is created.')]
|
||||
#[\core\attribute\tags('group')]
|
||||
class after_group_created {
|
||||
|
||||
/**
|
||||
* Constructor for the hook.
|
||||
*
|
||||
* @param stdClass $groupinstance The group instance.
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly stdClass $groupinstance,
|
||||
) {
|
||||
}
|
||||
}
|
41
group/classes/hook/after_group_deleted.php
Normal file
41
group/classes/hook/after_group_deleted.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
// 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/>.
|
||||
|
||||
namespace core_group\hook;
|
||||
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* Hook after group deletion.
|
||||
*
|
||||
* @package core_group
|
||||
* @copyright 2024 Safat Shahin <safat.shahin@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
#[\core\attribute\label('Allows plugins or features to perform actions after a group is deleted.')]
|
||||
#[\core\attribute\tags('group')]
|
||||
class after_group_deleted {
|
||||
|
||||
/**
|
||||
* Constructor for the hook.
|
||||
*
|
||||
* @param stdClass $groupinstance The group instance.
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly stdClass $groupinstance,
|
||||
) {
|
||||
}
|
||||
}
|
43
group/classes/hook/after_group_membership_added.php
Normal file
43
group/classes/hook/after_group_membership_added.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
// 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/>.
|
||||
|
||||
namespace core_group\hook;
|
||||
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* Hook after a member added to the group.
|
||||
*
|
||||
* @package core_group
|
||||
* @copyright 2023 Safat Shahin <safat.shahin@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
#[\core\attribute\label('Allows plugins or features to perform actions after members added to the group.')]
|
||||
#[\core\attribute\tags('group', 'user')]
|
||||
class after_group_membership_added {
|
||||
|
||||
/**
|
||||
* Constructor for the hook.
|
||||
*
|
||||
* @param stdClass $groupinstance The group instance.
|
||||
* @param array $userids The user ids.
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly stdClass $groupinstance,
|
||||
public readonly array $userids,
|
||||
) {
|
||||
}
|
||||
}
|
43
group/classes/hook/after_group_membership_removed.php
Normal file
43
group/classes/hook/after_group_membership_removed.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
// 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/>.
|
||||
|
||||
namespace core_group\hook;
|
||||
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* Hook after a member removed from the group.
|
||||
*
|
||||
* @package core_group
|
||||
* @copyright 2024 Safat Shahin <safat.shahin@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
#[\core\attribute\label('Allows plugins or features to perform actions after members removed from the group.')]
|
||||
#[\core\attribute\tags('group', 'user')]
|
||||
class after_group_membership_removed {
|
||||
|
||||
/**
|
||||
* Constructor for the hook.
|
||||
*
|
||||
* @param stdClass $groupinstance The group instance.
|
||||
* @param array $userids The user ids.
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly stdClass $groupinstance,
|
||||
public readonly array $userids,
|
||||
) {
|
||||
}
|
||||
}
|
41
group/classes/hook/after_group_updated.php
Normal file
41
group/classes/hook/after_group_updated.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
// 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/>.
|
||||
|
||||
namespace core_group\hook;
|
||||
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* Hook after group updates.
|
||||
*
|
||||
* @package core_group
|
||||
* @copyright 2023 Safat Shahin <safat.shahin@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
#[\core\attribute\label('Allows plugins or features to perform actions after a group is updated.')]
|
||||
#[\core\attribute\tags('group')]
|
||||
class after_group_updated {
|
||||
|
||||
/**
|
||||
* Constructor for the hook.
|
||||
*
|
||||
* @param stdClass $groupinstance The group instance.
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly stdClass $groupinstance,
|
||||
) {
|
||||
}
|
||||
}
|
@ -126,6 +126,13 @@ function groups_add_member($grouporid, $userorid, $component=null, $itemid=0) {
|
||||
$event->add_record_snapshot('groups', $group);
|
||||
$event->trigger();
|
||||
|
||||
// Dispatch the hook for a user added to the group.
|
||||
$hook = new \core_group\hook\after_group_membership_added(
|
||||
groupinstance: $group,
|
||||
userids: [$userid],
|
||||
);
|
||||
\core\di::get(\core\hook\manager::class)->dispatch($hook);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -232,6 +239,13 @@ function groups_remove_member($grouporid, $userorid) {
|
||||
$event->add_record_snapshot('groups', $group);
|
||||
$event->trigger();
|
||||
|
||||
// Dispatch the hook for a user removed from the group.
|
||||
$hook = new \core_group\hook\after_group_membership_removed(
|
||||
groupinstance: $group,
|
||||
userids: [$userid],
|
||||
);
|
||||
\core\di::get(\core\hook\manager::class)->dispatch($hook);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -323,6 +337,12 @@ function groups_create_group($data, $editform = false, $editoroptions = false) {
|
||||
$event->add_record_snapshot('groups', $group);
|
||||
$event->trigger();
|
||||
|
||||
// Dispatch the hook for post group creation actions.
|
||||
$hook = new \core_group\hook\after_group_created(
|
||||
groupinstance: $group,
|
||||
);
|
||||
\core\di::get(\core\hook\manager::class)->dispatch($hook);
|
||||
|
||||
return $group->id;
|
||||
}
|
||||
|
||||
@ -511,6 +531,12 @@ function groups_update_group($data, $editform = false, $editoroptions = false) {
|
||||
$event->add_record_snapshot('groups', $group);
|
||||
$event->trigger();
|
||||
|
||||
// Dispatch the hook for post group update actions.
|
||||
$hook = new \core_group\hook\after_group_updated(
|
||||
groupinstance: $group,
|
||||
);
|
||||
\core\di::get(\core\hook\manager::class)->dispatch($hook);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -616,6 +642,12 @@ function groups_delete_group($grouporid) {
|
||||
$event->add_record_snapshot('groups', $group);
|
||||
$event->trigger();
|
||||
|
||||
// Dispatch the hook for post group delete actions.
|
||||
$hook = new \core_group\hook\after_group_deleted(
|
||||
groupinstance: $group,
|
||||
);
|
||||
\core\di::get(\core\hook\manager::class)->dispatch($hook);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user