/** * @param float $cost * @param Event $event * @param User $user * @param DateTime $now * * @return number */ protected function getVariation($cost, Event $event, User $user, DateTime $now) { $variation = $cost * $event->getRegistrationInfo()->getCostVariation() / 100; if (!$this->talkManager->eventHasAnyApprovedTalk($event) || $event->isSpeakerPromotionalPeriod($now) && $this->talkManager->userHasAnyTalk($user, $event)) { return $variation * -1; } if ($event->isLateRegistrationPeriod($now)) { return $variation; } }
/** * @param Event $event * @param User $user * @param boolean $isStudent * @param string $registrationType * @return Attendee */ public function create(Event $event, User $user, $isStudent, $registrationType) { $attendee = new Attendee(); $attendee->setEvent($event); $attendee->setUser($user); $attendee->setStatus(Attendee::WAITING_PAYMENT); $attendee->setArrived(false); $attendee->setStudentRegistration($isStudent); $attendee->setRegistrationType($registrationType); $attendee->setCreationTime(new DateTime()); if ($this->talkService->userHasAnyApprovedTalk($user, $event)) { $attendee->setStatus(Attendee::PAYMENT_NOT_NECESSARY); $attendee->setRegistrationType(Attendee::WORKSHOPS_AND_TALKS); } return $attendee; }
/** * @param Event $event * @return string */ protected function getItemDescription(Event $event) { if (!$this->talkService->eventHasAnyApprovedTalk($event)) { return 'Inscrição Antecipada - ' . $event->getName(); } if ($event->isLateRegistrationPeriod(new \DateTime())) { return 'Inscrição Tardia - ' . $event->getName(); } return 'Inscrição Regular - ' . $event->getName(); }
/** * @param int $id * @param boolean $verifyOwnership * @return string */ public function getById($id, $verifyOwnership = true) { $talk = $this->talkManager->findById($id, $verifyOwnership ? $this->authService->getLoggedUser() : null); if ($talk === null) { $response = array('error' => 'Não foi possível encontrar a submissão de trabalho.'); } else { $response = array('id' => $talk->getId(), 'title' => $talk->getTitle(), 'type' => array('id' => $talk->getType()->getId(), 'description' => $talk->getType()->getDescription()), 'shortDescription' => $talk->getShortDescription(), 'longDescription' => $talk->getLongDescription(), 'complexity' => $talk->getComplexity(), 'tags' => $talk->getTags(), 'approved' => $talk->getApproved(), 'creationTime' => $talk->getCreationTime()->format(\DateTime::RFC3339)); } return json_encode($response); }
/** * @param int $talkId * @param string $likes * @throws \InvalidArgumentException * @return string */ public function create($talkId, $likes) { try { $user = $this->authService->getLoggedUser(); $talk = $this->talkManager->findById($talkId); if ($talk === null) { throw new \InvalidArgumentException('Submissão não encontrada'); } $opinion = $this->opinionManager->create($user, $talk, $likes); $likesCount = $this->opinionManager->getLikesCount($talk->getEvent(), $user); return json_encode(array('data' => array('id' => $opinion->getId(), 'likesCount' => $likesCount))); } catch (\InvalidArgumentException $error) { return json_encode(array('error' => $error->getMessage())); } catch (\PDOException $error) { return json_encode(array('error' => 'Não foi possível salvar os dados na camada de persistência.')); } catch (\Exception $error) { return json_encode(array('error' => 'Erro interno no processamento da requisição.')); } }
/** * @test * @covers PHPSC\Conference\Domain\Service\RegistrationCostCalculator::__construct * @covers PHPSC\Conference\Domain\Service\RegistrationCostCalculator::getBaseCost * @covers PHPSC\Conference\Domain\Service\RegistrationCostCalculator::getVariation * @covers PHPSC\Conference\Domain\Service\RegistrationCostCalculator::getCost * @covers PHPSC\Conference\Domain\Service\RegistrationCostCalculator::getStudentDiscount */ public function getCostShouldApplyDiscountWhenAttendeeHasACoupon() { $this->event->expects($this->any())->method('hasAttendeeRegistration')->willReturn(true); $discount = $this->getMock(DiscountCoupon::class); $discount->expects($this->any())->method('applyDiscountTo')->willReturn(50); $this->attendee->expects($this->any())->method('isStudentRegistration')->willReturn(false); $this->attendee->expects($this->any())->method('canAttendTalksDayOnly')->willReturn(false); $this->attendee->expects($this->any())->method('getDiscount')->willReturn($discount); $this->talkManager->expects($this->any())->method('eventHasAnyApprovedTalk')->willReturn(true); $this->event->expects($this->any())->method('isLateRegistrationPeriod')->willReturn(false); $this->assertEquals(50, $this->calculator->getCost($this->attendee, new DateTime())); }
/** * @return boolean */ public function isSpeakerWithApprovedTalks() { return $this->talkService->userHasAnyApprovedTalk($this->user, $this->event); }