Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial commit for added email notifications for admins and staff mem… #519

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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
2 changes: 2 additions & 0 deletions data/res/i18n/de-DE/backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@
=> 'Wird für Benachrichtigungen des Systems benötigt.<br>Kann auch Benutzern für Hilfe angezeigt werden.',
'Send user emails like booking/cancel confirmation to this address as well'
=> 'Sende Benutzer-E-Mails wie Buchungs- oder Stornierungsbestätigungen als Kopie an diese Adresse',
'Also generate emails in case an admin/staff member creates/cancels booking'
=> 'E-Mails auch verschicken wenn die Buchung von der Verwaltung oder Mitarbeitern getätigt wird',
'Your phone number' => 'Ihre Telefonnummer',
'Displayed for booking by phone.'
=> 'Wird für die telefonische Buchung angezeigt.<br>Erscheint z.B. ganz oben in der Kopfleiste.',
Expand Down
3 changes: 3 additions & 0 deletions data/res/i18n/de-DE/booking.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
'Weekly' => 'Wöchentlich',
'Every 2 weeks' => 'Alle 2 Wochen',
'Monthly' => 'Monatlich',
'until' => 'bis zum',
'This booking repeats:' => 'Dies ist eine wiederkehrende Buchung:',
'This booking was a repeat booking: ' => 'Dies war eine wiederkehrende Buchung: ',

'Ambiguous user name "%s" passed (multiple users under this name)'
=> 'Es gibt mehrere Benutzer mit dem Namen "%s"',
Expand Down
15 changes: 15 additions & 0 deletions module/Backend/src/Backend/Controller/BookingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public function editAction()

$serviceManager = @$this->getServiceLocator();
$formElementManager = $serviceManager->get('FormElementManager');
$bookingService = $serviceManager->get('Booking\Service\BookingService');

$editForm = $formElementManager->get('Backend\Form\Booking\EditForm');

Expand Down Expand Up @@ -153,6 +154,8 @@ public function editAction()

$this->flashMessenger()->addSuccessMessage('Booking has been saved');

$bookingService->getEventManager()->trigger('create.booking', $savedBooking);

if ($this->params()->fromPost('bf-edit-user')) {
return $this->redirect()->toRoute('backend/user/edit', ['uid' => $savedBooking->get('uid')]);
} else if ($this->params()->fromPost('bf-edit-bills')) {
Expand Down Expand Up @@ -261,6 +264,7 @@ public function editRangeAction()
$bookingManager = $serviceManager->get('Booking\Manager\BookingManager');
$reservationManager = $serviceManager->get('Booking\Manager\ReservationManager');
$formElementManager = $serviceManager->get('FormElementManager');
$bookingService = $serviceManager->get('Booking\Service\BookingService');

$bid = $this->params()->fromRoute('bid');

Expand Down Expand Up @@ -297,6 +301,8 @@ public function editRangeAction()
$bookingManager->save($booking);
}

$bookingService->getEventManager()->trigger('create.booking', $booking);

$this->flashMessenger()->addSuccessMessage('Booking has been saved');

return $this->redirect()->toRoute('frontend');
Expand Down Expand Up @@ -327,6 +333,8 @@ public function editRangeAction()
$bookingManager->save($booking);
}

$bookingService->getEventManager()->trigger('create.booking', $booking);

$this->flashMessenger()->addSuccessMessage('Booking has been saved');

return $this->redirect()->toRoute('frontend');
Expand Down Expand Up @@ -363,6 +371,7 @@ public function deleteAction()
$serviceManager = @$this->getServiceLocator();
$bookingManager = $serviceManager->get('Booking\Manager\BookingManager');
$reservationManager = $serviceManager->get('Booking\Manager\ReservationManager');
$bookingService = $serviceManager->get('Booking\Service\BookingService');

