Example #1
0
 /**
  * @param Restaurant $restaurant
  * @return mixed
  */
 public function setOrderAsSent(Restaurant $restaurant)
 {
     $date = new \DateTime();
     $date->setTime(0, 0, 0);
     $qb = $this->createQueryBuilder('o');
     $query = $qb->update()->set('o.sent', '?1')->where('o.date = :date')->andWhere('o.restaurant = :restaurantId')->setParameter('1', true)->setParameter('date', $date)->setParameter('restaurantId', $restaurant->getId())->getQuery();
     return $query->execute();
 }
Example #2
0
 /**
  * @param Restaurant $restaurant
  * @return bool
  */
 public function validateRestaurant(Restaurant $restaurant)
 {
     if (null === $restaurant->getCommand()) {
         throw new \InvalidArgumentException('The command can\'t be null.');
     }
     if (!preg_match('/^\\/([a-z]+)$/', $restaurant->getCommand())) {
         throw new \InvalidArgumentException('Invalid command name format: /bagel, only letters are allowed and must start by /');
     }
     if (mb_strlen($restaurant->getName()) > 255) {
         throw new \InvalidArgumentException('The restaurant name must be less than 255 characters.');
     }
     if (null === $restaurant->getExample()) {
         throw new \InvalidArgumentException('The order example can\'t be null.');
     }
     if (null === $restaurant->getPhoneNumber()) {
         throw new \InvalidArgumentException('The restaurant phone number can\'t be null.');
     }
     if (!preg_match('/^[0-9]{10}$/', $restaurant->getPhoneNumber())) {
         throw new \InvalidArgumentException('Invalid restaurant phone number format: Only numbers are allowed.');
     }
     if (!preg_match('/^[0-9]{2}:[0-9]{2}$/', $restaurant->getStartHour())) {
         throw new \InvalidArgumentException('Invalid start hour format.');
     }
     if (!preg_match('/^[0-9]{2}:[0-9]{2}$/', $restaurant->getEndHour())) {
         throw new \InvalidArgumentException('Invalid end hour format.');
     }
     if (null === $restaurant->getToken()) {
         throw new \InvalidArgumentException('The token can\'t be null.');
     }
     if ($restaurant->sendOrderByEmail() && null === $restaurant->getEndHour()) {
         throw new \InvalidArgumentException('You must set the restaurant email if you want to send order by email');
     }
     if ($restaurant->sendOrderByEmail() && null === $restaurant->getSenderEmail()) {
         throw new \InvalidArgumentException('You must set the sender email if you want to send order by email');
     }
     return true;
 }
 /**
  * @param String $hour
  * @param String $phoneNumber
  * @param String $name
  * @param Order[] $orders
  * @return int
  */
 private function sendEmail($hour, $phoneNumber, $name, $orders)
 {
     $message = \Swift_Message::newInstance()->setSubject($this->translator->trans('email.subject'))->setFrom($this->restaurant->getSenderEmail())->setTo($this->restaurant->getEmail())->setBody($this->twig->render('Emails/order.html.twig', ['name' => $name, 'hour' => $hour, 'phoneNumber' => $phoneNumber, 'orders' => $orders]), 'text/html');
     return $this->mailer->send($message);
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $helper = $this->getHelper('question');
     $commandNameQuestion = new Question('What is the name of your command ? [/bagel] : ', '/bagel');
     $commandName = $helper->ask($input, $output, $commandNameQuestion);
     /** @var RestaurantRepository $restaurantRepository */
     $restaurantRepository = $this->entityManager->getRepository('SlackOrder\\Entity\\Restaurant');
     $restaurant = $restaurantRepository->findOneBy(['command' => $commandName]);
     if ($restaurant) {
         throw new \InvalidArgumentException('This command already exists.');
     }
     $restaurant = new Restaurant();
     $restaurant->setCommand($commandName);
     $restaurantNameQuestion = new Question('What is the name of the restaurant ? [our favorite restaurant] : ', 'our favorite restaurant');
     $restaurantName = $helper->ask($input, $output, $restaurantNameQuestion);
     $restaurant->setName($restaurantName);
     $restaurantOrderExampleQuestion = new Question('Can you give an example of order [Big Mac] : ');
     $restaurantOrderExample = $helper->ask($input, $output, $restaurantOrderExampleQuestion);
     $restaurant->setExample($restaurantOrderExample);
     $restaurantPhoneNumberQuestion = new Question('What is the phone number of the restaurant ? [0611223344] : ');
     $restaurantPhoneNumber = $helper->ask($input, $output, $restaurantPhoneNumberQuestion);
     $restaurant->setPhoneNumber($restaurantPhoneNumber);
     $restaurantEmailQuestion = new Question('What is the email of the restaurant ? ');
     $restaurantEmail = $helper->ask($input, $output, $restaurantEmailQuestion);
     if (null !== $restaurantEmail) {
         $restaurant->setSendOrderByEmail(true);
         $restaurantEmailSenderQuestion = new Question('So who will send the mail ? [contact@yourentreprise.com] : ');
         $restaurantEmailSender = $helper->ask($input, $output, $restaurantEmailSenderQuestion);
         $restaurant->setSenderEmail($restaurantEmailSender);
     }
     $restaurantMenuUrlQuestion = new Question('Where can we find the menu on the Internet ? ');
     $restaurantMenuUrl = $helper->ask($input, $output, $restaurantMenuUrlQuestion);
     $restaurant->setUrlMenu($restaurantMenuUrl);
     $orderStartHourQuestion = new Question('When can we start to place an order ? [08:00] : ', '08:00');
     $orderStartHour = $helper->ask($input, $output, $orderStartHourQuestion);
     $restaurant->setStartHour($orderStartHour);
     $orderEndHourQuestion = new Question('When can we send the orders ? [11:00] : ', '11:00');
     $orderEndHour = $helper->ask($input, $output, $orderEndHourQuestion);
     $restaurant->setEndHour($orderEndHour);
     $commandSlackTokenQuestion = new Question('The token given by Slack when you configure it : ');
     $commandSlackToken = $helper->ask($input, $output, $commandSlackTokenQuestion);
     $restaurant->setToken($commandSlackToken);
     $this->validateRestaurant($restaurant);
     $this->entityManager->persist($restaurant);
     $this->entityManager->flush();
 }