Example #1
0
 /**
  * @param string $attribute
  * @param OfferingInterface $offering
  * @param TokenInterface $token
  * @return bool
  */
 protected function voteOnAttribute($attribute, $offering, TokenInterface $token)
 {
     $session = $offering->getSession();
     if (!$session) {
         return false;
     }
     // grant perms based on the owning session
     return parent::voteOnAttribute($attribute, $session, $token);
 }
Example #2
0
 /**
  * @param string $attribute
  * @param OfferingInterface $offering
  * @param UserInterface|null $user
  * @return bool
  */
 protected function isGranted($attribute, $offering, $user = null)
 {
     // grant perms based on the owning session
     return parent::isGranted($attribute, $offering->getSession(), $user);
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function deleteOffering(OfferingInterface $offering)
 {
     $offering->setDeleted(true);
     $this->updateOffering($offering);
 }
Example #4
0
 /**
  * @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());
 }