Skip to content

Commit

Permalink
added events to the notification of updated/new week in mattermost
Browse files Browse the repository at this point in the history
  • Loading branch information
IrisOlfermann committed Sep 3, 2024
1 parent 721b1e6 commit 8340e2b
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 17 deletions.
21 changes: 11 additions & 10 deletions src/Mealz/MealBundle/Controller/MealAdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,16 +204,17 @@ private function handleDay(array $day): void
$dayEntity->setEnabled($day['enabled']);
}
$this->setLockParticipationForDay($dayEntity, $day);

$eventCollection = $day['events'];
foreach ($dayEntity->getEvents() as $event) {
$this->em->remove($event); // Hier wird sichergestellt, dass die Events tatsächlich aus der Datenbank gelöscht werden.
}
$dayEntity->removeEvents();
$this->em->flush(); // Alle Änderungen in die Datenbank schreiben.
foreach ($eventCollection as $event) {
$this->logger->info('Event '. implode($event));
$this->handleEventArr($event, $dayEntity);
if(array_key_exists('events', $day)){
$eventCollection = $day['events'];
foreach ($dayEntity->getEvents() as $event) {
$this->em->remove($event); // Hier wird sichergestellt, dass die Events tatsächlich aus der Datenbank gelöscht werden.
}
$dayEntity->removeEvents();
$this->em->flush(); // Alle Änderungen in die Datenbank schreiben.
foreach ($eventCollection as $event) {
$this->logger->info('Event '. implode($event));
$this->handleEventArr($event, $dayEntity);
}
}

$mealCollection = $day['meals'];
Expand Down
41 changes: 34 additions & 7 deletions src/Mealz/MealBundle/Message/WeeklyMenuMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function getContent(): string
],
'messages'
);
$tableHeader = "\n|Day|Meals|\n|:-----|:-----|\n";
$tableHeader = "\n|Day|Meals|Events|\n|:-----|:-----|\n";
$body = $this->getDishesByWeek($this->week);
$footer = $this->translator->trans('week.notification.footer.default', [], 'messages');
}
Expand Down Expand Up @@ -73,12 +73,8 @@ private function getDishesByDay(Day $day): string
{
$body = $day->getDateTime()->format('l') . ' | ';

if (!$day->isEnabled() || (0 === count($day->getMeals()))) {
return $body . $this->translator->trans('week.notification.content.no_meals', [], 'messages') . ' | ';
}

$dishes = [];

$events = [];
/** @var Meal $meal */
foreach ($day->getMeals() as $meal) {
if ($meal->isCombinedMeal()) {
Expand All @@ -94,8 +90,27 @@ private function getDishesByDay(Day $day): string
$dishes[$dish->getTitleEn()] = [];
}
}
/** @var Event $event */
foreach($day->getEvents() as $event){

Check failure on line 94 in src/Mealz/MealBundle/Message/WeeklyMenuMessage.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis

UndefinedDocblockClass

src/Mealz/MealBundle/Message/WeeklyMenuMessage.php:94:38: UndefinedDocblockClass: Docblock-defined class, interface or enum named App\Mealz\MealBundle\Message\Event does not exist (see https://psalm.dev/200)
$events[$event->getEvent()->getTitle()] = $event->getEvent()->getTitle();

Check failure on line 95 in src/Mealz/MealBundle/Message/WeeklyMenuMessage.php

View workflow job for this annotation

GitHub Actions / Static Code Analysis

UndefinedDocblockClass

src/Mealz/MealBundle/Message/WeeklyMenuMessage.php:95:21: UndefinedDocblockClass: Docblock-defined class, interface or enum named App\Mealz\MealBundle\Message\Event does not exist (see https://psalm.dev/200)
}

return $body . $this->toString($dishes);
if (!$day->isEnabled() || (0 === count($day->getMeals()))) {
$body = $body . $this->translator->trans('week.notification.content.no_meals', [], 'messages') . ' | ';
if((0 === count($day->getEvents()))){
return $body . $this->translator->trans('week.notification.content.no_events', [], 'messages') . ' | ';
} else{
return $body . $this->eventsToString($events);
}
}
elseif(!$day->isEnabled() || (0 === count($day->getEvents()))) {
$body = $body . $this->toString($dishes);
return $body . $this->translator->trans('week.notification.content.no_events', [], 'messages') . ' | ';
}
else{
$body = $body . $this->toString($dishes);
return $body . $this->eventsToString($events);
}
}

/**
Expand All @@ -113,6 +128,18 @@ private function toString(array $dishes): string
}
}

return implode(', ', $result) . ' |';
}
/**
* @param array<string, list<string>> $events
*/
private function eventsToString(array $events): string
{
$result = [];
foreach($events as $eventTitle) {
$result[$eventTitle] = '**' . $eventTitle . '**';
}

return implode(', ', $result) . ' |';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ week:
default: Log into your account at https://meals.aoe.com/ to get it!
content:
no_meals: No offers for this day
no_events: No events on this day

entity:
added: '%entityName% has been added.'
Expand Down
1 change: 1 addition & 0 deletions src/Resources/src/components/dashboard/EventData.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ async function handleClick(event: EventParticipation) {
if (event?.isParticipating === undefined || event?.isParticipating === false) {
await joinEvent(props.day.date.date, event?.participationId);
event.isParticipating = true;
event.participations = event.participations +1;
} else {
await leaveEvent(props.day.date.date,event?.participationId);
event.isParticipating = false;
Expand Down

0 comments on commit 8340e2b

Please sign in to comment.