Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
add_to_group_node
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
4 / 4
4
100.00% covered (success)
100.00%
1 / 1
 type
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 params
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 branches
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 execute
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2// This file is part of Moodle - https://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle.  If not, see <https://www.gnu.org/licenses/>.
16
17namespace tool_autoflow\local\nodes;
18
19use tool_autoflow\local\engine\node_result;
20use tool_autoflow\local\engine\node_type;
21use tool_autoflow\local\engine\param;
22
23/**
24 * Adds a user who is enrolled in the course to one of its groups.
25 *
26 * It calls core_group_add_group_members, so the user the workflow runs as needs
27 * moodle/course:managegroups in the group's course.
28 *
29 * @package    tool_autoflow
30 * @copyright  2026 DevLMS <contact@devlms.com>
31 * @license    https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
32 */
33final class add_to_group_node implements node_type {
34    /**
35     * Type name.
36     *
37     * @return string
38     */
39    public function type(): string {
40        return 'moodle.add_to_group';
41    }
42
43    /**
44     * Parameters.
45     *
46     * @return param[]
47     */
48    public function params(): array {
49        return [new param('userid', 'user', true), new param('groupid', 'number', true)];
50    }
51
52    /**
53     * Branches.
54     *
55     * @return string[]
56     */
57    public function branches(): array {
58        return [];
59    }
60
61    /**
62     * Add the member.
63     *
64     * @param array $params userid, groupid
65     * @param array $context
66     * @return node_result userid and groupid.
67     */
68    public function execute(array $params, array $context): node_result {
69        $userid = node_values::id($params['userid'] ?? null, 'user id');
70        $groupid = node_values::id($params['groupid'] ?? null, 'group id');
71        call_function_node::call('core_group_add_group_members', ['members' => [['groupid' => $groupid, 'userid' => $userid]]]);
72        return new node_result(['userid' => $userid, 'groupid' => $groupid]);
73    }
74}