Example #1
0
 /**
  * onCreate event handler
  * @param SeasonApplication $app
  */
 public function onCreate(SeasonApplication $app)
 {
     $id = $this->defaultRoleName;
     try {
         if (!is_string($id)) {
             $role = $this->roleService->getRole($id);
         } else {
             $role = $this->roleService->getRoleName($id);
         }
     } catch (Exceptions\DataErrorException $ex) {
         $this->logger->addError("Application listener - onCreate -  role load failed with - " . $ex->getMessage());
         return;
     }
     $pos = new Position();
     $pos->setGroup($app->getSportGroup());
     $pos->setRole($role);
     $pos->setOwner($app->getOwner());
     $pos->setPublishContact(false);
     $pos->setComment($this->defaultComment);
     try {
         $this->positionService->createPosition($pos);
         if ($this->deleteOldPosition) {
             $this->positionService->deletePositionsWithRole($pos->getOwner(), $pos->getRole());
         }
     } catch (Exceptions\DataErrorException $ex) {
         $this->logger->addError("Application listener - onCreate - savingData failed with - " . $ex->getMessage());
         return;
     }
 }
Example #2
0
 /**
  * Method for handling single onCreate event
  * @param SeasonApplication $app
  * @return void
  * @throws Exceptions\InvalidStateException
  */
 public function onCreate(SeasonApplication $app)
 {
     $amount = null;
     $season = $app->getSeason();
     $group = $app->getSportGroup();
     try {
         $tax = $this->seasonTaxService->getSeasonTaxSG($season, $group);
         if ($tax !== null) {
             $amount = $tax->getMemberShip();
             if (empty($amount) || $amount == 0) {
                 return;
             }
         } else {
             throw new Exceptions\InvalidStateException("Season tax for season {$season} and group {$group} does not exist");
         }
     } catch (Exceptions\DataErrorException $ex) {
         $this->logger->addError("Application listener - onCreate - getSeasonTaxSG failed with - " . $ex->getMessage());
         return;
     }
     $subject = "Application for " . $app->getSportGroup()->getName() . " (" . $app->getSportGroup()->getSportType()->getName() . ") within " . $app->getSeason()->getLabel() . " season";
     $payment = new Payment();
     $payment->setOwner($app->getOwner());
     $payment->setSeason($app->getSeason());
     $payment->setSubject($subject);
     $payment->setAmount($amount);
     $payment->setDueDate($this->paymentService->getDefaultDueDate());
     $payment->setOrderedDate(new DateTime());
     $payment->setEditor($app->getEditor());
     $payment->setStatus(PaymentStatus::NOT_YET);
     $payment->setVs($this->paymentService->generateVs($payment));
     $payment->setPublicNote("");
     $payment->setProtectedNote("");
     try {
         $this->paymentService->createPayment($payment);
         $app->setPayment($payment);
         $this->seasonApplicationService->updateSeasonApplication($app);
     } catch (Exceptions\DataErrorException $ex) {
         $this->logger->addError("Application listener - onCreate - savingData failed with - " . $ex->getMessage());
         return;
     }
 }
Example #3
0
 public function updateSeasonApplicationHandle(ArrayHash $values)
 {
     $app = new SeasonApplication((array) $values);
     try {
         $app->setEditor($this->getUser()->getIdentity());
         $this->getSeasonApplicationService()->updateSeasonApplication($app);
     } catch (Exceptions\DataErrorException $ex) {
         $this->handleDataSave($app->getId(), "default", $ex);
     }
     $this->redirect("default");
 }
 public function updateSeasonApplication(SeasonApplication $app)
 {
     if ($app === null) {
         throw new Exceptions\NullPointerException("Argument SeasonApplication cannot be null", 0);
     }
     try {
         $this->entityManager->beginTransaction();
         $appDb = $this->seasonApplicationDao->find($app->getId(), false);
         if ($appDb !== null) {
             $app->setEnrolledTime($appDb->getEnrolledTime());
             $appDb->fromArray($app->toArray());
             $this->applicationSeasonTypeHandle($appDb);
             $this->applicationPaymentTypeHandle($appDb);
             $this->applicationGroupTypeHandle($appDb);
             $this->applicationOwnerTypeHandle($appDb);
             $this->applicationEditorTypeHandle($appDb);
             $appDb->setUpdated(new DateTime());
             $this->entityManager->merge($appDb);
             $this->entityManager->flush();
         }
         $this->entityManager->commit();
         $this->invalidateEntityCache($appDb);
         $this->onUpdate(clone $appDb);
     } catch (DuplicateEntryException $ex) {
         $this->logWarning($ex);
         throw new Exceptions\DuplicateEntryException($ex->getMessage(), Exceptions\DuplicateEntryException::SEASON_APPLICATION, $ex->getPrevious());
     } catch (\Exception $ex) {
         $this->logError($ex->getMessage());
         throw new Exceptions\DataErrorException($ex->getMessage(), $ex->getCode(), $ex->getPrevious());
     }
 }
 public function notifyNewSeasonApplication(SeasonApplication $app)
 {
     $u = $app->getOwner();
     $subjKey = "systemModule.notification.newApplication.subject";
     $bodyKey = "systemModule.notification.newApplication.body";
     $subject = $this->translator->translate($subjKey, null, ["host" => $this->getHostName()]);
     $type = $app->getSportGroup()->getSportType();
     $t = "";
     if ($type !== NULL) {
         $t = " ({$type})";
     }
     $body = $this->translator->translate($bodyKey, null, ["name" => $u->getName(), "surname" => $u->getSurname(), "season" => $app->getSeason()->getLabel(), "group" => $app->getSportGroup()->getName() . $t]);
     $mail = new Message();
     $mail->setFrom($this->getSenderEmail())->setSubject($subject)->setBody($body)->addTo($u->getContact()->getEmail());
     $this->send($mail);
 }