Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions trigger/enddate/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# moodle-lifecycletrigger_enddate

This subplugin adds a trigger for the tool lifecycle that depends on the course enddate.
40 changes: 40 additions & 0 deletions trigger/enddate/classes/privacy/provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?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 lifecycletrigger_enddate\privacy;

use core_privacy\local\metadata\null_provider;

/**
* Privacy subsystem implementation for lifecycletrigger_enddate.
*
* @package lifecycletrigger_enddate
* @copyright 2022 ISB Bayern
* @author Philipp Memmel
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements null_provider {

/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string the reason
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
}
31 changes: 31 additions & 0 deletions trigger/enddate/lang/de/lifecycletrigger_enddate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?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/>.

/**
* Lang strings for start date delay trigger
*
* @package lifecycletrigger_enddate
* @copyright 2025 Ostfalia
* @copyright 2017 Tobias Reischmann WWU
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

$string['delay'] = 'Zeit seit Kursendedatum, bis ein Prozess gestartet wird';
$string['delay_help'] = 'Dieser Trigger wird ausgeführt, sobald die Zeit, die seit dem Ende des Kurses vergangen ist, größer ist als der angegebene Zeitraum.';
$string['plugindescription'] = 'Trigger des Lifecycle-Tools, der bestimmt, wieviel Zeit nach dem Endedatum des Kurses verstreichen muss, ehe dieser Workflow startet.';
$string['pluginname'] = 'Endedatumsabstand - Trigger';
$string['privacy:metadata'] = 'Dieses Subplugin speichert keine persönlichen Daten.';

31 changes: 31 additions & 0 deletions trigger/enddate/lang/en/lifecycletrigger_enddate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?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/>.

/**
* Lang strings for start date delay trigger
*
* @package lifecycletrigger_enddate
* @copyright 2025 Ostfalia
* @copyright 2017 Tobias Reischmann WWU
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

$string['delay'] = 'Delay from end of course until starting a process';
$string['delay_help'] = 'The trigger will be invoked if the time passed since the course has ended is longer than this delay.';
$string['plugindescription'] = 'Defines the time that has to pass after the course end date has been reached before this workflow starts.';
$string['pluginname'] = 'End date trigger';
$string['privacy:metadata'] = 'This subplugin does not store any personal data.';

112 changes: 112 additions & 0 deletions trigger/enddate/lib.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?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/>.

/**
* Subplugin for the start date delay.
*
* @package lifecycletrigger_enddate
* @copyright 2025 Ostfalia
* @copyright 2017 Tobias Reischmann WWU
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lifecycle\trigger;

use tool_lifecycle\local\manager\settings_manager;
use tool_lifecycle\local\response\trigger_response;
use tool_lifecycle\settings_type;

defined('MOODLE_INTERNAL') || die();
require_once(__DIR__ . '/../lib.php');
require_once(__DIR__ . '/../../lib.php');

/**
* Class which implements the basic methods necessary for a cleanyp courses trigger subplugin
*
* @package lifecycletrigger_enddate
* @copyright 2025 Ostfalia
* @copyright 2017 Tobias Reischmann WWU
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class enddate extends base_automatic {

/**
* If check_course_code() returns true, code to check the given course is placed here
* @param object $course
* @param int $triggerid
* @return trigger_response
*/
public function check_course($course, $triggerid) {
return trigger_response::trigger();
}

/**
* Add sql comparing the current date to the start date of a course in combination with the specified delay.
* @param int $triggerid Id of the trigger.
* @return array A list containing the constructed sql fragment and an array of parameters.
* @throws \coding_exception
* @throws \dml_exception
*/
public function get_course_recordset_where($triggerid) {
$delay = settings_manager::get_settings($triggerid, settings_type::TRIGGER)['delay'];
$where = "c.enddate > 0 AND c.enddate < :enddatedelay";
$params = [
"enddatedelay" => time() - $delay,
];
return [$where, $params];
}

/**
* The return value should be equivalent with the name of the subplugin folder.
* @return string technical name of the subplugin
*/
public function get_subpluginname() {
return 'enddate';
}

/**
* Defines which settings each instance of the subplugin offers for the user to define.
* @return instance_setting[] containing settings keys and PARAM_TYPES
*/
public function instance_settings() {
return [
new instance_setting('delay', PARAM_INT, true),
];
}

/**
* At the delay since the start date of a course.
* @param \MoodleQuickForm $mform
* @throws \coding_exception
*/
public function extend_add_instance_form_definition($mform) {
$mform->addElement('duration', 'delay', get_string('delay', 'lifecycletrigger_enddate'));
$mform->addHelpButton('delay', 'delay', 'lifecycletrigger_enddate');
}

/**
* Reset the delay at the add instance form initializiation.
* @param \MoodleQuickForm $mform
* @param array $settings array containing the settings from the db.
*/
public function extend_add_instance_form_definition_after_data($mform, $settings) {
if (is_array($settings) && array_key_exists('delay', $settings)) {
$default = $settings['delay'];
} else {
$default = 24 * 60 * 60; // One day.
}
$mform->setDefault('delay', $default);
}
}
71 changes: 71 additions & 0 deletions trigger/enddate/tests/generator/lib.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?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/>.

/**
* lifecycletrigger_enddate generator tests
*
* @package lifecycletrigger_enddate
* @category test
* @copyright 2025 Ostfalia
* @copyright 2018 Tobias Reischmann WWU
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

use tool_lifecycle\local\entity\trigger_subplugin;
use tool_lifecycle\local\entity\workflow;
use tool_lifecycle\local\manager\settings_manager;
use tool_lifecycle\local\manager\trigger_manager;
use tool_lifecycle\local\manager\workflow_manager;
use tool_lifecycle\settings_type;

/**
* lifecycletrigger_enddate generator tests
*
* @package lifecycletrigger_enddate
* @category test
* @copyright 2025 Ostfalia
* @copyright 2018 Tobias Reischmann WWU
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tool_lifecycle_trigger_enddate_generator extends testing_module_generator {

/**
* Creates a trigger enddatedelay for an artificial workflow without steps.
* @return trigger_subplugin the created enddatedelay trigger.
* @throws moodle_exception
*/
public static function create_trigger_with_workflow() {
// Create Workflow.
$record = new stdClass();
$record->id = null;
$record->title = 'myworkflow';
$workflow = workflow::from_record($record);
workflow_manager::insert_or_update($workflow);
// Create trigger.
$record = new stdClass();
$record->subpluginname = 'enddate';
$record->instancename = 'enddate';
$record->workflowid = $workflow->id;
$trigger = trigger_subplugin::from_record($record);
trigger_manager::insert_or_update($trigger);
// Set delay setting.
$settings = new stdClass();
$settings->delay = 10 * DAYSECS; // Trigger when 10 days have passed.
settings_manager::save_settings($trigger->id, settings_type::TRIGGER, $trigger->subpluginname, $settings);

return $trigger;
}
}
Loading