Skip to content

Commit

Permalink
Merge pull request #94 from NielsRoels/oldMailCleanUp
Browse files Browse the repository at this point in the history
Mail clean up
  • Loading branch information
tvlooy committed Apr 7, 2016
2 parents f30bf0d + c994324 commit b4d6ca1
Show file tree
Hide file tree
Showing 11 changed files with 215 additions and 594 deletions.
109 changes: 0 additions & 109 deletions src/Intracto/SecretSantaBundle/Command/MailqueueCommand.php

This file was deleted.

87 changes: 0 additions & 87 deletions src/Intracto/SecretSantaBundle/Command/SendBatchMailsCommand.php

This file was deleted.

21 changes: 12 additions & 9 deletions src/Intracto/SecretSantaBundle/Controller/PoolController.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ public function manageAction($listUrl)
'success',
$translator->trans('flashes.manage.email_validated')
);
/** @var \Intracto\SecretSantaBundle\Entity\EntryService $entryService */
$entryService = $this->get('intracto_secret_santa.entry_service');
/** @var \Intracto\SecretSantaBundle\Mailer\MailerService $mailerService */
$mailerService = $this->get('intracto_secret_santa.mail');

$entryService->sendSecretSantaMailsForPool($this->pool);
$mailerService->sendSecretSantaMailsForPool($this->pool);
}

return array(
Expand Down Expand Up @@ -225,9 +225,9 @@ public function exposeAction(Request $request, $listUrl)
$em->flush();

/* Mail pool owner the pool matches */
/** @var \Intracto\SecretSantaBundle\Entity\EntryService $entryService */
$entryService = $this->get('intracto_secret_santa.entry_service');
$entryService->sendPoolMatchesToAdmin($this->pool);
/** @var \Intracto\SecretSantaBundle\Mailer\MailerService $mailerService */
$mailerService = $this->get('intracto_secret_santa.mail');
$mailerService->sendPoolMatchesToAdmin($this->pool);

return $this->redirect($this->generateUrl('pool_manage', array('listUrl' => $listUrl)));
}
Expand All @@ -248,8 +248,9 @@ public function resendAction($listUrl, $entryId)
throw new NotFoundHttpException();
}

$entryService = $this->get('intracto_secret_santa.entry_service');
$entryService->sendSecretSantaMailForEntry($entry);
/** @var \Intracto\SecretSantaBundle\Mailer\MailerService $mailerService */
$mailerService = $this->get('intracto_secret_santa.mail');
$mailerService->sendSecretSantaMailForEntry($entry);

