Skip to content

Commit

Permalink
check_reminders: use filter to exclude weekends
Browse files Browse the repository at this point in the history
increases readability
  • Loading branch information
glensc committed Sep 8, 2017
1 parent 363a423 commit 58cf9b8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
6 changes: 1 addition & 5 deletions lib/eventum/class.reminder.php
Original file line number Diff line number Diff line change
Expand Up @@ -775,11 +775,7 @@ public static function getList()
{{%reminder_level}}
ORDER BY
rem_rank ASC';
try {
$res = DB_Helper::getInstance()->getAll($stmt);
} catch (DatabaseException $e) {
return [];
}
$res = DB_Helper::getInstance()->getAll($stmt);

if (empty($res)) {
return [];
Expand Down
30 changes: 22 additions & 8 deletions src/Command/CheckRemindersCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,12 @@ private function checkReminders()
$triggered_issues = [];

$reminders = Reminder::getList();
$weekday = date('w');
foreach ($reminders as $reminder) {
// if this is the weekend and this reminder isn't supposed to run on weekends skip
if ($reminder['rem_skip_weekend'] == 1 && in_array($weekday, [0, 6])) {
$message = "Skipping Reminder '{$reminder['rem_title']}' due to weekend exclusion";
$this->debugMessage($message);

continue;
}
$reminders = array_filter($reminders, function ($reminder) {
return $this->filteroutWeekends($reminder);
});

foreach ($reminders as $reminder) {
// for each action, get the conditions and see if it triggered any issues
foreach ($reminder['actions'] as $action) {
$message = "Processing Reminder Action '{$action['rma_title']}'";
Expand Down Expand Up @@ -125,6 +121,24 @@ private function checkReminders()
}
}

/**
* if this is the weekend and this reminder isn't supposed to run on weekends skip
*/
private function filteroutWeekends($reminder)
{
$weekday = date('w');

// if this is the weekend and this reminder isn't supposed to run on weekends skip
if ($reminder['rem_skip_weekend'] == 1 && in_array($weekday, [0, 6])) {
$message = "Skipping Reminder '{$reminder['rem_title']}' due to weekend exclusion";
$this->debugMessage($message);

return false;
}

return true;
}

private function debugMessage($message)
{
$this->output->writeln($message, OutputInterface::VERBOSITY_DEBUG);
Expand Down

0 comments on commit 58cf9b8

Please sign in to comment.