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();
 }
 /**
  * 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);
 }
Ejemplo n.º 3
0
 /**
  * @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;
 }