Ejemplo n.º 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;
 }
Ejemplo n.º 2
0
 public function createOrUpdate(\AppBundle\DRV_Import\Athlete $athlete, LoggerInterface $logger)
 {
     /** @var \AppBundle\Entity\Competitor $dbItem */
     $dbItem = null;
     $gotError = false;
     try {
         $this->findByAthlete($athlete, $logger);
     } catch (NonUniqueResultException $e) {
         $gotError = true;
     }
     if (null != $dbItem) {
         $logger->debug("Found competitor with id [{$dbItem->getId()}] for DRV-ID [{$athlete->drv_id}]");
         // check and update if necessary
         $updates = false;
         if ($dbItem->getLastName() != $athlete->lastname) {
             $dbItem->setLastName($athlete->lastname);
             $updates = true;
         }
         if ($dbItem->getFirstName() != $athlete->firstname) {
             $dbItem->setFirstName($athlete->firstname);
             $updates = true;
         }
         if ($dbItem->getYearOfBirth() != $athlete->yearofbirth) {
             $dbItem->setYearOfBirth($athlete->yearofbirth);
             $updates = true;
         }
         if ($athlete->is_female && $dbItem->getGender() != Competitor::GENDER_FEMALE) {
             $dbItem->setGender(Competitor::GENDER_FEMALE);
         } elseif (!$athlete->is_female && $dbItem->getGender() != Competitor::GENDER_MALE) {
             $dbItem->setGender(Competitor::GENDER_MALE);
         }
         if ($dbItem->getDrvId() != $athlete->drv_id) {
             $dbItem->setDrvId($athlete->drv_id);
         }
         if ($updates) {
             $logger->debug("Updating competitor with id [{$dbItem->getId()}]");
             $this->getEntityManager()->persist($dbItem);
         }
     } else {
         if (!$gotError) {
             $logger->debug("Found nothing. Create a new competitor.");
             // create competitor
             $dbItem = new Competitor();
             $dbItem->setLastName($athlete->lastname)->setFirstName($athlete->firstname)->setYearOfBirth($athlete->yearofbirth)->setGender($athlete->is_female ? Competitor::GENDER_FEMALE : Competitor::GENDER_MALE)->setDrvId($athlete->drv_id);
             $this->getEntityManager()->persist($dbItem);
         } else {
             throw new NonUniqueResultException("got multiple results for competitor: [{$athlete->lastname}, {$athlete->firstname}, {$athlete->yearofbirth}]");
         }
     }
     return $dbItem;
 }
Ejemplo n.º 3
0
 /**
  * Creates a new Membership entity.
  *
  * @Route("/new/{competitor}", name="membership_new")
  * @Method({"GET", "POST"})
  * @Security("has_role('ROLE_REGISTRATION')")
  */
 public function newAction(Request $request, Competitor $competitor)
 {
     $membership = new Membership();
     $em = $this->getDoctrine()->getManager();
     // find all clubs where the given competitor is _not_ a member
     $myClubs = $competitor->getMemberships()->map(function ($membership) {
         return $membership->getClub()->getId();
     });
     $clubQb = $em->getRepository('AppBundle:Club')->createQueryBuilder('c');
     if (0 < count($myClubs)) {
         $clubQb = $clubQb->where('c.id NOT IN (:clubs)')->setParameter('clubs', $myClubs);
     }
     $clubQ = $clubQb->getQuery();
     $clubs = $clubQ->getResult();
     $form = $this->createForm('AppBundle\\Form\\MembershipType', $membership, array('competitors' => array($competitor), 'clubs' => $clubs));
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid()) {
         $em->persist($membership);
         $em->flush();
         $this->addFlash('notice', 'Neue Mitgliedschaft wurde angelegt!');
         return $this->redirectToRoute('competitor_show', array('id' => $competitor->getId()));
     }
     return $this->render('membership/new.html.twig', array('membership' => $membership, 'person' => $competitor, 'form' => $form->createView()));
 }
Ejemplo n.º 4
0
 /**
  * Creates a form to delete a Competitor entity.
  *
  * @param Competitor $competitor The Competitor entity
  *
  * @return \Symfony\Component\Form\Form The form
  */
 private function createDeleteForm(Competitor $competitor)
 {
     return $this->createFormBuilder()->setAction($this->generateUrl('competitor_delete', array('id' => $competitor->getId())))->setMethod('DELETE')->getForm();
 }