$translator = $this->get('translator');
$this->get('session')->getFlashBag()->add(
Expand All @@ -267,11 +268,13 @@ public function resendAction($listUrl, $entryId)
public function forgotLinkAction(Request $request)
{
$form = $this->createForm(new ForgotLinkType());
/** @var \Intracto\SecretSantaBundle\Mailer\MailerService $mailerService */
$mailerService = $this->get('intracto_secret_santa.mail');

if ($request->isMethod('POST')) {
$form->handleRequest($request);
if ($form->isValid()) {
if ($this->get('intracto_secret_santa.pool_service')->sendForgotManageLinkMail($form->getData()['email'])) {
if ($mailerService->sendForgotManageLinkMail($form->getData()['email'])) {
$feedback = array(
'type' => 'success',
'message' => $this->get('translator')->trans('flashes.forgot_manage_link.success'),
Expand Down
61 changes: 0 additions & 61 deletions src/Intracto/SecretSantaBundle/Entity/EntryService.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,67 +77,6 @@ public function shuffleEntries(Pool $pool)
$this->em->flush();
}

/**
* Sends out all mails for a Pool
*
* @param Pool $pool
*/
public function sendSecretSantaMailsForPool(Pool $pool)
{
$pool->setSentdate(new \DateTime('now'));
$this->em->flush($pool);

foreach ($pool->getEntries() as $entry) {
$this->sendSecretSantaMailForEntry($entry);
}
}

/**
* Sends out mail for a Entry
*
* @param Entry $entry
*/
public function sendSecretSantaMailForEntry(Entry $entry)
{
$this->translator->setLocale($entry->getPool()->getLocale());

$message = $entry->getPool()->getMessage();
$message = str_replace('(NAME)', $entry->getName(), $message);
$message = str_replace('(ADMINISTRATOR)', $entry->getPool()->getOwnerName(), $message);
$txtBody = $this->templating->render(
'IntractoSecretSantaBundle:Emails:secretsanta.txt.twig',
array('message' => $message, 'entry' => $entry)
);
$htmlBody = $this->templating->render(
'IntractoSecretSantaBundle:Emails:secretsanta.html.twig',
array('message' => $message, 'entry' => $entry)
);

$mail = \Swift_Message::newInstance()
->setSubject($this->translator->trans('emails.secretsanta.subject'))
->setFrom($this->adminEmail, $entry->getPool()->getOwnerName())
->setReplyTo([$entry->getPool()->getOwnerEmail() => $entry->getPool()->getOwnerName()])
->setTo($entry->getEmail(), $entry->getName())
->setBody($txtBody)
->addPart($htmlBody, 'text/html');
$this->mailer->send($mail);
}

/**
* @param Pool $pool
*/
public function sendPoolMatchesToAdmin(Pool $pool)
{
$this->translator->setLocale($pool->getLocale());
$this->mailer->send(\Swift_Message::newInstance()
->setSubject($this->translator->trans('emails.admin_matches.subject'))
->setFrom($this->adminEmail, $this->translator->trans('emails.sender'))
->setTo($pool->getOwnerEmail(), $pool->getOwnerName())
->setBody($this->templating->render('IntractoSecretSantaBundle:Emails:admin_matches.html.twig', array('pool' => $pool)), 'text/html')
->addPart($this->templating->render('IntractoSecretSantaBundle:Emails:admin_matches.txt.twig', array('pool' => $pool)), 'text/plain')
);
}

/**
* @return array
*
Expand Down
4 changes: 2 additions & 2 deletions src/Intracto/SecretSantaBundle/Entity/PoolRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ public function findAllAdminPools($email)
{
$qb = $this->_em->createQueryBuilder();
$qb->addSelect('pool.listurl')
->addSelect('pool.date')
->addSelect('pool.eventdate')
->addSelect('pool.locale')
->from('IntractoSecretSantaBundle:Pool', 'pool')
->join('pool.entries', 'entries')
->andWhere('entries.poolAdmin = true')
->andWhere('entries.email = :email')
->andWhere('pool.date >= :date')
->andWhere('pool.eventdate >= :date')
->setParameters([
'email' => $email,
'date' => new \DateTime('-1 week'),
Expand Down
44 changes: 0 additions & 44 deletions src/Intracto/SecretSantaBundle/Entity/PoolService.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,49 +59,5 @@ class PoolService
*/
public $routing;

public function sendForgotManageLinkMail($email)
{
$results = $this->em->getRepository('IntractoSecretSantaBundle:Pool')->findAllAdminPools($email);

if (count($results) == 0) {
return false;
}

$poolLinks = array();
foreach ($results as $result) {
$text = $this->translator->trans('manage.title');

if ($result['date'] instanceof \DateTime) {
$text .= ' (' . $result['date']->format('d/m/Y') . ')';
}

$poolLinks[] = array(
'url' => $this->routing->generate('pool_manage', array('listUrl' => $result['listurl']), Router::ABSOLUTE_URL),
'text' => $text,
);
}

$this->translator->setLocale($results[0]['locale']);

$message = \Swift_Message::newInstance()
->setSubject($this->translator->trans('emails.forgot_link.subject'))
->setFrom($this->adminEmail, $this->translator->trans('emails.sender'))
->setTo($email)
->setBody(
$this->templating->render(
'IntractoSecretSantaBundle:Emails:forgotlink.txt.twig',
array('poolLinks' => $poolLinks)
)
)
->addPart(
$this->templating->render(
'IntractoSecretSantaBundle:Emails:forgotlink.html.twig',
array('poolLinks' => $poolLinks)
),
'text/html'
);
$this->mailer->send($message);

return true;
}
}
Loading

0 comments on commit b4d6ca1

Please sign in to comment.