$rid = $this->params()->fromRoute('rid');
$editMode = $this->params()->fromQuery('edit-mode');
Expand All @@ -384,6 +393,8 @@ public function deleteAction()
if ($editMode == 'reservation') {
$this->authorize(['calendar.delete-single-bookings', 'calendar.delete-subscription-bookings']);

$bookingService->getEventManager()->trigger('cancel.booking', $booking);

$reservationManager->delete($reservation);

$this->flashMessenger()->addSuccessMessage('Reservation has been deleted');
Expand All @@ -392,6 +403,8 @@ public function deleteAction()
if ($this->params()->fromQuery('cancel') == 'true') {
$this->authorize(['calendar.cancel-single-bookings', 'calendar.cancel-subscription-bookings']);

$bookingService->getEventManager()->trigger('cancel.booking', $booking);

$booking->set('status', 'cancelled');
$booking->setMeta('cancellor', $sessionUser->get('alias'));
$booking->setMeta('cancelled', date('Y-m-d H:i:s'));
Expand All @@ -401,6 +414,8 @@ public function deleteAction()
} else {
$this->authorize(['calendar.delete-single-bookings', 'calendar.delete-subscription-bookings']);

$bookingService->getEventManager()->trigger('cancel.booking', $booking);

$bookingManager->delete($booking);

$this->flashMessenger()->addSuccessMessage('Booking has been deleted');
Expand Down
1 change: 1 addition & 0 deletions module/Backend/src/Backend/Form/Config/TextForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class TextForm extends Form
'client.name.short' => array('Your abbreviation', 'Short form or abbreviation of your name.<br>Displayed in emails, for example.'),
'client.contact.email' => array('Your email address', 'Will be used for system notifications.<br>Might also be displayed to users for help.'),
'client.contact.email.user-notifications' => array('Send user emails like booking/cancel confirmation to this address as well', null, 'Checkbox'),
'client.contact.email.admin-notifications' => array('Also generate emails in case an admin/staff member creates/cancels booking', null, 'Checkbox'),
'client.contact.phone' => array('Your phone number', 'Displayed for booking by phone.'),
'client.website' => array('Your website', 'The address of your website.<br>Displayed in the header, for example.'),
'client.website.contact' => array('Your contact page', 'The address of your website\'s contact page.<br>Displayed in the header, for example.'),
Expand Down
4 changes: 2 additions & 2 deletions module/Booking/src/Booking/Service/BookingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function createSingle(User $user, Square $square, $quantity, DateTime $da
$this->connection->commit();
}

$this->getEventManager()->trigger('create.single', $booking);
$this->getEventManager()->trigger('create.booking', $booking);

return $booking;

Expand All @@ -140,7 +140,7 @@ public function cancelSingle(Booking $booking)

$this->bookingManager->save($booking);

$this->getEventManager()->trigger('cancel.single', $booking);
$this->getEventManager()->trigger('cancel.booking', $booking);

return $booking;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Booking\Manager\ReservationManager;
use Square\Manager\SquareManager;
use User\Manager\UserManager;
use User\Entity\User;
use User\Service\MailService as UserMailService;
use Zend\EventManager\AbstractListenerAggregate;
use Zend\EventManager\Event;
Expand Down Expand Up @@ -46,20 +47,40 @@ public function __construct(OptionManager $optionManager, ReservationManager $re

public function attach(EventManagerInterface $events)
{
$events->attach('create.single', array($this, 'onCreateSingle'));
$events->attach('cancel.single', array($this, 'onCancelSingle'));
$events->attach('create.booking', array($this, 'onCreate'));
$events->attach('cancel.booking', array($this, 'onCancel'));
}

public function onCreateSingle(Event $event)
public function validateUser(User $user)
{
if($user->get('email', null) == null)
return false;

//need to check if we are admins or assists and want to receive notifications
if($user->getStatus() == 'Admin' || $user->getStatus() == 'Assist')
if(!$this->optionManager->get('client.contact.email.admin-notifications'))
return false;

return true;
}

public function onCreate(Event $event)
{
$booking = $event->getTarget();
$reservation = current($booking->getExtra('reservations'));
$square = $this->squareManager->get($booking->need('sid'));
$user = $this->userManager->get($booking->need('uid'));

$dateFormatHelper = $this->dateFormatHelper;
$dateRangerHelper = $this->dateRangeHelper;

if(!$this->validateUser($user))
return;

$reservationArray = $this->reservationManager->getBy(['bid' => $booking->need('bid')], 'date ASC');

//for single bookins we only have one reservation, so array will have one element, need to get the first
$reservation = reset($reservationArray);

$reservationTimeStart = explode(':', $reservation->need('time_start'));
$reservationTimeEnd = explode(':', $reservation->need('time_end'));

Expand All @@ -78,6 +99,15 @@ public function onCreateSingle(Event $event)
$square->need('name'),
$dateRangerHelper($reservationStart, $reservationEnd));

if($booking->getMeta('repeat')) {
$lastReservation = end($reservationArray);
$reservationEnd = new \DateTime($lastReservation->need('date'));

$message .= "\n".$this->t("This booking repeats:")."\n";
$message .= $this->t($booking->getRepeat())." ".$this->t("until")." ";
$message .= $dateFormatHelper($reservationEnd, \IntlDateFormatter::MEDIUM, \IntlDateFormatter::NONE).".";
}

$playerNames = $booking->getMeta('player-names');

if ($playerNames) {
Expand Down Expand Up @@ -115,14 +145,18 @@ public function onCreateSingle(Event $event)
}
}

public function onCancelSingle(Event $event)
public function onCancel(Event $event)
{
$booking = $event->getTarget();
$reservations = $this->reservationManager->getBy(['bid' => $booking->need('bid')], 'date ASC', 1);
$reservations = $this->reservationManager->getBy(['bid' => $booking->need('bid')], 'date ASC');
$reservation = current($reservations);
$lastReservation = end($reservations);
$square = $this->squareManager->get($booking->need('sid'));
$user = $this->userManager->get($booking->need('uid'));

if(!$this->validateUser($user))
return;

$dateRangerHelper = $this->dateRangeHelper;

$reservationTimeStart = explode(':', $reservation->need('time_start'));
Expand All @@ -131,7 +165,13 @@ public function onCancelSingle(Event $event)
$reservationStart = new \DateTime($reservation->need('date'));
$reservationStart->setTime($reservationTimeStart[0], $reservationTimeStart[1]);

$reservationEnd = new \DateTime($reservation->need('date'));
if($booking->getMeta('repeat')) {
$reservationEnd = new \DateTime($lastReservation->need('date'));
}
else {
$reservationEnd = new \DateTime($reservation->need('date'));
}

$reservationEnd->setTime($reservationTimeEnd[0], $reservationTimeEnd[1]);

$subject = sprintf($this->t('Your %s-booking has been cancelled'),
Expand All @@ -142,6 +182,11 @@ public function onCancelSingle(Event $event)
$square->need('name'),
$dateRangerHelper($reservationStart, $reservationEnd));

if($booking->getMeta('repeat')) {
$message .= "\n".$this->t("This booking was a repeat booking: ");
$message .= $this->t($booking->getRepeat());
}

if ($user->getMeta('notification.bookings', 'true') == 'true') {
$this->userMailService->send($user, $subject, $message);
}
Expand Down