private function setRegistrationStatus(Registration $registration, $status) { $registration->setStatus($status); $em = $this->getDoctrine()->getManager(); $em->persist($registration); $em->flush(); }
/** * Perform a single access check operation on a given attribute, object and (optionally) user * It is safe to assume that $attribute and $object's class pass supportsAttribute/supportsClass * $user can be one of the following: * a UserInterface object (fully authenticated user) * a string (anonymously authenticated user). * * @param string $attribute * @param Registration $object * @param UserInterface|string $user * * @return bool */ protected function isGranted($attribute, $object, $user = null) { if (!$user instanceof UserInterface) { return false; } return $user == $object->getUser(); }
public function setTime(Registration $registration, $timestamp, $checkpoint, LoggerInterface $logger = null) { if (is_null($checkpoint) || false == trim($checkpoint)) { // PHP evaluates an empty string to false throw new \InvalidArgumentException('Checkpoint must not be empty!'); } elseif (is_null($timestamp) || false == trim($timestamp)) { // PHP evaluates an empty string to false throw new \InvalidArgumentException('Time must not be empty!'); } /** @var EntityManager $em */ $em = $this->getEntityManager(); $checkpoint = trim($checkpoint); // expected format of the timestamp is unix timestamp plus microseconds $dtime = \DateTime::createFromFormat("U.u", $timestamp); // check validity of the given timestamp // if parsing did not work, the method returns false (else object) if ($dtime === false || false === $dtime->getTimestamp()) { throw new \InvalidArgumentException('Time parameter is not a valid timestamp!'); } // check if the checkpoint does not exist for this registration /** @var Timing $t */ foreach ($registration->getTimings() as $t) { if ($t->getCheckpoint() == $checkpoint) { throw new \InvalidArgumentException('There is already a timing for this checkpoint!'); } } // validate if setting a checkpoint makes sense if ($checkpoint == Registration::CHECKPOINT_START) { if (!$registration->isCheckedIn()) { throw new \InvalidArgumentException($registration->getId() . ': ' . "Competitors on lane {$registration->getLane()} are not checked in for starting!"); } } else { // some other checkpoint after the starting line if (!$registration->isStarted()) { throw new \InvalidArgumentException('Competitors are not on track!'); } } // store time and checkpoint in database $timing = new Timing(); $timing->setRegistration($registration)->setTime($dtime)->setCheckpoint($checkpoint); $em->persist($timing); if (!is_null($logger)) { $logger->debug("stored {$registration->getId()} with timestamp {$timestamp} for checkpoint {$checkpoint}"); } if ($checkpoint == Registration::CHECKPOINT_START) { $registration->setStarted(); $em->persist($registration); } elseif ($checkpoint == Registration::CHECKPOINT_FINISH) { $registration->setFinished(); $em->persist($registration); } $em->flush(); }
/** * @return Registration */ public function getCurrentRegistration() { $user = $this->getUser(); $registration = $this->container->get('ritsiga.repository.registration')->findOneBy(['user' => $user]); if (!$registration) { $convention = $this->getCurrentSite(); $registration = new Registration(); $registration->setConvention($convention); $registration->setUser($user); $registration->setTaxdata(TaxData::copyFromUniversity($this->getUser()->getUniversity())); } return $registration; }
public function createOrUpdate(Boat $boat, Race $race, LoggerInterface $logger) { /** @var Team $dbItem */ $dbItem = null; // first try to find by ID if (!empty($boat->id)) { $dbItem = $this->findOneByDrvId($boat->id); } // if this does not help, do a fuzzy search if (null == $dbItem) { // TODO search by club + representative + name + race? } if (null != $dbItem) { // TODO updating $logger->warning("Implementation missing for updating teams in TeamRepository::createOrUpdate"); } else { // create new team $em = $this->getEntityManager(); $dbItem = new Team(); /** @var \AppBundle\Entity\Club $club */ $club = $this->getEntityManager()->getRepository('AppBundle:Club')->findOneByDrvId($boat->club_id); if (null == $club) { $message = "Found no club with DRV-ID {$boat->club_id}! No team created for " . "[{$boat->name}, {$boat->id}]"; $logger->warning($message); throw new \Exception($message); } if ($race->getSections()->isEmpty()) { /** @var \AppBundle\Repository\RaceRepository $raceRepo */ $raceRepo = $this->getEntityManager()->getRepository('AppBundle:Race'); // create initial section $raceRepo->createSection($race, 1, $logger); } /** @var \AppBundle\Entity\RaceSection $raceSection */ $raceSection = $race->getSections()->last(); if (null == $raceSection) { $message = "Found no section for race {$race->getId()}! No team created for " . "[{$boat->name}, {$boat->id}]"; $logger->warning($message); throw new \Exception($message); } // save to DB - bugfix: lane for section is always 1 (because section does not exist yet) $em->flush(); $dbItem->setClub($club)->setDrvId($boat->id)->setName($boat->name); $em->persist($dbItem); /** @var \AppBundle\Repository\RegistrationRepository $regRepo */ $regRepo = $this->getEntityManager()->getRepository('AppBundle:Registration'); $section = new Registration(); $section->setSection($raceSection)->setLane($regRepo->getNextLaneForSection($raceSection))->setTeam($dbItem); $em->persist($section); } return $dbItem; }
public function forwardAction(ProcessContextInterface $context) { $request = $this->container->get('request_stack')->getCurrentRequest(); $user = $this->get('security.token_storage')->getToken()->getUser(); $siteManager = $this->container->get('ritsiga.site.manager'); $convention = $siteManager->getCurrentSite(); $em = $this->getDoctrine()->getManager(); $registration = new Registration(); $registration->setConvention($convention); $form = $this->createForm(new ResponsibleType(), $registration); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $registration->setUser($user); $em->persist($registration); $em->flush(); $this->addFlash('warning', $this->get('translator')->trans('Your registration has been saved, you can now add registrations')); return $this->complete(); } }
/** * @Given /^que existen las inscripciones:$/ */ public function createStudentDelegation(TableNode $tableNode) { foreach ($tableNode->getHash() as $registrationHash) { $user = $this->getEntityManager()->getRepository('AppBundle:User')->findOneBy(['username' => $registrationHash['usuario']]); $convention = $this->getEntityManager()->getRepository('AppBundle:Convention')->findOneBy(['slug' => $registrationHash['asamblea']]); $registration = new Registration(); $registration->setUser($user); $registration->setName($registrationHash['nombre']); $registration->setPosition($registrationHash['cargo']); $registration->setConvention($convention); $registration->setStatus($registrationHash['estado']); $this->getEntityManager()->persist($registration); } $this->getEntityManager()->flush(); }
/** * Genera una factura para la inscripción indicada. * * @param Registration $registration * @param $filename * * @return string */ public function generateInvoiceDraft(Registration $registration, &$filename) { $filename = sprintf('factura-%s-%d-%s.pdf', $registration->getConvention()->getSlug(), $registration->getId(), $registration->getUser()->getUniversity()->getSlug()); $html = $this->twig->render('themes/invoice/invoice_draft.html.twig', array('registration' => $registration, 'fecha' => new \DateTime('today'))); return $this->loggableGenerator->getOutputFromHtml($html); }
/** * Reset a team (registration) after marking it as "not at start", so that a new registration is possible. * * @see notAtStartAction * * @Route("/team/{registration}/resetNas", name="race_start_reset") * @Method("GET") * @Security("has_role('ROLE_REGISTRATION')") */ public function resetNotAtStart(Request $request, Registration $registration) { $em = $this->getDoctrine()->getManager(); $registration->undoCancelled(); $em->persist($registration); $em->flush(); return $this->redirect($request->headers->get('referer')); }
/** * @Route("/descargar_factura/{registration}", name="invoice_download") */ public function downloadInvoiceAction(Registration $registration) { $this->get('kernel')->getRootDir(); $fileToDownload = $this->get('kernel')->getRootDir() . '/../private/documents/invoices/' . $registration->getId() . '.pdf'; $response = new BinaryFileResponse($fileToDownload); $response->trustXSendfileTypeHeader(); $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $registration->getConvention()->getName() . '_factura.pdf', iconv('UTF-8', 'ASCII//TRANSLIT', $registration->getId())); return $response; }
public function singlePeriodsAction(Registration $registration) { $app = new AppExtension(); $myTimings = array(); /** @var string $startPoint */ $startPoint = null; /** @var \DateTime $startTime */ $startTime = null; /** @var Timing $timing */ foreach ($registration->getTimings() as $timing) { if (!is_null($startPoint)) { // calculate delta $myTimeD = doubleval($timing->getTime()->format('U.u')); $startTimeD = doubleval($startTime->format('U.u')); $delta = abs($myTimeD - $startTimeD); $deltaString = $app->timeString($delta); $myTimings[] = sprintf('%s - %s: <strong>%s</strong>', $startPoint, $timing->getCheckpoint(), $deltaString); } $startPoint = $timing->getCheckpoint(); $startTime = $timing->getTime(); } return new Response(implode('<br>', $myTimings)); }
/** * Search for the next section with free lanes. * * @param Registration $registration * @param \Closure $compareFunction for comparing the number of the inspected lane with the best match * @return RaceSection | null */ private function getNextPossibleSection(Registration $registration, $compareFunction) { $mySectionNumber = $registration->getSection()->getNumber(); $maxStarters = $registration->getSection()->getRace()->getMaxStarterPerSection(); $sections = array(); /** @var RaceSection $section */ foreach ($registration->getSection()->getRace()->getSections() as $section) { if (!$section->isStarted() && !$section->isFinished()) { // check for free spaces if ($section->getValidRegistrations()->count() < $maxStarters) { $sections[] = $section; } } } /** @var RaceSection $next */ $next = null; foreach ($sections as $section) { if ($compareFunction($section->getNumber(), $mySectionNumber)) { if (is_null($next)) { $next = $section; } else { // search the lowest section of those that are higher if (!$compareFunction($next->getNumber(), $section->getNumber())) { $next = $section; } } } } return $next; }
protected function configureListFields(ListMapper $listMapper) { $listMapper->add('id', null, ['label' => 'label.id_transfer'])->add('user.university', null, ['label' => 'label.university'])->add('user.college', null, ['label' => 'label.college'])->add('status', 'choice', ['label' => 'label.status', 'choices' => Registration::getStatusArrayChoice(), 'catalogue' => 'messages'])->add('arrivaldate', null, ['label' => 'label.arrivaldate'])->add('departuredate', null, ['label' => 'label.departuredate'])->add('_action', 'actions', ['actions' => ['edit' => [], 'show' => []]]); }