/** * @param OfferingInterface $offering * @param array $originalProperties */ protected function createOrUpdateAlertForUpdatedOffering(OfferingInterface $offering, array $originalProperties) { $updatedProperties = $offering->getAlertProperties(); $changeTypes = []; if ($updatedProperties['startDate'] !== $originalProperties['startDate']) { $changeTypes[] = AlertChangeTypeInterface::CHANGE_TYPE_TIME; } if ($updatedProperties['endDate'] !== $originalProperties['endDate']) { $changeTypes[] = AlertChangeTypeInterface::CHANGE_TYPE_TIME; } if ($updatedProperties['room'] !== $originalProperties['room']) { $changeTypes[] = AlertChangeTypeInterface::CHANGE_TYPE_LOCATION; } $instructorIdsDiff = array_merge(array_diff($updatedProperties['instructors'], $originalProperties['instructors']), array_diff($originalProperties['instructors'], $updatedProperties['instructors'])); if (!empty($instructorIdsDiff)) { $changeTypes[] = AlertChangeTypeInterface::CHANGE_TYPE_INSTRUCTOR; } $instructorGroupIdsDiff = array_merge(array_diff($updatedProperties['instructorGroups'], $originalProperties['instructorGroups']), array_diff($originalProperties['instructorGroups'], $updatedProperties['instructorGroups'])); if (!empty($instructorGroupIdsDiff)) { $changeTypes[] = AlertChangeTypeInterface::CHANGE_TYPE_INSTRUCTOR; } $learnerIdsDiff = array_merge(array_diff($updatedProperties['learners'], $originalProperties['learners']), array_diff($originalProperties['learners'], $updatedProperties['learners'])); if (!empty($learnerIdsDiff)) { $changeTypes[] = AlertChangeTypeInterface::CHANGE_TYPE_LEARNER_GROUP; } $learnerGroupIdsDiff = array_merge(array_diff($updatedProperties['learnerGroups'], $originalProperties['learnerGroups']), array_diff($originalProperties['learnerGroups'], $updatedProperties['learnerGroups'])); if (!empty($learnerGroupIdsDiff)) { $changeTypes[] = AlertChangeTypeInterface::CHANGE_TYPE_LEARNER_GROUP; } if (empty($changeTypes)) { return; } array_unique($changeTypes); $alertManager = $this->container->get('ilioscore.alert.manager'); $alertChangeTypeManager = $this->container->get('ilioscore.alertchangetype.manager'); $alert = $alertManager->findOneBy(['dispatched' => false, 'tableName' => 'offering', 'tableRowId' => $offering->getId()]); if (!$alert) { $recipient = $offering->getSchool(); if (!$recipient) { return; // SOL. } $alert = $alertManager->create(); $alert->addRecipient($recipient); $alert->setTableName('offering'); $alert->setTableRowId($offering->getId()); $alert->addInstigator($this->getUser()); } foreach ($changeTypes as $type) { $changeType = $alertChangeTypeManager->findOneBy(['id' => $type]); if ($changeType && !$alert->getChangeTypes()->contains($changeType)) { $alert->addChangeType($changeType); } } $alertManager->update($alert, true, (bool) $alert->getId()); }