Пример #1
0
 public function createOrUpdate(Competitor $competitor, $drvClubId, \DateTime $dateTime, LoggerInterface $logger)
 {
     /** @var Membership $dbItem */
     $dbItem = null;
     /** @var Membership $m */
     foreach ($competitor->getMemberships() as $m) {
         if ($m->getClub()->getDrvId() == $drvClubId) {
             if (null != $m->getSince() && $m->getSince() < $dateTime) {
                 if (null != $m->getUntil() && $m->getUntil() > $dateTime) {
                     // The membership has an end, but this import falls into the active period.
                     $dbItem = $m;
                 } elseif (null == $m->getUntil()) {
                     // no ending
                     $dbItem = $m;
                 }
             }
         }
     }
     // If no matching membership was found, create one
     if (null == $dbItem) {
         $club = $this->getEntityManager()->getRepository('AppBundle:Club')->findOneByDrvId($drvClubId);
         if (null != $club) {
             $dbItem = new Membership();
             $dbItem->setPerson($competitor)->setClub($club)->setSince($dateTime);
             $this->getEntityManager()->persist($dbItem);
             $logger->info("Created new membership for " . "[{$competitor->getLastName()}, {$competitor->getFirstName()}, {$competitor->getId()}]");
         } else {
             $message = "Found no club with DRV-ID {$drvClubId}! No membership created for " . "[{$competitor->getLastName()}, {$competitor->getFirstName()}, {$competitor->getId()}]";
             $logger->warning($message);
             throw new \Exception($message);
         }
     }
     return $dbItem;
 }
 /**
  * Displays a form to create a new Membership entity.
  *
  * @Route("/new/{clientId}", name="membership_new")
  * @Method("GET")
  * @Template()
  */
 public function newAction($clientId = null)
 {
     $membership = new Membership();
     if (null != $clientId) {
         $em = $this->getDoctrine()->getManager();
         $client = $em->getRepository('AppBundle:Client')->find($clientId);
         if ($client) {
             $membership->setClient($client);
         }
     }
     $form = $this->createCreateForm($membership);
     return array('entity' => $membership, 'form' => $form->createView());
 }
Пример #3
0
 /**
  * Creates a form to delete a Membership entity.
  *
  * @param Membership $membership The Membership entity
  *
  * @return \Symfony\Component\Form\Form The form
  */
 private function createDeleteForm(Membership $membership)
 {
     return $this->createFormBuilder()->setAction($this->generateUrl('membership_delete', array('id' => $membership->getId())))->setMethod('DELETE')->getForm();
 }
Пример #4
0
 /**
  * @param Request $request
  * @param Membership $membership
  * @param Document $document
  * @return Response
  *
  * @Route("/member/membership/{membership}/document/{document}/delete",
  *     name="app_member_membership_document_delete",
  *     methods={"GET","POST"},
  *     requirements={"membership"="\d+","document"="\d+"})
  */
 public function documentDeleteAction(Request $request, Membership $membership, Document $document)
 {
     // Delete form
     $formDelete = $this->createForm(DocumentDeleteType::class, $document);
     $formDelete->handleRequest($request);
     if ($formDelete->isSubmitted() && $formDelete->isValid()) {
         // Delete document
         if ($document == $membership->getMedicalCertificate()) {
             $membership->setMedicalCertificate(null);
         } elseif ($document == $membership->getRegistrationForm()) {
             $membership->setRegistrationForm(null);
         }
         $dm = $this->get('app.document_manager');
         $dm->delete($document);
         // Flash message
         $this->addFlash('success', $this->get('translator')->trans('document_delete.success.deleted', array(), 'member'));
         // Redirect
         return $this->redirectToRoute('app_member_membership_edit', ['membership' => $membership->getId()]);
     }
     // Render
     return $this->render('member/membership/document/delete.html.twig', ['document' => $document, 'formDelete' => $formDelete->createView(), 'membership' => $membership]);
 }