Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
1 / 1
trigger_node
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
5 / 5
8
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 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%
5 / 5
100.00% covered (success)
100.00%
1 / 1
4
 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%
1 / 1
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
17declare(strict_types=1);
18
19namespace tool_autoflow\local\engine\nodes;
20
21use tool_autoflow\local\engine\node_result;
22use tool_autoflow\local\engine\node_type;
23use tool_autoflow\local\engine\param;
24
25/**
26 * The start of a workflow. Its output is the trigger data, so {{nodes.<trigger id>.x}}
27 * and {{trigger.x}} read the same value.
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 trigger_node implements node_type {
34    /**
35     * Create a trigger node for one trigger type.
36     *
37     * @param string $type For example trigger.manual, trigger.schedule or trigger.event.
38     */
39    public function __construct(
40        /** @var string Type name. */
41        private readonly string $type,
42    ) {
43    }
44
45    /**
46     * Type name.
47     *
48     * @return string
49     */
50    public function type(): string {
51        return $this->type;
52    }
53
54    /**
55     * Parameters.
56     *
57     * @return param[]
58     */
59    public function params(): array {
60        return match ($this->type) {
61            'trigger.schedule' => [new param('cron', 'text', true)],
62            'trigger.event' => [new param('eventname', 'event', true)],
63            default => [],
64        };
65    }
66
67    /**
68     * Branches.
69     *
70     * @return string[]
71     */
72    public function branches(): array {
73        return [];
74    }
75
76    /**
77     * Pass the trigger data on.
78     *
79     * @param array $params
80     * @param array $context
81     * @return node_result
82     */
83    public function execute(array $params, array $context): node_result {
84        return new node_result($context['trigger']);
85    }
86}