public function getPossibleDayPricesForAnnouncement(Advertisement $announcement) { $zonePrices = $this->getActiveZonesPrices(); $expireDate = $announcement->getExpireDate(); $toExpirationInterval = $expireDate->diff(new \DateTime()); $possiblePrices = array(); $percentageDiscount = $this->getPercentageDiscountForUser($announcement->getAdvertiser()); foreach ($zonePrices as $zoneId => $defaultPrice) { $calculatedPrice = ($defaultPrice - $defaultPrice * $percentageDiscount) * $toExpirationInterval->days; $possiblePrices[$zoneId] = $this->getRoundedPrice($calculatedPrice); } return $possiblePrices; }
private function accessDeniedWhenInvalidUser(Advertisement $announcement = null) { /** @var $user \Hyper\AdsBundle\Entity\Advertiser */ $user = $this->getUser(); if (null === $user) { throw new AccessDeniedException('Only logged in user can perform this action'); } if (null !== $announcement && !$user->hasRole('ROLE_ADMIN') && $announcement->getAdvertiser() != $user) { throw new AccessDeniedException("You can edit only your own advertisements when you don't have admin privileges"); } }
/** * @param \Hyper\AdsBundle\Entity\Advertisement $entity * @return \Swift_Message */ private function prepareMessage(Advertisement $entity) { $message = new \Swift_Message(); $messageContent = $this->templating->render('HyperAdsBundle:Mailing:postPersistAnnouncement.html.twig', array('announcement' => $entity)); $message->setBody($messageContent, 'text/html', 'utf-8'); $message->setFrom($this->mailerFromEmail, $this->mailerFromName); $message->setSubject($this->translator->trans('announcement.edited', array('%user%' => $entity->getAdvertiser()->getUsernameCanonical(), '%title%' => $entity->getTitle()), 'HyperAdsBundle')); foreach ($this->mailingPersonList as $person) { $message->addTo($person); } return $message; }
private function throwUnlessValidUser(Advertisement $advertisement) { if ($this->getUser()->getId() !== $advertisement->getAdvertiser()->getId()) { throw new AccessDeniedException($this->trans('access.denied')); } }