public function getPromptEmailData(SiteModel $site, EventModel $lastEvent = null) { global $CONFIG; $moreEventsNeeded = false; $checkTime = \TimeSource::getDateTime(); if ($lastEvent) { $dateInterval = new \DateInterval("P" . $site->getPromptEmailsDaysInAdvance() . "D"); $endTimeMinusExtra = clone $lastEvent->getEndAt(); $endTimeMinusExtra->sub($dateInterval); if ($endTimeMinusExtra < $checkTime) { // there is a last event and it is before now plus whenever! // Now check; have we notified the user of this before? $dateSince = $this->getSinceDateForPromptChecking(); if ($endTimeMinusExtra > $dateSince) { // Finally check: has safe gap passed where we only send one email every X days? $safeGapDays = max($site->getPromptEmailsDaysInAdvance(), $CONFIG->userWatchesPromptEmailSafeGapDays); $nowMinusSafeGap = \TimeSource::getDateTime(); $nowMinusSafeGap->sub(new \DateInterval("P" . $safeGapDays . "D")); if ($dateSince < $nowMinusSafeGap) { // Finally we can agree to send an alert! $moreEventsNeeded = true; } } } } // TODO when add importing, need to double check this. return array('moreEventsNeeded' => $moreEventsNeeded, 'checkTime' => $checkTime); }