protected function run() { $siteRepoBuilder = new SiteRepositoryBuilder(); $siteRepoBuilder->setIsOpenBySysAdminsOnly(true); $countCheck = 0; $countSend = 0; foreach ($siteRepoBuilder->fetchAll() as $site) { $this->logVerbose("Site " . $site->getSlug()); $userRepoBuilder = new UserAccountRepositoryBuilder(); $userRepoBuilder->setIsOpenBySysAdminsOnly(true); foreach ($userRepoBuilder->fetchAll() as $userAccount) { $this->logVerbose("User " . $userAccount->getId()); ++$countCheck; $checkTime = \TimeSource::getDateTime(); $contentsToSend = array(); foreach ($this->app['extensions']->getExtensionsIncludingCore() as $extension) { $contentsToSend = array_merge($contentsToSend, $extension->getUserNotifyContents($site, $userAccount)); } if ($contentsToSend) { $this->logVerbose("Found contents!"); ++$countSend; $this->makeSureHistoriesAreCorrect($contentsToSend); $this->sendFor($site, $userAccount, $contentsToSend); foreach ($contentsToSend as $contentToSend) { $contentToSend->markNotificationSent($checkTime); } } else { $this->logVerbose("found nothing"); } } } return array('result' => 'ok', 'countCheck' => $countCheck, 'countSend' => $countSend); }
function __construct(BaseValueReport $report, \DateTime $start, $end = null, $timeperiod = "P1M") { $this->end = $end ? $end : \TimeSource::getDateTime(); $this->report = $report; $this->start = $start; $this->timeperiod = $timeperiod; }
public function build() { // We only want events in X days before now and onwards $time = \TimeSource::getDateTime(); $time->add(new \DateInterval("P" . $this->daysBefore . "D")); $this->eventRepositoryBuilder->setBefore($time); parent::build(); }
public function hasRunToday() { $start = \TimeSource::getDateTime(); $start->setTime(0, 0, 0); $stat = $this->app['db']->prepare("SELECT ended_at FROM task_log " . "WHERE extension_id=:extension_id AND task_id=:task_id AND started_at > :started_at " . "ORDER BY ended_at DESC LIMIT 1"); $stat->execute(array('extension_id' => $this->getExtensionId(), 'task_id' => $this->getTaskId(), 'started_at' => $start->format("Y-m-d H:i:s"))); return $stat->rowCount() > 0; }
public function __construct(SiteModel $site = null, $timeZone = null, $title = null) { parent::__construct($site, $timeZone, $title); // We go back a month, just so calendars have a bit of the past available. $time = \TimeSource::getDateTime(); $time->sub(new \DateInterval("P30D")); $this->eventRepositoryBuilder->setAfter($time); }
function calendarNow(Application $app) { $cal = new \RenderCalendar(); $cal->getEventRepositoryBuilder()->setSite($app['currentSite']); $cal->getEventRepositoryBuilder()->setIncludeDeleted(false); if ($app['currentUser']) { $cal->getEventRepositoryBuilder()->setUserAccount($app['currentUser'], true); } $cal->byDate(\TimeSource::getDateTime(), 31, true); list($prevYear, $prevMonth, $nextYear, $nextMonth) = $cal->getPrevNextLinksByMonth(); return $app['twig']->render('/site/calendarPage.html.twig', array('calendar' => $cal, 'prevYear' => $prevYear, 'prevMonth' => $prevMonth, 'nextYear' => $nextYear, 'nextMonth' => $nextMonth, 'pageTitle' => 'Calendar', 'showCurrentUserOptions' => true)); }
/** * * @return \models\UserAccountResetModel A single one or NULL. Technically it may load multiple ones, but we only return one. */ public function loadRecentlyUnusedSentForUserAccountId($id, $seconds = 60) { global $DB; $stat = $DB->prepare("SELECT user_account_reset.* FROM user_account_reset WHERE reset_at IS NULL AND user_account_id =:user_account_id AND created_at > :since"); $time = \TimeSource::getDateTime(); $time->setTimestamp($time->getTimestamp() - $seconds); $stat->execute(array('user_account_id' => $id, 'since' => $time->format('Y-m-d H:i:s'))); if ($stat->rowCount() > 0) { $uar = new UserAccountResetModel(); $uar->setFromDataBaseRow($stat->fetch()); return $uar; } }
function calendarNow(Request $request, Application $app) { $this->parameters['calendar'] = new \RenderCalendar(); $this->parameters['calendar']->getEventRepositoryBuilder()->setSite($app['currentSite']); $this->parameters['calendar']->getEventRepositoryBuilder()->setVenueVirtualOnly(true); $this->parameters['calendar']->getEventRepositoryBuilder()->setIncludeDeleted(false); if ($app['currentUser']) { $this->parameters['calendar']->getEventRepositoryBuilder()->setUserAccount($app['currentUser'], true); $this->parameters['showCurrentUserOptions'] = true; } $this->parameters['calendar']->byDate(\TimeSource::getDateTime(), 31, true); list($this->parameters['prevYear'], $this->parameters['prevMonth'], $this->parameters['nextYear'], $this->parameters['nextMonth']) = $this->parameters['calendar']->getPrevNextLinksByMonth(); $this->parameters['pageTitle'] = "Virtual"; $this->parameters['venueVirtual'] = true; return $app['twig']->render('/site/calendarPage.html.twig', $this->parameters); }
function calendarNow($slug, Request $request, Application $app) { if (!$this->build($slug, $request, $app)) { $app->abort(404, "Country does not exist."); } $this->parameters['calendar'] = new \RenderCalendar(); $this->parameters['calendar']->getEventRepositoryBuilder()->setSite($app['currentSite']); $this->parameters['calendar']->getEventRepositoryBuilder()->setCountry($this->parameters['country']); $this->parameters['calendar']->getEventRepositoryBuilder()->setIncludeDeleted(false); if ($app['currentUser']) { $this->parameters['calendar']->getEventRepositoryBuilder()->setUserAccount($app['currentUser'], true); $this->parameters['showCurrentUserOptions'] = true; } $this->parameters['calendar']->byDate(\TimeSource::getDateTime(), 31, true); list($this->parameters['prevYear'], $this->parameters['prevMonth'], $this->parameters['nextYear'], $this->parameters['nextMonth']) = $this->parameters['calendar']->getPrevNextLinksByMonth(); $this->parameters['pageTitle'] = $this->parameters['country']->getTitle(); return $app['twig']->render('/site/calendarPage.html.twig', $this->parameters); }
function onThisStepProcessPage() { if ($this->getCurrentMode() == $this->MODE_FREE) { if ($this->request->request->get('action') == 'startAndEndFreeText') { $this->draftEvent->setDetailsValue('event.start_end_freetext.start', \TimeSource::getDateTime()); $this->draftEvent->setDetailsValue('event.start_end_freetext.end', \TimeSource::getDateTime()); if ($this->request->request->get('startAndEndFreeText')) { $parse = new ParseDateTimeRangeString(\TimeSource::getDateTime(), $this->application['currentTimeZone']); $parseResult = $parse->parse($this->request->request->get('startAndEndFreeText')); if ($parseResult->getStart()) { $this->draftEvent->setDetailsValue('event.start_end_freetext.start', $parseResult->getStart()); // If no end is returned, just set start as sensible default $this->draftEvent->setDetailsValue('event.start_end_freetext.end', $parseResult->getEnd() ? $parseResult->getEnd() : $parseResult->getStart()); } } $this->draftEvent->setDetailsValue('event.start_end_freetext.text', $this->request->request->get('startAndEndFreeText')); $this->draftEvent->setDetailsValue('event.start_end_freetext.done', 'yes'); return true; } } else { if ('POST' == $this->request->getMethod()) { $this->form->bind($this->request); // Store these on object for JS $this->currentStart = $this->form->get('start_at')->getData(); $this->currentEnd = $this->form->get('end_at')->getData(); $this->currentTimeZone = $this->form->get('timezone')->getData(); if ($this->form->isValid()) { $this->draftEvent->setDetailsValue('event.start_at', $this->form->get('start_at')->getData()); $this->draftEvent->setDetailsValue('event.end_at', $this->form->get('end_at')->getData()); $this->draftEvent->setDetailsValue('event.country_id', $this->form->get('country_id')->getData()); $this->draftEvent->setDetailsValue('event.timezone', $this->form->get('timezone')->getData()); $this->isAllInformationGathered = true; return true; } } } return false; }
public function buildEvents(Application $app) { global $CONFIG; $repo = new SiteRepository(); $site = $repo->loadById($this->site_id); $start = \TimeSource::getDateTime(); $end = \TimeSource::getDateTime(); $end->add(new \DateInterval("P" . ($this->days_into_future + 1) . "D")); $calendar = new \RenderCalendar(); $calendar->setStartAndEnd($start, $end); $calendar->getEventRepositoryBuilder()->setSite($site); $calendar->getEventRepositoryBuilder()->setIncludeDeleted(true); $calData = $calendar->getData(); $this->events = $calendar->getEvents(); $this->event_text = $app['twig']->render('email/sendemail.eventview.calendar.txt.twig', array('data' => $calData, 'currentSite' => $site)); if ($CONFIG->isDebug) { file_put_contents('/tmp/sendemail.eventview.calendar.txt', $this->event_text); } $this->event_html = $app['twig']->render('email/sendemail.eventview.calendar.html.twig', array('data' => $calData, 'currentSite' => $site)); if ($CONFIG->isDebug) { file_put_contents('/tmp/sendemail.eventview.calendar.html', $this->event_html); } }
public function buildForm(FormBuilderInterface $builder, array $options) { $crb = new CountryRepositoryBuilder(); $crb->setSiteIn($this->site); $this->defaultCountry = null; $defaultCountryID = null; $countries = $crb->fetchAll(); if (count($countries) > 1) { $countriesForSelect = array(); foreach ($countries as $country) { $countriesForSelect[$country->getId()] = $country->getTitle(); if ($this->defaultCountry == null && in_array($this->timeZoneName, $country->getTimezonesAsList())) { $this->defaultCountry = $country; $defaultCountryID = $country->getId(); } } $builder->add('country_id', 'choice', array('label' => 'Country', 'choices' => $countriesForSelect, 'required' => true, 'data' => $defaultCountryID)); } else { if (count($countries) == 1) { $this->defaultCountry = $countries[0]; $builder->add('country_id', 'hidden', array('data' => $this->defaultCountry->getId())); } } $timezones = array(); // Must explicetly set name as key otherwise Symfony forms puts an ID in, and that's no good for processing outside form foreach ($this->site->getCachedTimezonesAsList() as $timezone) { $timezones[$timezone] = $timezone; } if (count($timezones) != 1) { $builder->add('timezone', 'choice', array('label' => 'Time Zone', 'choices' => $timezones, 'required' => true)); } else { $timezone = array_pop($timezones); $builder->add('timezone', 'hidden', array('data' => $timezone)); } $years = array(date('Y'), date('Y') + 1); $data = null; if ($this->eventDraft->hasDetailsValue('event.start_at')) { $data = $this->eventDraft->getDetailsValueAsDateTime('event.start_at'); } else { if ($this->eventDraft->hasDetailsValue('event.start_end_freetext.start')) { $data = $this->eventDraft->getDetailsValueAsDateTime('event.start_end_freetext.start'); } else { if ($this->eventDraft->hasDetailsValue('incoming.event.start_at')) { $data = $this->eventDraft->getDetailsValueAsDateTime('incoming.event.start_at'); } } } $startOptions = array('label' => 'Start', 'date_widget' => 'single_text', 'date_format' => 'd/M/y', 'model_timezone' => 'UTC', 'view_timezone' => $this->timeZoneName, 'years' => $years, 'attr' => array('class' => 'dateInput'), 'required' => true, 'data' => $data); if ($this->formWidgetTimeMinutesMultiples > 1) { $startOptions['minutes'] = array(); for ($i = 0; $i <= 59; $i = $i + $this->formWidgetTimeMinutesMultiples) { $startOptions['minutes'][] = $i; } } $builder->add('start_at', 'datetime', $startOptions); $data = null; if ($this->eventDraft->hasDetailsValue('event.end_at')) { $data = $this->eventDraft->getDetailsValueAsDateTime('event.end_at'); } else { if ($this->eventDraft->hasDetailsValue('event.start_end_freetext.end')) { $data = $this->eventDraft->getDetailsValueAsDateTime('event.start_end_freetext.end'); } else { if ($this->eventDraft->hasDetailsValue('incoming.event.end_at')) { $data = $this->eventDraft->getDetailsValueAsDateTime('incoming.event.end_at'); } } } $endOptions = array('label' => 'End', 'date_widget' => 'single_text', 'date_format' => 'd/M/y', 'model_timezone' => 'UTC', 'view_timezone' => $this->timeZoneName, 'years' => $years, 'attr' => array('class' => 'dateInput'), 'required' => true, 'data' => $data); if ($this->formWidgetTimeMinutesMultiples > 1) { $endOptions['minutes'] = array(); for ($i = 0; $i <= 59; $i = $i + $this->formWidgetTimeMinutesMultiples) { $endOptions['minutes'][] = $i; } } $builder->add('end_at', 'datetime', $endOptions); /** @var \closure $myExtraFieldValidator **/ $myExtraFieldValidator = function (FormEvent $event) { global $CONFIG; $form = $event->getForm(); $myExtraFieldStart = $form->get('start_at')->getData(); $myExtraFieldEnd = $form->get('end_at')->getData(); // Validate end is after start? if ($myExtraFieldStart > $myExtraFieldEnd) { $form['start_at']->addError(new FormError("The start can not be after the end!")); } // validate not to far in future $max = \TimeSource::getDateTime(); $max->add(new \DateInterval("P" . $CONFIG->eventsCantBeMoreThanYearsInFuture . "Y")); if ($myExtraFieldStart > $max) { $form['start_at']->addError(new FormError("The event can not be more than " . ($CONFIG->eventsCantBeMoreThanYearsInFuture > 1 ? $CONFIG->eventsCantBeMoreThanYearsInFuture . " years" : "a year") . " in the future.")); } if ($myExtraFieldEnd > $max) { $form['end_at']->addError(new FormError("The event can not be more than " . ($CONFIG->eventsCantBeMoreThanYearsInFuture > 1 ? $CONFIG->eventsCantBeMoreThanYearsInFuture . " years" : "a year") . " in the future.")); } // validate not to far in past $min = \TimeSource::getDateTime(); $min->sub(new \DateInterval("P" . $CONFIG->eventsCantBeMoreThanYearsInPast . "Y")); if ($myExtraFieldStart < $min) { $form['start_at']->addError(new FormError("The event can not be more than " . ($CONFIG->eventsCantBeMoreThanYearsInPast > 1 ? $CONFIG->eventsCantBeMoreThanYearsInPast . " years" : "a year") . " in the past.")); } if ($myExtraFieldEnd < $min) { $form['end_at']->addError(new FormError("The event can not be more than " . ($CONFIG->eventsCantBeMoreThanYearsInPast > 1 ? $CONFIG->eventsCantBeMoreThanYearsInPast . " years" : "a year") . " in the past.")); } }; // adding the validator to the FormBuilderInterface $builder->addEventListener(FormEvents::POST_BIND, $myExtraFieldValidator); }
function calendarNow(Application $app) { $cal = new \RenderCalendar(); $params = new EventFilterParams($cal->getEventRepositoryBuilder()); $params->setHasDateControls(false); $params->setSpecifiedUserControls(true, $app['currentUser'], true); $params->set($_GET); $cal->byDate(\TimeSource::getDateTime(), 31, true); list($prevYear, $prevMonth, $nextYear, $nextMonth) = $cal->getPrevNextLinksByMonth(); return $app['twig']->render('/index/currentuser/calendar.html.twig', array('calendar' => $cal, 'eventListFilterParams' => $params, 'prevYear' => $prevYear, 'prevMonth' => $prevMonth, 'nextYear' => $nextYear, 'nextMonth' => $nextMonth, 'showCurrentUserOptions' => true)); }
public function setAfterNow() { $this->after = \TimeSource::getDateTime(); return $this; }
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); }
public function setBeforeNow() { $this->endBefore = \TimeSource::getDateTime(); return $this; }
public function expire(ImportURLModel $importURL) { global $DB; try { $DB->beginTransaction(); $importURL->setExpiredAt(\TimeSource::getDateTime()); $importURLEditMetaData = new ImportURLEditMetaDataModel(); $importURLEditMetaData->setUserAccount(null); $this->importURLDBAccess->update($importURL, array('expired_at'), $importURLEditMetaData); $DB->commit(); } catch (Exception $e) { $DB->rollBack(); } }
public static function run(Application $app, $verbose = false) { global $CONFIG; if ($verbose) { print "Starting " . date("c") . "\n"; } $siteRepo = new SiteRepository(); $groupRepo = new GroupRepository(); $importURLRepo = new ImportURLRepository(); $userRepo = new UserAccountRepository(); $userWatchesSiteStopRepository = new UserWatchesSiteStopRepository(); $userWatchesGroupStopRepository = new UserWatchesGroupStopRepository(); $userAccountGeneralSecurityKeyRepository = new UserAccountGeneralSecurityKeyRepository(); $userNotificationRepo = new UserNotificationRepository(); /** @var usernotifications/UpcomingEventsUserNotificationType **/ $userNotificationType = $app['extensions']->getCoreExtension()->getUserNotificationType('ImportURLExpired'); $iurlBuilder = new ImportURLRepositoryBuilder(); foreach ($iurlBuilder->fetchAll() as $importURL) { $site = $siteRepo->loadById($importURL->getSiteID()); $group = $groupRepo->loadById($importURL->getGroupId()); if ($verbose) { print date("c") . " ImportURL " . $importURL->getId() . " " . $importURL->getTitle() . " Site " . $site->getTitle() . "\n"; } if ($site->getIsClosedBySysAdmin()) { if ($verbose) { print " - site closed by sys admin\n"; } } else { if (!$site->getIsFeatureImporter()) { if ($verbose) { print " - site feature disabled\n"; } } else { if (!$group) { if ($verbose) { print " - no group - this should be impossible\n"; } } else { if ($group->getIsDeleted()) { if ($verbose) { print " - group deleted\n"; } } else { if ($importURL->getExpiredAt()) { if ($verbose) { print " - expired\n"; } } else { if (!$importURL->getIsEnabled()) { if ($verbose) { print " - not enabled\n"; } } else { if ($importURL->isShouldExpireNow()) { if ($verbose) { print " - expiring\n"; } $importURLRepo->expire($importURL); configureAppForSite($site); $uwsb = new UserWatchesSiteRepositoryBuilder(); $uwsb->setSite($site); foreach ($uwsb->fetchAll() as $userWatchesSite) { $user = $userRepo->loadByID($userWatchesSite->getUserAccountId()); if ($userWatchesSite->getIsWatching()) { /// Notification Class $userNotification = $userNotificationType->getNewNotification($user, $site); $userNotification->setImportURL($importURL); $userNotification->setGroup($group); ////// Save Notification Class $userNotificationRepo->create($userNotification); ////// Send Email if ($userNotification->getIsEmail()) { configureAppForUser($user); $userAccountGeneralSecurityKey = $userAccountGeneralSecurityKeyRepository->getForUser($user); $userWatchesSiteStop = $userWatchesSiteStopRepository->getForUserAndSite($user, $site); $message = \Swift_Message::newInstance(); $message->setSubject("Please confirm this is still valid: " . $importURL->getTitle()); $message->setFrom(array($CONFIG->emailFrom => $CONFIG->emailFromName)); $message->setTo($user->getEmail()); $messageText = $app['twig']->render('email/importURLExpired.watchesSite.txt.twig', array('user' => $user, 'importurl' => $importURL, 'stopCode' => $userWatchesSiteStop->getAccessKey(), 'generalSecurityCode' => $userAccountGeneralSecurityKey->getAccessKey())); if ($CONFIG->isDebug) { file_put_contents('/tmp/importURLExpired.watchesSite.txt', $messageText); } $message->setBody($messageText); $messageHTML = $app['twig']->render('email/importURLExpired.watchesSite.html.twig', array('user' => $user, 'importurl' => $importURL, 'stopCode' => $userWatchesSiteStop->getAccessKey(), 'generalSecurityCode' => $userAccountGeneralSecurityKey->getAccessKey())); if ($CONFIG->isDebug) { file_put_contents('/tmp/importURLExpired.watchesSite.html', $messageHTML); } $message->addPart($messageHTML, 'text/html'); if (!$CONFIG->isDebug) { $app['mailer']->send($message); } $userNotificationRepo->markEmailed($userNotification); } } } $uwgb = new UserWatchesGroupRepositoryBuilder(); $uwgb->setGroup($group); foreach ($uwgb->fetchAll() as $userWatchesGroup) { $user = $userRepo->loadByID($userWatchesGroup->getUserAccountId()); if ($userWatchesGroup->getIsWatching()) { /// Notification Class $userNotification = $userNotificationType->getNewNotification($user, $site); $userNotification->setImportURL($importURL); $userNotification->setGroup($group); ////// Save Notification Class $userNotificationRepo->create($userNotification); ////// Send Email if ($userNotification->getIsEmail()) { $userAccountGeneralSecurityKey = $userAccountGeneralSecurityKeyRepository->getForUser($user); $userWatchesGroupStop = $userWatchesGroupStopRepository->getForUserAndGroup($user, $group); $message = \Swift_Message::newInstance(); $message->setSubject("Please confirm this is still valid: " . $importURL->getTitle()); $message->setFrom(array($CONFIG->emailFrom => $CONFIG->emailFromName)); $message->setTo($user->getEmail()); $messageText = $app['twig']->render('email/importURLExpired.watchesGroup.txt.twig', array('user' => $user, 'importurl' => $importURL, 'stopCode' => $userWatchesGroupStop->getAccessKey(), 'generalSecurityCode' => $userAccountGeneralSecurityKey->getAccessKey(), 'group' => $group)); if ($CONFIG->isDebug) { file_put_contents('/tmp/importURLExpired.watchesGroup.txt', $messageText); } $message->setBody($messageText); $messageHTML = $app['twig']->render('email/importURLExpired.watchesGroup.html.twig', array('user' => $user, 'importurl' => $importURL, 'stopCode' => $userWatchesGroupStop->getAccessKey(), 'generalSecurityCode' => $userAccountGeneralSecurityKey->getAccessKey(), 'group' => $group)); if ($CONFIG->isDebug) { file_put_contents('/tmp/importURLExpired.watchesGroup.html', $messageHTML); } $message->addPart($messageHTML, 'text/html'); if (!$CONFIG->isDebug) { $app['mailer']->send($message); } $userNotificationRepo->markEmailed($userNotification); } } } } else { $lastRunDate = $importURLRepo->getLastRunDateForImportURL($importURL); $nowDate = \TimeSource::getDateTime(); if (!$lastRunDate || $lastRunDate->getTimestamp() < $nowDate->getTimestamp() - $CONFIG->importURLSecondsBetweenImports) { if ($verbose) { print " - importing\n"; } $runner = new ImportURLRunner(); $runner->go($importURL); } else { if ($verbose) { print " - already done on " . $lastRunDate->format("c") . "\n"; } } } } } } } } } } if ($verbose) { print "Finished " . date("c") . "\n"; } }
/** * One event, 31 days from now, then 30 days, then 29 days, etc, only 1 email sent * @global type $CONFIG */ function test6() { global $CONFIG; $CONFIG->userWatchesPromptEmailSafeGapDays = 30; \TimeSource::mock(2013, 1, 1, 0, 0, 0); $user = new UserAccountModel(); $user->setEmail("*****@*****.**"); $user->setUsername("test"); $user->setPassword("password"); $userRepo = new UserAccountRepository(); $userRepo->create($user); $site = new SiteModel(); $site->setTitle("Test"); $site->setSlug("test"); $siteRepo = new SiteRepository(); $siteRepo->create($site, $user, array(), $this->getSiteQuotaUsedForTesting()); $group = new GroupModel(); $group->setTitle("Group"); $groupRepo = new GroupRepository(); $groupRepo->create($group, $site, $user); $event = new EventModel(); $start = \TimeSource::getDateTime(); $start->setDate(2013, 30, 9); $start->setTime(9, 0, 0); $event->setStartAt($start); $end = \TimeSource::getDateTime(); $end->setDate(2013, 30, 9); $end->setTime(12, 0, 0); $event->setEndAt($end); $eventRepo = new EventRepository(); $eventRepo->create($event, $site, $user, $group); // User will watch site automatically in site->create() // We don't want that, we want the group instead $userWatchesSiteRepo = new UserWatchesSiteRepository(); $userWatchesSiteRepo->stopUserWatchingSite($user, $site); $userWatchesGroupRepo = new UserWatchesGroupRepository(); $userWatchesGroupRepo->startUserWatchingGroup($user, $group); #Before email sent! for ($day = 1; $day <= 29; $day++) { \TimeSource::mock(2013, $day, 8, 1, 0, 0); $userWatchesGroup = $userWatchesGroupRepo->loadByUserAndGroup($user, $group); $data = $userWatchesGroup->getPromptEmailData($site, $eventRepo->loadLastNonDeletedNonImportedByStartTimeInGroupId($group->getId())); $this->assertFalse($data['moreEventsNeeded']); } #Email sent! \TimeSource::mock(2013, 30, 8, 1, 0, 0); $userWatchesGroup = $userWatchesGroupRepo->loadByUserAndGroup($user, $group); $data = $userWatchesGroup->getPromptEmailData($site, $eventRepo->loadLastNonDeletedNonImportedByStartTimeInGroupId($group->getId())); $this->assertTrue($data['moreEventsNeeded']); $userWatchesGroupRepo->markPromptEmailSent($userWatchesGroup, \TimeSource::getDateTime()); #After email sent \TimeSource::mock(2013, 31, 8, 1, 0, 0); $userWatchesGroup = $userWatchesGroupRepo->loadByUserAndGroup($user, $group); $data = $userWatchesGroup->getPromptEmailData($site, $eventRepo->loadLastNonDeletedNonImportedByStartTimeInGroupId($group->getId())); $this->assertFalse($data['moreEventsNeeded']); for ($day = 1; $day <= 30; $day++) { \TimeSource::mock(2013, $day, 9, 1, 0, 0); $userWatchesGroup = $userWatchesGroupRepo->loadByUserAndGroup($user, $group); $data = $userWatchesGroup->getPromptEmailData($site, $eventRepo->loadLastNonDeletedNonImportedByStartTimeInGroupId($group->getId())); $this->assertFalse($data['moreEventsNeeded']); } for ($day = 1; $day <= 31; $day++) { \TimeSource::mock(2013, $day, 10, 1, 0, 0); $userWatchesGroup = $userWatchesGroupRepo->loadByUserAndGroup($user, $group); $data = $userWatchesGroup->getPromptEmailData($site, $eventRepo->loadLastNonDeletedNonImportedByStartTimeInGroupId($group->getId())); $this->assertFalse($data['moreEventsNeeded']); } for ($day = 1; $day <= 30; $day++) { \TimeSource::mock(2013, $day, 11, 1, 0, 0); $userWatchesGroup = $userWatchesGroupRepo->loadByUserAndGroup($user, $group); $data = $userWatchesGroup->getPromptEmailData($site, $eventRepo->loadLastNonDeletedNonImportedByStartTimeInGroupId($group->getId())); $this->assertFalse($data['moreEventsNeeded']); } for ($day = 1; $day <= 31; $day++) { \TimeSource::mock(2013, $day, 12, 1, 0, 0); $userWatchesGroup = $userWatchesGroupRepo->loadByUserAndGroup($user, $group); $data = $userWatchesGroup->getPromptEmailData($site, $eventRepo->loadLastNonDeletedNonImportedByStartTimeInGroupId($group->getId())); $this->assertFalse($data['moreEventsNeeded']); } }
function newEventDraft($draftslug, $stepid, Request $request, Application $app) { if (!$this->buildDraft($draftslug, $request, $app)) { return $app->abort(404); } $redirectToStep = $this->buildSteps($stepid, $request, $app); if ($redirectToStep) { return $app->redirect("/event/new/" . $this->parameters['draft']->getSlug() . "/" . $redirectToStep); } if ($this->parameters['currentStep']->getStepID() == 'preview') { if ($request->request->get('action') == 'CREATE' && $request->request->get('CSFRToken') == $app['websession']->getCSFRToken()) { //////////////////////////////////////// Actually Create Event $event = new EventModel(); $event->setSiteId($app['currentSite']->getId()); foreach ($this->parameters['steps'] as $step) { $step->addDataToEventBeforeSave($event); } $eventEditMetaData = new EventEditMetaDataModel(); $eventEditMetaData->setUserAccount($app['currentUser']); $eventEditMetaData->setCreatedFromNewEventDraftID($this->parameters['draft']->getId()); if ($request->request->get('edit_comment')) { $eventEditMetaData->setEditComment($request->request->get('edit_comment')); } $repo = new EventRepository(); $repo->createWithMetaData($event, $app['currentSite'], $eventEditMetaData); if ($app['config']->logFileParseDateTimeRange && $this->parameters['draft']->hasDetailsValue('event.start_end_freetext.done') == 'yes') { $parseStart = $this->parameters['draft']->getDetailsValueAsDateTime('event.start_end_freetext.start'); $parseEnd = $this->parameters['draft']->getDetailsValueAsDateTime('event.start_end_freetext.end'); $success = $parseStart->getTimestamp() == $event->getStartAt()->getTimestamp() && $parseEnd->getTimestamp() == $event->getEndAt()->getTimestamp(); $handle = fopen($app['config']->logFileParseDateTimeRange, "a"); $now = \TimeSource::getDateTime(); fputcsv($handle, array('Site', $app['currentSite']->getId(), $app['currentSite']->getSlug(), 'Event', $event->getSlug(), 'Now', $now->format("c"), 'Wanted Timezone', $event->getTimezone(), 'Wanted Start UTC', $event->getStartAtInUTC()->format("c"), 'Wanted End UTC', $event->getEndAtInUTC()->format("c"), 'Typed', $this->parameters['draft']->getDetailsValue('event.start_end_freetext.text'), 'Got Start UTC', $parseStart->format("c"), 'Got End UTC', $parseEnd->format("c"), $success ? 'SUCCESS' : 'FAIL')); fclose($handle); } $app['flashmessages']->addMessage("Thanks! The event has been created."); return $app->redirect('/event/' . $event->getSlugForUrl()); } else { //////////////////////////////////////// Show Final Preview Screen $this->parameters['stepsUI'] = (new StepsUI($this->parameters['steps'], $this->parameters['currentStep']))->getSteps(); $this->parameters = array_merge($this->parameters, $this->parameters['currentStep']->onThisStepSetUpPageView()); return $app['twig']->render('site/eventnew/eventDraft.preview.html.twig', $this->parameters); } } else { //////////////////////////////////////// Info needed! Show this step $this->parameters = array_merge($this->parameters, $this->parameters['currentStep']->onThisStepSetUpPage()); if ($this->parameters['currentStep']->onThisStepProcessPage() && 'POST' == $request->getMethod()) { $repo = new NewEventDraftRepository(); $repo->saveProgress($this->parameters['draft']); if ($this->parameters['currentStep']->getIsAllInformationGathered()) { return $app->redirect('/event/new/' . $this->parameters['draft']->getSlug() . "/" . $this->parameters['nextStepID']); } else { // we just have some info, but not all for this step. Stay on this step. return $app->redirect('/event/new/' . $this->parameters['draft']->getSlug() . "/" . $this->parameters['currentStep']->getStepID()); } } $this->parameters = array_merge($this->parameters, $this->parameters['currentStep']->onThisStepSetUpPageView()); $this->parameters['stepsUI'] = (new StepsUI($this->parameters['steps'], $this->parameters['currentStep']))->getSteps(); return $app['twig']->render('site/eventnew/eventDraft.html.twig', $this->parameters); } }
private function getTemplateForDaysData(\DateTime $now, $isFirst = false) { $currentDateTime = \TimeSource::getDateTime(); $out = array('timestamp' => $now->getTimestamp(), 'day' => $now->format('Y m d'), 'dataForAddUrl' => $now > $currentDateTime ? $now->format('Y-m-d') : null, 'dayOfWeek' => $now->format('N'), 'events' => array(), 'eventsContinuing' => array(), 'today' => false); if ($isFirst) { $out['display'] = $now->format('jS M Y'); $this->lastDateShown = new \DateTime('', new \DateTimeZone('UTC')); } else { if ($this->lastDateShown->format('M Y') != $now->format('M Y')) { $out['display'] = $now->format('jS M Y'); } else { $out['display'] = $now->format('jS'); } } if (date('Y m d') == $out['day']) { $out['today'] = true; } $this->lastDateShown->setTimestamp($now->getTimestamp()); $dt = new \DateTime('', new \DateTimeZone('UTC')); $dt->setTimestamp($now->getTimestamp()); $dt->setTime(0, 0, 0); $out['startTimestamp'] = $dt->getTimestamp(); $dt->setTime(23, 59, 59); $out['endTimestamp'] = $dt->getTimestamp(); return $out; }
function index(Application $app) { $start = \TimeSource::getDateTime(); return $app['twig']->render('site/maptime/index.html.twig', array('start' => $start)); }
/** * * @return type array(array(), array(), array(), boolean) - upcoming events, other events, user at event data, flag if any to send */ public function getDataForUpcomingEventsEmail() { $flag = false; $start = \TimeSource::getDateTime(); $end = \TimeSource::getDateTime(); if ($this->email_upcoming_events_days_notice > 0) { $interval = new \DateInterval("P" . $this->email_upcoming_events_days_notice . "D"); $start->add($interval); $end->add($interval); } $start->setTime(0, 0, 0); $end->setTime(23, 59, 59); $upcomingEvents = array(); $allEvents = array(); $userAtEvent = array(); $userAtEventRepo = new UserAtEventRepository(); $erb = new EventRepositoryBuilder(); $erb->setAfterNow(); $erb->setIncludeDeleted(false); $erb->setIncludeCancelled(true); $erb->setUserAccount($this, false, true); foreach ($erb->fetchAll() as $event) { $userAtEvent[$event->getId()] = $userAtEventRepo->loadByUserAndEvent($this, $event); if ($start->getTimestamp() <= $event->getStartAt()->getTimestamp() && $event->getStartAt()->getTimestamp() <= $end->getTimestamp()) { $upcomingEvents[] = $event; if ($this->email_upcoming_events == 'w') { $flag = true; } else { if ($this->email_upcoming_events == 'a') { if ($userAtEvent[$event->getId()] && $userAtEvent[$event->getId()]->getIsPlanAttending()) { $flag = true; } } else { if ($this->email_upcoming_events == 'm') { if ($userAtEvent[$event->getId()] && ($userAtEvent[$event->getId()]->getIsPlanAttending() || $userAtEvent[$event->getId()]->getIsPlanMaybeAttending())) { $flag = true; } } } } } $allEvents[] = $event; } return array($upcomingEvents, $allEvents, $userAtEvent, $flag); }
public function buildForm(FormBuilderInterface $builder, array $options) { parent::buildForm($builder, $options); $builder->add('summary', 'text', array('label' => 'Summary', 'required' => true, 'max_length' => VARCHAR_COLUMN_LENGTH_USED, 'attr' => array('autofocus' => 'autofocus'))); $builder->add('description', 'textarea', array('label' => 'Description', 'required' => false)); $builder->add('url', new \symfony\form\MagicUrlType(), array('label' => 'Information Web Page URL', 'required' => false)); $builder->add('ticket_url', new \symfony\form\MagicUrlType(), array('label' => 'Tickets Web Page URL', 'required' => false)); $crb = new CountryRepositoryBuilder(); $crb->setSiteIn($this->site); $countries = array(); $defaultCountry = null; foreach ($crb->fetchAll() as $country) { $countries[$country->getId()] = $country->getTitle(); if ($defaultCountry == null && in_array($this->timeZoneName, $country->getTimezonesAsList())) { $defaultCountry = $country->getId(); } } if (count($countries) != 1) { $builder->add('country_id', 'choice', array('label' => 'Country', 'choices' => $countries, 'required' => true, 'data' => $defaultCountry)); } else { $countryID = array_shift(array_keys($countries)); $builder->add('country_id', 'hidden', array('data' => $countryID)); } $timezones = array(); // Must explicetly set name as key otherwise Symfony forms puts an ID in, and that's no good for processing outside form foreach ($this->site->getCachedTimezonesAsList() as $timezone) { $timezones[$timezone] = $timezone; } if (count($timezones) != 1) { $builder->add('timezone', 'choice', array('label' => 'Time Zone', 'choices' => $timezones, 'required' => true)); } else { $timezone = array_pop($timezones); $builder->add('timezone', 'hidden', array('data' => $timezone)); } if ($this->site->getIsFeatureVirtualEvents()) { // if both are an option, user must check which one. if ($this->site->getIsFeaturePhysicalEvents()) { $builder->add("is_virtual", "checkbox", array('required' => false, 'label' => 'Is event accessible online?')); } } if ($this->site->getIsFeaturePhysicalEvents()) { // if both are an option, user must check which one. if ($this->site->getIsFeatureVirtualEvents()) { $builder->add("is_physical", "checkbox", array('required' => false, 'label' => 'Does the event happen at a place?')); } } $years = array(date('Y'), date('Y') + 1); $startOptions = array('label' => 'Start', 'date_widget' => 'single_text', 'date_format' => 'd/M/y', 'model_timezone' => 'UTC', 'view_timezone' => $this->timeZoneName, 'years' => $years, 'attr' => array('class' => 'dateInput'), 'required' => true); if ($this->formWidgetTimeMinutesMultiples > 1) { $startOptions['minutes'] = array(); for ($i = 0; $i <= 59; $i = $i + $this->formWidgetTimeMinutesMultiples) { $startOptions['minutes'][] = $i; } } $builder->add('start_at', 'datetime', $startOptions); $endOptions = array('label' => 'End', 'date_widget' => 'single_text', 'date_format' => 'd/M/y', 'model_timezone' => 'UTC', 'view_timezone' => $this->timeZoneName, 'years' => $years, 'attr' => array('class' => 'dateInput'), 'required' => true); if ($this->formWidgetTimeMinutesMultiples > 1) { $endOptions['minutes'] = array(); for ($i = 0; $i <= 59; $i = $i + $this->formWidgetTimeMinutesMultiples) { $endOptions['minutes'][] = $i; } } $builder->add('end_at', 'datetime', $endOptions); $this->customFields = array(); foreach ($this->site->getCachedEventCustomFieldDefinitionsAsModels() as $customField) { if ($customField->getIsActive()) { $extension = $this->extensionManager->getExtensionById($customField->getExtensionId()); if ($extension) { $fieldType = $extension->getEventCustomFieldByType($customField->getType()); if ($fieldType) { $this->customFields[] = $customField; $options = $fieldType->getSymfonyFormOptions($customField); $options['mapped'] = false; $options['data'] = $builder->getData()->getCustomField($customField); $builder->add('custom_' . $customField->getKey(), $fieldType->getSymfonyFormType($customField), $options); } } } } /** @var \closure $myExtraFieldValidator **/ $myExtraFieldValidator = function (FormEvent $event) { global $CONFIG; $form = $event->getForm(); $myExtraFieldStart = $form->get('start_at')->getData(); $myExtraFieldEnd = $form->get('end_at')->getData(); // Validate end is after start? if ($myExtraFieldStart > $myExtraFieldEnd) { $form['start_at']->addError(new FormError("The start can not be after the end!")); } // validate not to far in future $max = \TimeSource::getDateTime(); $max->add(new \DateInterval("P" . $CONFIG->eventsCantBeMoreThanYearsInFuture . "Y")); if ($myExtraFieldStart > $max) { $form['start_at']->addError(new FormError("The event can not be more than " . ($CONFIG->eventsCantBeMoreThanYearsInFuture > 1 ? $CONFIG->eventsCantBeMoreThanYearsInFuture . " years" : "a year") . " in the future.")); } if ($myExtraFieldEnd > $max) { $form['end_at']->addError(new FormError("The event can not be more than " . ($CONFIG->eventsCantBeMoreThanYearsInFuture > 1 ? $CONFIG->eventsCantBeMoreThanYearsInFuture . " years" : "a year") . " in the future.")); } // validate not to far in past $min = \TimeSource::getDateTime(); $min->sub(new \DateInterval("P" . $CONFIG->eventsCantBeMoreThanYearsInPast . "Y")); if ($myExtraFieldStart < $min) { $form['start_at']->addError(new FormError("The event can not be more than " . ($CONFIG->eventsCantBeMoreThanYearsInPast > 1 ? $CONFIG->eventsCantBeMoreThanYearsInPast . " years" : "a year") . " in the past.")); } if ($myExtraFieldEnd < $min) { $form['end_at']->addError(new FormError("The event can not be more than " . ($CONFIG->eventsCantBeMoreThanYearsInPast > 1 ? $CONFIG->eventsCantBeMoreThanYearsInPast . " years" : "a year") . " in the past.")); } // URL validation. We really can't do much except verify ppl haven't put a space in, which they might do if they just type in Google search terms (seen it done) if (strpos($form->get("url")->getData(), " ") !== false) { $form['url']->addError(new FormError("Please enter a URL")); } if (strpos($form->get("ticket_url")->getData(), " ") !== false) { $form['ticket_url']->addError(new FormError("Please enter a URL")); } }; // adding the validator to the FormBuilderInterface $builder->addEventListener(FormEvents::POST_BIND, $myExtraFieldValidator); }
/** * * @package com.meetyournextmp * @license Closed Source * @copyright (c) 2013-2015, JMB Technology Limited, http://jmbtechnology.co.uk/ * @author James Baster <*****@*****.**> */ // setup $siteRepo = new \repositories\SiteRepository(); $site = $siteRepo->loadById($CONFIG->singleSiteID); $customFields = $site->getCachedEventCustomFieldDefinitionsAsModels(); $customFieldOrganiserEmail = $customFields[0]; $userRepo = new \repositories\UserAccountRepository(); $organiserEmailRepo = new \com\meetyournextmp\repositories\OrganiserEmailRepository(); configureAppForSite($site); $nowPlusSomeEmailReadingTime = TimeSource::getDateTime(); $nowPlusSomeEmailReadingTime->add(new \DateInterval("P1D")); // Events $erb = new \repositories\builders\EventRepositoryBuilder(); $erb->setSite($site); $erb->setAfterNow(); $erb->setIncludeCancelled(false); $erb->setIncludeDeleted(false); foreach ($erb->fetchAll() as $event) { print $event->getSlug() . " " . $event->getSummary() . "\n"; $email = \com\meetyournextmp\models\OrganiserEmailModel::getEmailFrom($event->getCustomField($customFieldOrganiserEmail)); if ($email) { print " - email: " . $email . "\n"; if ($event->getStartAtInUTC()->getTimestamp() < $nowPlusSomeEmailReadingTime->getTimestamp()) { print " - event to soon, not sending\n"; } else {
die("NO CONFIG " . $key . " ?\n"); } } // ######################################################### Load site, build query $siteRepository = new SiteRepository(); $site = $siteRepository->loadById($thisconfig->get('SiteID')); if (!$site) { die("NO SITE?\n"); } $calendar = new \RenderCalendar(); $calendar->getEventRepositoryBuilder()->setSite($site); $calendar->getEventRepositoryBuilder()->setIncludeDeleted(false); // ######################################################### Set Start and End $start = \TimeSource::getDateTime(); $start->setTime(0, 0, 0); $end = \TimeSource::getDateTime(); $end->setTime(0, 0, 0); if ($thisconfig->hasValue("Month") && $thisconfig->hasValue("Year")) { // Options for setting end; by a set month and year if ($thisconfig->get('Month') == 12) { $end->setDate($thisconfig->get('Year') + 1, 1, 1); } else { $end->setDate($thisconfig->get('Year'), $thisconfig->get('Month') + 1, 1); } $end->sub(new \DateInterval('PT1S')); } else { if ($thisconfig->hasValue("Days")) { // Options for setting end; by a number of days $end->add(new \DateInterval('P' . $thisconfig->get("Days") . 'D')); } else { // Options for setting end; default to 30 days
public function isDateToLateForArbitraryDate(\DateTime $newDate, \TimeSource $timeSource, $daysInAdvance = 186) { $now = $timeSource->getDateTime(); // Add one day just to stop random errors with time. $now->add(new \DateInterval('P' . $daysInAdvance . 'D')); return $newDate > $now; }
function run(Request $request, Application $app) { $this->build($app); // Get dates we will sort events into $t = \TimeSource::getDateTime(); $t->setTimeZone(new \DateTimeZone($app['currentTimeZone'])); $today = $t->format('d-m-Y'); $nextDates = array(); for ($i = 1; $i <= $this->paramaters['daysAheadInNextBox']; $i++) { $t->add(new \DateInterval('P1D')); $nextDates[] = $t->format('d-m-Y'); } // Sort events into dates $this->paramaters['eventsToday'] = array(); $this->paramaters['eventsTodayMinorImportance'] = array(); $this->paramaters['eventsNext'] = array(); $this->paramaters['eventsNextMinorImportance'] = array(); $this->paramaters['eventsLater'] = array(); $this->paramaters['eventsLaterMinorImportance'] = array(); $eventIDsSeen = array(); foreach ($this->paramaters['data'] as $queries) { foreach ($queries['query']->fetchAll() as $event) { if (!in_array($event->getId(), $eventIDsSeen)) { $eventStart = $event->getStartAt()->format('d-m-Y'); if ($eventStart == $today) { $this->paramaters['eventsToday' . ($queries['minorImportance'] ? 'MinorImportance' : '')][] = $event; } else { if (in_array($eventStart, $nextDates)) { $this->paramaters['eventsNext' . ($queries['minorImportance'] ? 'MinorImportance' : '')][] = $event; } else { $this->paramaters['eventsLater' . ($queries['minorImportance'] ? 'MinorImportance' : '')][] = $event; } } $eventIDsSeen[] = $event->getId(); } } } $cmp = function ($a, $b) { if ($a->getStartAt()->getTimestamp() == $b->getStartAt()->getTimestamp()) { return 0; } return $a->getStartAt()->getTimestamp() < $b->getStartAt()->getTimestamp() ? -1 : 1; }; usort($this->paramaters['eventsToday'], $cmp); usort($this->paramaters['eventsTodayMinorImportance'], $cmp); usort($this->paramaters['eventsNext'], $cmp); usort($this->paramaters['eventsNextMinorImportance'], $cmp); usort($this->paramaters['eventsLater'], $cmp); usort($this->paramaters['eventsLaterMinorImportance'], $cmp); return $app['twig']->render('displayboard/site/displayboard/run.html.twig', $this->paramaters); }
protected function run() { $siteRepo = new \repositories\SiteRepository(); $site = $siteRepo->loadById($this->app['config']->singleSiteID); // TODO assumes single site! $out = array(); $erb = new EventRepositoryBuilder(); $erb->setIncludeDeleted(false); $erb->setIncludeCancelled(false); $erb->setSite($site); $out['countEventsTotal'] = count($erb->fetchAll()); $erb = new EventRepositoryBuilder(); $erb->setIncludeDeleted(false); $erb->setIncludeCancelled(false); $erb->setSite($site); $erb->setBefore($this->app['timesource']->getDateTime()); $out['countEventsBeforeNow'] = count($erb->fetchAll()); $erb = new EventRepositoryBuilder(); $erb->setIncludeDeleted(false); $erb->setIncludeCancelled(false); $erb->setSite($site); $erb->setAfterNow(); $out['countEventsAfterNow'] = count($erb->fetchAll()); $arb = new \com\meetyournextmp\repositories\builders\AreaRepositoryBuilder(); $arb->setIsMapItAreaOnly(true); $arb->setIncludeDeleted(false); $arb->setIncludeAreasWithNoEventsOnly(true); $arb->setLimit(800); $out['countSeatsWithNoEvents'] = count($arb->fetchAll()); $areaRepo = new AreaRepository(); foreach (array(3 => 'countEventsInScotland', 1 => 'countEventsInEngland', 2 => 'countEventsInWales', 4 => 'countEventsInNIreland', 712 => 'countEventsInGreaterLondon') as $areaSlug => $key) { $erb = new EventRepositoryBuilder(); $erb->setIncludeDeleted(false); $erb->setIncludeCancelled(false); $erb->setSite($site); $erb->setArea($areaRepo->loadBySlug($site, $areaSlug)); $out[$key] = count($erb->fetchAll()); } // =================================== Events by day $report = $this->getValueReport('com.meetyournextmp', 'NonDeletedNonCancelledEventsStartAtReport', $this->app); $startAt = \TimeSource::getDateTime(); $startAt->setTime(0, 0, 0); $endAt = new \DateTime('2015-05-07 10:00:00'); $period = "P1D"; $report->setFilterSiteId($this->app['config']->singleSiteID); $reportByTime = new SeriesOfValueByTimeReport($report, $startAt, $endAt, $period); $reportByTime->run(); $out['countEventsByDay'] = array(); foreach ($reportByTime->getData() as $data) { $out['countEventsByDay'][] = array('count' => $data->getData(), 'date' => $data->getLabelStart()->format('D d F Y')); } // =================================== Users with edits $report = $this->getSeriesReport("org.openacalendar", "UsersWithEventsEdited", $this->app); $report->run(); $out['userEventsEdited'] = array(); foreach ($report->getData() as $data) { $out['userEventsEdited'][] = array('count' => $data->getData(), 'userID' => $data->getLabelID(), 'userUserName' => $data->getLabelText()); } //var_dump($out); file_put_contents(APP_ROOT_DIR . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'numbers.json', json_encode($out)); return array('result' => 'ok'); }
/** * @return BaseUserWatchesNotifyContent|null */ public function getUserNotifyContentForSiteAndUser(SiteModel $siteModel, UserAccountModel $userAccountModel) { global $CONFIG; $userWatchesSite = $this->loadByUserAndSite($userAccountModel, $siteModel); if ($userWatchesSite && $userWatchesSite->getIsWatching()) { $dateSince = $userWatchesSite->getSinceDateForNotifyChecking(); $checkTime = \TimeSource::getDateTime(); $historyRepositoryBuilder = new HistoryRepositoryBuilder(); $historyRepositoryBuilder->setSite($siteModel); $historyRepositoryBuilder->setSince($dateSince); $historyRepositoryBuilder->setNotUser($userAccountModel); // Only admins can change tags at the moment so don't include $historyRepositoryBuilder->setIncludeTagHistory(false); $histories = $historyRepositoryBuilder->fetchAll(); if ($histories) { $content = new UserWatchesSiteNotifyContent(); $content->setHistories($histories); $userWatchesSiteStopRepository = new UserWatchesSiteStopRepository(); $userWatchesSiteStop = $userWatchesSiteStopRepository->getForUserAndSite($userAccountModel, $siteModel); $content->setUnwatchURL($CONFIG->getWebSiteDomainSecure($siteModel->getSlug()) . '/stopWatchingFromEmail/' . $userAccountModel->getId() . '/' . $userWatchesSiteStop->getAccessKey()); $content->setUserAccount($userAccountModel); $content->setSite($siteModel); $content->setWatchedThingTitle($siteModel->getTitle()); $content->setWatchedThingURL($CONFIG->getWebSiteDomainSecure($siteModel->getSlug()) . '/history'); return $content; } } }