Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions module/CudiBundle/Component/Mail/Booking.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,100 @@ public static function sendAssignMail(EntityManager $entityManager, TransportInt
$mailTransport->send($mail);
}
}
/**
* Send a mail when an assignment has been extended
*
* @param EntityManager $entityManager
* @param TransportInterface $mailTransport
* @param array $bookings
* @param Person $person
*/
public static function sendAssignmentExtendedMail(EntityManager $entityManager, TransportInterface $mailTransport, $bookings, Person $person)
{
$language = $person->getLanguage();
if ($language === null) {
$language = $entityManager->getRepository('CommonBundle\Entity\General\Language')
->findOneByAbbrev('en');
}

// Retrieve mail configuration for assignment extension (you need to add this key in your config)
$mailData = unserialize(
$entityManager
->getRepository('CommonBundle\Entity\General\Config')
->getConfigValue('cudi.booking_assignment_extended_mail')
);

$message = $mailData[$language->getAbbrev()]['content'];
$subject = $mailData[$language->getAbbrev()]['subject'];

$mailAddress = $entityManager
->getRepository('CommonBundle\Entity\General\Config')
->getConfigValue('cudi.mail');

$mailName = $entityManager
->getRepository('CommonBundle\Entity\General\Config')
->getConfigValue('cudi.mail_name');

$openingHours = $entityManager
->getRepository('CudiBundle\Entity\Sale\Session\OpeningHour')
->findPeriodFromNow('P7D');

$openingHourText = '';
foreach ($openingHours as $openingHour) {
$openingHourText .= '- ' . $openingHour->getStart()->format('l') . ' (' . $openingHour->getStart()->format('d/m') . ') : ' .
$openingHour->getStart()->format('G:i') . ' - ' . $openingHour->getEnd()->format('G:i');
if (strlen($openingHour->getComment($language)) > 0) {
$openingHourText .= ' (' . $openingHour->getComment($language) . ')';
}
$openingHourText .= "\r\n";
}

if ($openingHourText == '') {
$message = str_replace('#no_opening_hours#', '', $message);
} else {
$message = preg_replace('/#no_opening_hours#.*#no_opening_hours#/', '', $message);
}

preg_match('/#expires#(.*)#expires#/', $message, $matches);
$message = preg_replace('/#expires#.*#expires#/', '', $message);

$list = '';
foreach ($bookings as $booking) {
$list .= '* ' . $booking->getArticle()->getMainArticle()->getTitle();
if ($booking->getExpirationDate()) {
$list .= ' (' . $matches[1] . ' ' . $booking->getExpirationDate()->format('d/m/Y') . ')';
}
$list .= "\r\n";
}

$mail = new Message();
$mail->setEncoding('UTF-8')
->setBody(str_replace('{{ bookings }}', $list, str_replace('{{ openingHours }}', $openingHourText, $message)))
->setFrom($mailAddress, $mailName)
->addTo($person->getEmail(), $person->getFullName())
->setSubject($subject);

if ($entityManager->getRepository('CommonBundle\Entity\General\Config')->getConfigValue('cudi.booking_mails_to_sysadmin')) {
$mail->addBcc(
$entityManager
->getRepository('CommonBundle\Entity\General\Config')
->getConfigValue('system_administrator_mail'),
'System Administrator'
);
}

$sendMailsToCudi = $entityManager
->getRepository('CommonBundle\Entity\General\Config')
->getConfigValue('cudi.booking_mails_to_cudi') == 1;
if ($sendMailsToCudi) {
$mail->addCc($mailAddress, $mailName);
}

if (getenv('APPLICATION_ENV') != 'development') {
$mailTransport->send($mail);
}
}


/**
* Send a warning mail before expiring bookings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,11 +428,18 @@ public function extendAction()
$date = clone $booking->getExpirationDate();
$booking->setExpirationDate($date->add(new DateInterval($extendTime)));
$this->getEntityManager()->flush();
// Send an email notification indicating the assignment was extended
BookingMail::sendAssignmentExtendedMail(
$this->getEntityManager(),
$this->getMailTransport(),
[$booking],
$booking->getPerson()
);
}

$this->flashMessenger()->success(
'SUCCESS',
'The booking was successfully extended!'
'The booking was successfully extended and a notification email has been sent!'
);

$this->redirect()->toRoute(
Expand Down