Skip to content
Snippets Groups Projects
Unverified Commit 88e02203 authored by Justus Dieckmann's avatar Justus Dieckmann Committed by GitHub
Browse files

Merge pull request #151 from FelixDiLenarda/master

Refined 'specificdate'-trigger, so it works and triggers 'todays'-date. issue#147
parents 51dcf1fa 2120209d
No related branches found
No related tags found
No related merge requests found
......@@ -26,6 +26,6 @@ $string['pluginname'] = 'Bestimmtes Datum - Trigger';
$string['privacy:metadata'] = 'Dieses Subplugin speichert keine persönlichen Daten.';
$string['dates'] = 'Daten, an denen der Workflow ausgeführt werden soll.';
$string['dates_desc'] = 'Ein Datum pro Zeile in dem Format Tag.Monat';
$string['dates_help'] = 'Ein Datum pro Zeile in dem Format Tag.Monat<br><br>Zum Beispiel 04.08 für den 4. August. Wenn Sie das heutige Datum wählen, wird es getriggert.';
$string['timelastrun'] = 'Datum, an dem der Trigger zuletzt ausgeführt wurde.';
$string['dates_not_parseable'] = 'Daten müssen in dem Format Tag.Monat sein!';
......@@ -26,6 +26,6 @@ $string['pluginname'] = 'Specific date trigger';
$string['privacy:metadata'] = 'This subplugin does not store any personal data.';
$string['dates'] = 'Dates at which the workflow should run.';
$string['dates_desc'] = 'Write one date per line with the format Day.Month';
$string['dates_help'] = 'Write one date per line with the format Day.Month<br><br>For example 04.08 for 4th of august. If you put in today\'s date, it will be triggered.';
$string['timelastrun'] = 'Date when the trigger last run.';
$string['dates_not_parseable'] = 'Dates must be of the format Day.Month';
......@@ -64,40 +64,26 @@ class specificdate extends base_automatic {
*/
public function get_course_recordset_where($triggerid) {
$settings = settings_manager::get_settings($triggerid, settings_type::TRIGGER);
$lastrun = getdate($settings['timelastrun']);
$datesraw = $settings['dates'];
$dates = $this->parse_dates($datesraw);
$triggerat = array();
foreach ($dates as $dateparts) {
if ($dateparts['mon'] > $lastrun['mon']) {
$date = new DateTime($lastrun['year'].'-'.$dateparts['mon'].'-'.$dateparts['day']);
} else if ($dateparts['mon'] === $lastrun['mon']) {
if ($dateparts['day'] > $lastrun['day']) {
$date = new DateTime($lastrun['year'].'-'.$dateparts['mon'].'-'.$dateparts['day']);
} else {
$date = new DateTime(($lastrun['year'] + 1) .'-'.$dateparts['mon'].'-'.$dateparts['day']);
}
} else {
$date = new DateTime(($lastrun['year'] + 1) .'-'.$dateparts['mon'].'-'.$dateparts['day']);
}
$triggerat[] = $date->getTimestamp();
}
sort($triggerat);
$lastrun = getdate($settings['timelastrun']);
$current = time();
$today = getdate($current);
foreach ($triggerat as $timestamp) {
if ($timestamp < $current) {
foreach ($dates as $date) {
// We want to trigger only if the $date is today.
if ($date['mon'] == $today['mon'] && $date['day'] == $today['mday']) {
// Now only make sure if $lastrun was today -> don't trigger.
if ($lastrun['yday'] == $today['yday'] && $lastrun['year'] == $today['year']) {
continue;
} else {
$settings['timelastrun'] = $current;
$trigger = trigger_manager::get_instance($triggerid);
settings_manager::save_settings($triggerid, settings_type::TRIGGER, $trigger->subpluginname, $settings);
return array('true', array());
}
}
}
return array('false', array());
}
......@@ -149,11 +135,11 @@ class specificdate extends base_automatic {
* @throws \coding_exception
*/
public function extend_add_instance_form_definition($mform) {
$mform->addElement('textarea', 'dates', get_string('dates', 'lifecycletrigger_specificdate'),
get_string('dates_desc', 'lifecycletrigger_specificdate'));
$mform->addElement('textarea', 'dates', get_string('dates', 'lifecycletrigger_specificdate'));
$mform->setType('dates', PARAM_TEXT);
$mform->addHelpButton('dates', 'dates', 'lifecycletrigger_specificdate');
$mform->addElement('hidden', 'timelastrun');
$mform->setDefault('timelastrun', time());
$mform->setDefault('timelastrun', 0);
$mform->setType('timelastrun', PARAM_INT);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment