protected function run() { global $CONFIG; $userRepoBuilder = new UserAccountRepositoryBuilder(); $userAccountGeneralSecurityKeyRepository = new UserAccountGeneralSecurityKeyRepository(); $userNotificationRepo = new UserNotificationRepository(); /** @var usernotifications/UpcomingEventsUserNotificationType **/ $userNotificationType = $this->app['extensions']->getCoreExtension()->getUserNotificationType('UpcomingEvents'); configureAppForThemeVariables(null); foreach ($userRepoBuilder->fetchAll() as $user) { $this->logVerbose(" User " . $user->getEmail()); $this->logVerbose(" ... searching"); list($upcomingEvents, $allEvents, $userAtEvent, $flag) = $user->getDataForUpcomingEventsEmail(); if ($flag) { $this->logVerbose(" ... found data"); /** Notification Class * @var usernotifications/UpcomingEventsUserNotificationModel **/ $userNotification = $userNotificationType->getNewNotification($user, null); $userNotification->setUpcomingEvents($upcomingEvents); $userNotification->setAllEvents($allEvents); ////// Save Notification Class $userNotificationRepo->create($userNotification); ////// Send Email if ($userNotification->getIsEmail()) { configureAppForUser($user); $userAccountGeneralSecurityKey = $userAccountGeneralSecurityKeyRepository->getForUser($user); $unsubscribeURL = $CONFIG->getWebIndexDomainSecure() . '/you/emails/' . $user->getId() . '/' . $userAccountGeneralSecurityKey->getAccessKey(); $message = \Swift_Message::newInstance(); $message->setSubject("Events coming up"); $message->setFrom(array($CONFIG->emailFrom => $CONFIG->emailFromName)); $message->setTo($user->getEmail()); $messageText = $this->app['twig']->render('email/upcomingEventsForUser.txt.twig', array('user' => $user, 'upcomingEvents' => $upcomingEvents, 'allEvents' => $allEvents, 'userAtEvent' => $userAtEvent, 'generalSecurityCode' => $userAccountGeneralSecurityKey->getAccessKey(), 'currentTimeZone' => 'Europe/London', 'unsubscribeURL' => $unsubscribeURL)); if ($CONFIG->isDebug) { file_put_contents('/tmp/upcomingEventsForUser.txt', $messageText); } $message->setBody($messageText); $messageHTML = $this->app['twig']->render('email/upcomingEventsForUser.html.twig', array('user' => $user, 'upcomingEvents' => $upcomingEvents, 'allEvents' => $allEvents, 'userAtEvent' => $userAtEvent, 'generalSecurityCode' => $userAccountGeneralSecurityKey->getAccessKey(), 'currentTimeZone' => 'Europe/London', 'unsubscribeURL' => $unsubscribeURL)); if ($CONFIG->isDebug) { file_put_contents('/tmp/upcomingEventsForUser.html', $messageHTML); } $message->addPart($messageHTML, 'text/html'); $headers = $message->getHeaders(); $headers->addTextHeader('List-Unsubscribe', $unsubscribeURL); $this->logVerbose(" ... sending"); if (!$CONFIG->isDebug) { $this->app['mailer']->send($message); } $userNotificationRepo->markEmailed($userNotification); } } } return array('result' => 'ok'); }
public function sendEmail($app, UserAccountModel $user) { global $CONFIG; $message = \Swift_Message::newInstance(); $message->setSubject("Please verify your account on " . $CONFIG->siteTitle); $message->setFrom(array($CONFIG->emailFrom => $CONFIG->emailFromName)); $message->setTo($user->getEmail()); configureAppForThemeVariables(); $messageText = $app['twig']->render('email/userVerifyEmail.txt.twig', array('user' => $user, 'code' => $this->access_key)); if ($CONFIG->isDebug) { file_put_contents('/tmp/userVerifyEmail.txt', $messageText); } $message->setBody($messageText); $messageHTML = $app['twig']->render('email/userVerifyEmail.html.twig', array('user' => $user, 'code' => $this->access_key)); if ($CONFIG->isDebug) { file_put_contents('/tmp/userVerifyEmail.html', $messageHTML); } $message->addPart($messageHTML, 'text/html'); if (!$CONFIG->isDebug) { $app['mailer']->send($message); } }
function configureAppForSite(SiteModel $site) { global $app; # ////////////// Site // not sure where this is used, would be good to remove and switch to currentSite $app['twig']->addGlobal('site', $site); $app['site'] = $site; // this is the proper convention $app['twig']->addGlobal('currentSite', $site); $app['currentSite'] = $site; # ////////////// Timezone $timezone = ""; if (in_array('Europe/London', $site->getCachedTimezonesAsList())) { $timezone = 'Europe/London'; } else { $timezone = $site->getCachedTimezonesAsList()[0]; } $app['twig']->addGlobal('currentTimeZone', $timezone); $app['currentTimeZone'] = $timezone; # ////////////// Theme Vars configureAppForThemeVariables($site); }
public function send(Application $app, UserAccountModel $sentBy) { global $CONFIG; $message = \Swift_Message::newInstance(); $message->setSubject($this->subject); $message->setFrom(array($CONFIG->emailFrom => $this->getSendFromName($sentBy))); $message->setTo($this->send_to); configureAppForThemeVariables(); $messageText = $app['twig']->render('email/sendemail.txt.twig', array('currentTimeZone' => $this->timezone, 'sendemail' => $this)); if ($CONFIG->isDebug) { file_put_contents('/tmp/sendemail.txt', $messageText); } $message->setBody($messageText); $messageHTML = $app['twig']->render('email/sendemail.html.twig', array('currentTimeZone' => $this->timezone, 'sendemail' => $this)); if ($CONFIG->isDebug) { file_put_contents('/tmp/sendemail.html', $messageHTML); } $message->addPart($messageHTML, 'text/html'); if (!$CONFIG->isDebug) { $app['mailer']->send($message); } }
public function sendEmailToSupport($app, $userFrom = null) { global $CONFIG; if ($CONFIG->contactEmail) { $message = \Swift_Message::newInstance(); $message->setSubject("Contact Message From " . $CONFIG->siteTitle . " : " . $this->subject); $message->setFrom(array($CONFIG->emailFrom => $CONFIG->emailFromName)); $message->setTo($CONFIG->contactEmail); $message->setReplyTo(array($this->email => $this->email)); configureAppForThemeVariables(); $messageText = $app['twig']->render('email/contactSupport.txt.twig', array('contact' => $this, 'userFrom' => $userFrom)); if ($CONFIG->isDebug) { file_put_contents('/tmp/contactSupport.txt', $messageText); } $message->setBody($messageText); $messageHTML = $app['twig']->render('email/contactSupport.html.twig', array('contact' => $this, 'userFrom' => $userFrom)); if ($CONFIG->isDebug) { file_put_contents('/tmp/contactSupport.html', $messageHTML); } $message->addPart($messageHTML, 'text/html'); if (!$CONFIG->isDebug) { $app['mailer']->send($message); } } }