diff --git a/app/config/config.yml b/app/config/config.yml index c451008bb1a97cf9d6bb85196f065207d4245ff7..fa0e8a8d32e2c7e5a228b8de10e4f801ff81b80a 100644 --- a/app/config/config.yml +++ b/app/config/config.yml @@ -9,6 +9,8 @@ imports: # http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration parameters: locale: fr + team_directory: '%kernel.root_dir%/../web/img/application/team' + pack_directory: '%kernel.root_dir%/../web/img/application/pack' framework: #esi: ~ diff --git a/app/config/services.yml b/app/config/services.yml index 5c76fc5988534367e579dfddfb4a611e377c03f9..cdb4cf69af28dfc2260984c517552b0bc3fdaa63 100644 --- a/app/config/services.yml +++ b/app/config/services.yml @@ -1,9 +1,4 @@ # Learn more about services, parameters and containers at # http://symfony.com/doc/current/book/service_container.html parameters: -# parameter_name: value - -services: -# service_name: -# class: AppBundle\Directory\ClassName -# arguments: ["@another_service_name", "plain_value", "%parameter_name%"] +# parameter_name: value \ No newline at end of file diff --git a/src/ApiBundle/Controller/DefaultController.php b/src/ApiBundle/Controller/DefaultController.php index 74a004473172a3cef26742da4106f990cd44bab8..5e0e7646a0eb778416b01435600b65ddc6e0a449 100644 --- a/src/ApiBundle/Controller/DefaultController.php +++ b/src/ApiBundle/Controller/DefaultController.php @@ -51,6 +51,34 @@ class DefaultController extends FOSRestController } + /** + * @param string $sport + * @return Response + * + * GET Route annotation. + * @Get("/packs/{sport}") + */ + public function getPacksBySportAction(string $sport) + { + try { + $packs = $this->getPackRepository()->findPacksBySport($sport); + $view = View::create() + ->setStatusCode(200) + ->setData($packs); + + return $this->handleView($view); + } catch (\Exception $e) { + $this->getLogger()->err($e->getMessage()); + $view = View::create() + ->setStatusCode(400) + ->setData($e->getMessage()); + + return $this->handleView($view); + } + + + } + /** * @param int $id * @return Response @@ -76,6 +104,24 @@ class DefaultController extends FOSRestController return $view; } + /** + * @param string $sport + * @return Response + * + * GET Route annotation. + * @Get("/predictions/{sport}/free") + */ + public function getFreePredictionsAction(string $sport) + { + + $view = View::create(); + + $view->setStatusCode(200); + $view->setData($this->getPredictionRepository()->getFreePredictions($sport)); + return $view; + + } + /** * @param $id * @return Response @@ -151,11 +197,24 @@ class DefaultController extends FOSRestController return $this->handleView($view); } + /** + * @param string $uuid + * + * + * GET Route annotation. + * @Get("/notifications/{uuid}/read") + */ public function readAllNotificationsAction(string $uuid) { $device = $this->getDeviceRepository()->findOneBy(['uuid' => $uuid]); if ($device) { + try { $this->getNotificationOnDeviceRepository()->readAllNotifications($device); + } catch (\Exception $e) { + + } + } else { + } } @@ -188,4 +247,9 @@ class DefaultController extends FOSRestController { return $this->getDoctrine()->getRepository('BackendBundle:Pack'); } + + private function getLogger() + { + return $this->get('logger'); + } } diff --git a/src/BackendBundle/Controller/EntityBrowserController.php b/src/BackendBundle/Controller/EntityBrowserController.php index f0d98e1800fc7fcc35f85714d1dce1938f066b62..eb21664688bd0fba258288f011116e739f22aeb8 100644 --- a/src/BackendBundle/Controller/EntityBrowserController.php +++ b/src/BackendBundle/Controller/EntityBrowserController.php @@ -4,6 +4,7 @@ namespace BackendBundle\Controller; use Doctrine\ORM\Tools\Pagination\Paginator; use Symfony\Bundle\FrameworkBundle\Controller\Controller; +use Symfony\Component\HttpFoundation\File\File; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Request; @@ -116,6 +117,7 @@ class EntityBrowserController extends Controller if ($request->getMethod() == 'POST') { $editForm->handleRequest($request); if ($editForm->isValid()) { + $this->setPicture($name, $element); $em->flush(); $this->get('session')->getFlashBag()->add('success', "L'élément a bien été modifié"); return $this->redirectToRoute('backend_entitybrowser_list', ['name' => $name, 'page' => 1]); @@ -169,4 +171,60 @@ class EntityBrowserController extends Controller } + /** + * @param string $name + * @param int $id + * @param Request $request + * @return Response + * + * @Route("/admin/{name}/add-score/{id}", requirements={"name" = "prediction", "id"}) + */ + public function addScoreAction(string $name, int $id, Request $request) + { + $em = $this->getDoctrine()->getManager(); + $repository = $em->getRepository('BackendBundle:Prediction'); + $element = $repository->find($id); + + if ($element) { + $editForm = $this->createForm("BackendBundle\\Form\\AddScoreType", $element); + if ($request->getMethod() == 'POST') { + $editForm->handleRequest($request); + if ($editForm->isValid()) { + $em->flush(); + $this->get('session')->getFlashBag()->add('success', "Le score a bien été ajouté"); + return $this->redirectToRoute('backend_entitybrowser_list', ['name' => $name, 'page' => 1]); + } + } + } else { + $this->get('session')->getFlashBag()->add('error', "Vous tentez d'accéder à un élément qui n'existe pas"); + return $this->redirectToRoute('backend_entitybrowser_list', ['name' => $name, 'page' => 1]); + } + + return $this->render( + '@Backend/'. $name .'/add_score.html.twig', + [ + 'name' => $name, + 'form' => $editForm->createView() + ] + ); + } + + private function setPicture(string $name, $element) + { + if (in_array($name, ['team', 'pack'])) { + + /** @var File $file */ + $file = $element->getPicture(); + + $fileName = md5(uniqid() . '.' . $file->guessExtension()); + + $file->move( + $this->get($name. '_directory'), + $fileName + ); + + $element->setPicture($fileName); + } + } + } diff --git a/src/BackendBundle/Controller/NotificationController.php b/src/BackendBundle/Controller/NotificationController.php index f629dc40f2980f66ab47ea7f0b850b8febf32184..453fb0ffda085e15c2b5255a014cdff4529b9c23 100644 --- a/src/BackendBundle/Controller/NotificationController.php +++ b/src/BackendBundle/Controller/NotificationController.php @@ -26,8 +26,6 @@ class NotificationController extends Controller const SENDER_ID = "1006878207346"; const DEFAULT_PAGE_RESULT = 20; - - /** * @param Request $request * @return Response @@ -45,39 +43,46 @@ class NotificationController extends Controller $form->handleRequest($request); if ($form->isValid()) { - $message = [ - 'notification' => [ - 'title' => $notification->getTitle(), - 'body' => $notification->getContent() - ], - 'to' => 'cNgyx3ZgOX4:APA91bF5eigDuJLjj8wI8SC4l5KIHATuxi-2G5whpWI1n1jWpWWwRAwbEXec4fQ2S7HW8EdUPaREXJ5fVd_TZV8rZq_eIJIEhEadeH9wpsbYmUUM7E8H8Y0Qst9KmBuHWodCFFJPJ0vh' - ]; + + $devices = $this->getDoctrine()->getRepository('BackendBundle:Device')->findAll(); $client = new Client(); - $response = $client->request('POST', self::NOTIFICATION_API_URL, [ - 'body' => json_encode($message), - 'headers'=> [ - 'Authorization' => 'key='.self::SERVER_KEY, - 'Content-Type' => 'application/json', - ] - ]); - - $response = (array) \GuzzleHttp\json_decode($response->getBody()->getContents()); - - if (!$response['failure']) { - $notification->setDate(new \DateTime()); - $devices = $this->getDoctrine()->getRepository('BackendBundle:Device')->findAll(); - $em = $this->getDoctrine()->getEntityManager(); - $em->persist($notification); - $this->getDoctrine()->getRepository('BackendBundle:NotificationOnDevice')->updateStatusOnAllDevices($devices, $notification); - $this->addFlash('success', 'La notification a bien été envoyée'); - return $this->redirectToRoute('backend_notification_list', ['page' => 1]); - } - $this->addFlash('danger', $response['results'][0]->error); + foreach ($devices as $device) { + if ($device->getLocale() === 'fr') { + $message = [ + 'notification' => [ + 'title' => $notification->getFrenchTitle(), + 'body' => $notification->getFrenchContent() + ], + 'to' => $device->getToken() + ]; + } else { + $message = [ + 'notification' => [ + 'title' => $notification->getEnglishTitle(), + 'body' => $notification->getEnglishContent() + ], + 'to' => $device->getToken() + ]; + } + + $client->request('POST', self::NOTIFICATION_API_URL, [ + 'body' => json_encode($message), + 'headers'=> [ + 'Authorization' => 'key='.self::SERVER_KEY, + 'Content-Type' => 'application/json', + ] + ]); + } + $notification->setDate(new \DateTime()); + $em = $this->getDoctrine()->getEntityManager(); + $em->persist($notification); + $this->getDoctrine()->getRepository('BackendBundle:NotificationOnDevice')->updateStatusOnAllDevices($devices, $notification); + $this->addFlash('success', 'La notification a bien été envoyée'); + return $this->redirectToRoute('backend_notification_list', ['page' => 1]); } - } return $this->render('@Backend/notification/create.html.twig',[ diff --git a/src/BackendBundle/Entity/Device.php b/src/BackendBundle/Entity/Device.php index d741a978f77b2b848feeb7a1249d3b1619b59108..eb3e92fd309ba7769d87fa4ff615bceaaaf52662 100644 --- a/src/BackendBundle/Entity/Device.php +++ b/src/BackendBundle/Entity/Device.php @@ -56,6 +56,13 @@ class Device */ private $token; + /** + * @var string + * + * @ORM\Column(type="string", length=255) + */ + private $locale; + /** * Get id @@ -186,4 +193,20 @@ class Device { return $this->token; } + + /** + * @return string + */ + public function getLocale() + { + return $this->locale; + } + + /** + * @param string $locale + */ + public function setLocale($locale) + { + $this->locale = $locale; + } } diff --git a/src/BackendBundle/Entity/Device.php~ b/src/BackendBundle/Entity/Device.php~ new file mode 100644 index 0000000000000000000000000000000000000000..4d745f73666f932e75ad46e829f8303c3658d3d2 --- /dev/null +++ b/src/BackendBundle/Entity/Device.php~ @@ -0,0 +1,190 @@ +<?php + +namespace BackendBundle\Entity; + +use Doctrine\ORM\Mapping as ORM; + +/** + * Device + * + * @ORM\Table(name="device") + * @ORM\Entity(repositoryClass="BackendBundle\Repository\DeviceRepository") + */ +class Device +{ + /** + * @var int + * + * @ORM\Column(name="id", type="integer") + * @ORM\Id + * @ORM\GeneratedValue(strategy="AUTO") + */ + private $id; + + /** + * @var string + * + * @ORM\Column(name="uuid", type="string", length=255) + */ + private $uuid; + + /** + * @var string + * + * @ORM\Column(name="model", type="string", length=255) + */ + private $model; + + /** + * @var string + * + * @ORM\Column(name="version", type="string", length=255) + */ + private $version; + + /** + * @var string + * + * @ORM\Column(name="platform", type="string", length=255) + */ + private $platform; + + /** + * @var string + * + * @ORM\Column(name="token", type="string", length=255) + */ + private $token; + + + /** + * Get id + * + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * Set uuid + * + * @param string $uuid + * + * @return Device + */ + public function setUuid($uuid) + { + $this->uuid = $uuid; + + return $this; + } + + /** + * Get uuid + * + * @return string + */ + public function getUuid() + { + return $this->uuid; + } + + /** + * Set model + * + * @param string $model + * + * @return Device + */ + public function setModel($model) + { + $this->model = $model; + + return $this; + } + + /** + * Get model + * + * @return string + */ + public function getModel() + { + return $this->model; + } + + /** + * Set version + * + * @param string $version + * + * @return Device + */ + public function setVersion($version) + { + $this->version = $version; + + return $this; + } + + /** + * Get version + * + * @return string + */ + public function getVersion() + { + return $this->version; + } + + /** + * Set platform + * + * @param string $platform + * + * @return Device + */ + public function setPlatform($platform) + { + $this->platform = $platform; + + return $this; + } + + /** + * Get platform + * + * @return string + */ + public function getPlatform() + { + return $this->platform; + } + + /** + * Set token + * + * @param string $token + * + * @return Device + */ + public function setToken($token) + { + $this->token = $token; + + return $this; + } + + /** + * Get token + * + * @return string + */ + public function getToken() + { + return $this->token; + } +} + diff --git a/src/BackendBundle/Entity/Notification.php b/src/BackendBundle/Entity/Notification.php index ca52bf46cef0e5b0051f6351ee0308c8840b16bc..75c3dbffda7429e875cfe85be7ebf8a47d4b2e4a 100644 --- a/src/BackendBundle/Entity/Notification.php +++ b/src/BackendBundle/Entity/Notification.php @@ -24,33 +24,39 @@ class Notification /** * @var string * - * @ORM\Column(name="title", type="string", length=255) + * @ORM\Column(type="string", length=255) */ - private $title; + private $frenchTitle; /** * @var string * * @ORM\Column(name="content", type="text") */ - private $content; + private $frenchContent; /** - * @var \DateTime + * @var string * - * @ORM\Column(name="date", type="datetime") + * @ORM\Column(type="string", length=255) */ - private $date; + private $englishTitle; /** * @var string + * + * @ORM\Column(name="content", type="text") */ - private $deviceStatus; - + private $englishContent; /** - * Get id + * @var \DateTime * + * @ORM\Column(name="date", type="datetime") + */ + private $date; + + /** * @return int */ public function getId() @@ -59,90 +65,91 @@ class Notification } /** - * Set title - * - * @param string $title - * - * @return Notification + * @param int $id */ - public function setTitle($title) + public function setId($id) { - $this->title = $title; - - return $this; + $this->id = $id; } /** - * Get title - * * @return string */ - public function getTitle() + public function getFrenchTitle() { - return $this->title; + return $this->frenchTitle; } /** - * Set content - * - * @param string $content - * - * @return Notification + * @param string $frenchTitle */ - public function setContent($content) + public function setFrenchTitle($frenchTitle) { - $this->content = $content; - - return $this; + $this->frenchTitle = $frenchTitle; } /** - * Get content - * * @return string */ - public function getContent() + public function getFrenchContent() { - return $this->content; + return $this->frenchContent; } /** - * Set date - * - * @param \DateTime $date - * - * @return Notification + * @param string $frenchContent */ - public function setDate($date) + public function setFrenchContent($frenchContent) { - $this->date = $date; + $this->frenchContent = $frenchContent; + } - return $this; + /** + * @return string + */ + public function getEnglishTitle() + { + return $this->englishTitle; } /** - * Get date - * - * @return \DateTime + * @param string $englishTitle */ - public function getDate() + public function setEnglishTitle($englishTitle) { - return $this->date; + $this->englishTitle = $englishTitle; } /** * @return string */ - public function getDeviceStatus() + public function getEnglishContent() + { + return $this->englishContent; + } + + /** + * @param string $englishContent + */ + public function setEnglishContent($englishContent) { - return $this->deviceStatus; + $this->englishContent = $englishContent; } /** - * @param string $deviceStatus + * @return \DateTime */ - public function setDeviceStatus($deviceStatus) + public function getDate() { - $this->deviceStatus = $deviceStatus; + return $this->date; } + + /** + * @param \DateTime $date + */ + public function setDate($date) + { + $this->date = $date; + } + } diff --git a/src/BackendBundle/Entity/Notification.php~ b/src/BackendBundle/Entity/Notification.php~ new file mode 100644 index 0000000000000000000000000000000000000000..eb31af54dfd32edb63d51965f72e7517d1368bbd --- /dev/null +++ b/src/BackendBundle/Entity/Notification.php~ @@ -0,0 +1,128 @@ +<?php + +namespace BackendBundle\Entity; + +use Doctrine\ORM\Mapping as ORM; + +/** + * Notification + * + * @ORM\Table(name="notification") + * @ORM\Entity(repositoryClass="BackendBundle\Repository\NotificationRepository") + */ +class Notification +{ + /** + * @var int + * + * @ORM\Column(name="id", type="integer") + * @ORM\Id + * @ORM\GeneratedValue(strategy="AUTO") + */ + private $id; + + /** + * @var string + * + * @ORM\Column(name="title", type="string", length=255) + */ + private $title; + + /** + * @var string + * + * @ORM\Column(name="content", type="text") + */ + private $content; + + /** + * @var \DateTime + * + * @ORM\Column(name="date", type="datetime") + */ + private $date; + + + /** + * Get id + * + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * Set title + * + * @param string $title + * + * @return Notification + */ + public function setTitle($title) + { + $this->title = $title; + + return $this; + } + + /** + * Get title + * + * @return string + */ + public function getTitle() + { + return $this->title; + } + + /** + * Set content + * + * @param string $content + * + * @return Notification + */ + public function setContent($content) + { + $this->content = $content; + + return $this; + } + + /** + * Get content + * + * @return string + */ + public function getContent() + { + return $this->content; + } + + /** + * Set date + * + * @param \DateTime $date + * + * @return Notification + */ + public function setDate($date) + { + $this->date = $date; + + return $this; + } + + /** + * Get date + * + * @return \DateTime + */ + public function getDate() + { + return $this->date; + } +} + diff --git a/src/BackendBundle/Entity/Pack.php b/src/BackendBundle/Entity/Pack.php index 1d0ba4b34a284868a181b70c57ca7d3d36cb04ce..e3463bb4703ae868aab74f3c4071e269cf49cd4e 100644 --- a/src/BackendBundle/Entity/Pack.php +++ b/src/BackendBundle/Entity/Pack.php @@ -4,6 +4,7 @@ namespace BackendBundle\Entity; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; +use Symfony\Component\Validator\Constraints as Assert; /** * Pack @@ -46,6 +47,14 @@ class Pack */ private $leagues; + /** + * @ORM\Column(name="picture", type="string", length=255) + * + * @Assert\NotBlank(message="Veuillez uploader une image de l'équipe") + * @Assert\File(mimeTypes={"image/jpeg", "image/png"}) + */ + private $picture; + /** * Get id @@ -135,5 +144,21 @@ class Pack } } + /** + * @return mixed + */ + public function getPicture() + { + return $this->picture; + } + + /** + * @param mixed $picture + */ + public function setPicture($picture) + { + $this->picture = $picture; + } + } diff --git a/src/BackendBundle/Entity/Prediction.php b/src/BackendBundle/Entity/Prediction.php index 95e4922396e599b46272ff8e12ece0c85d5a96b0..a9202461a856b74630a6363b2fa5a978592eb5ef 100644 --- a/src/BackendBundle/Entity/Prediction.php +++ b/src/BackendBundle/Entity/Prediction.php @@ -80,6 +80,20 @@ class Prediction */ private $league; + /** + * @var bool + * + * @ORM\Column(name="free", type="boolean") + */ + private $free = false; + + /** + * @var int + * + * @ORM\Column(name="winner", type="integer", nullable=true) + */ + private $winner; + /** * Get id * @@ -273,5 +287,37 @@ class Prediction { $this->league = $league; } + + /** + * @return mixed + */ + public function getFree() + { + return $this->free; + } + + /** + * @param mixed $free + */ + public function setFree($free) + { + $this->free = $free; + } + + /** + * @return int + */ + public function getWinner() + { + return $this->winner; + } + + /** + * @param int $winner + */ + public function setWinner($winner) + { + $this->winner = $winner; + } } diff --git a/src/BackendBundle/Entity/Team.php b/src/BackendBundle/Entity/Team.php index 20fc4fa315af5c3671857bc17779e6254fa80b4f..ca8dc507fd04d51d8594ce375b1c747d3822ef41 100644 --- a/src/BackendBundle/Entity/Team.php +++ b/src/BackendBundle/Entity/Team.php @@ -9,6 +9,7 @@ namespace BackendBundle\Entity; use Doctrine\ORM\Mapping as ORM; +use Symfony\Component\Validator\Constraints as Assert; /** * Team @@ -34,6 +35,14 @@ class Team */ private $name; + /** + * @ORM\Column(name="picture", type="string", length=255) + * + * @Assert\NotBlank(message="Veuillez uploader une image de l'équipe") + * @Assert\File(mimeTypes={"image/jpeg", "image/png"}) + */ + private $picture; + /** * @return int */ @@ -65,4 +74,20 @@ class Team { $this->name = $name; } + + /** + * @return string + */ + public function getPicture() + { + return $this->picture; + } + + /** + * @param string $picture + */ + public function setPicture($picture) + { + $this->picture = $picture; + } } \ No newline at end of file diff --git a/src/BackendBundle/Form/AddScoreType.php b/src/BackendBundle/Form/AddScoreType.php index 13092a5826113cf5e1b2f4c6f0739b45f18ec34e..60ac340cce1a8973121efbe4b7fd9790912a5d11 100644 --- a/src/BackendBundle/Form/AddScoreType.php +++ b/src/BackendBundle/Form/AddScoreType.php @@ -3,19 +3,45 @@ namespace BackendBundle\Form; use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\Extension\Core\Type\ChoiceType; +use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Component\Form\FormEvent; +use Symfony\Component\Form\FormEvents; use Symfony\Component\OptionsResolver\OptionsResolver; class AddScoreType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { + $builder + ->add('score', TextType::class, [ + 'label' => 'Score (mettre le score sous la forme 3-1 ou encore 6-3 2-6 7-5)', + 'required' => true + ]); + + $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) { + $prediction = $event->getData(); + $form = $event->getForm(); + + $form->add('winner', ChoiceType::class, [ + 'choices' => [ + $prediction->getFirstTeam()->getName() => $prediction->getFirstTeam()->getId(), + $prediction->getSecondTeam()->getName() => $prediction->getSecondTeam()->getId(), + 'Égalité' => -1 + ] + ]); + + }); } public function configureOptions(OptionsResolver $resolver) { - + $resolver->setDefaults([ + 'data_class' => 'BackendBundle\Entity\Prediction', + 'csrf_protection' => false, + ]); } public function getName() diff --git a/src/BackendBundle/Form/NotificationType.php b/src/BackendBundle/Form/NotificationType.php index b75cf0ee8b112cb8a68d4f660024e344c471f21f..f28f005af34a9a2ddc4448b560661e710201abef 100644 --- a/src/BackendBundle/Form/NotificationType.php +++ b/src/BackendBundle/Form/NotificationType.php @@ -13,11 +13,17 @@ class NotificationType extends AbstractType public function buildForm(FormBuilderInterface $builder, array $options) { $builder - ->add('title', TextType::class, [ - 'label' => 'Titre', + ->add('frenchTitle', TextType::class, [ + 'label' => 'Titre (Français)', ]) - ->add('content', TextareaType::class, [ - 'label' => 'Contenu', + ->add('frenchContent', TextareaType::class, [ + 'label' => 'Contenu (Français)', + ]) + ->add('englishTitle', TextType::class, [ + 'label' => 'Titre (Anglais)', + ]) + ->add('englishContent', TextareaType::class, [ + 'label' => 'Contenu (Anglais)', ]); } diff --git a/src/BackendBundle/Form/PackType.php b/src/BackendBundle/Form/PackType.php index 5ed0e72b64d4ccf8e5c1eef83269056248f51dc3..2940ef58bc9a7528565bc1894bfe53bd6658c370 100644 --- a/src/BackendBundle/Form/PackType.php +++ b/src/BackendBundle/Form/PackType.php @@ -5,6 +5,7 @@ namespace BackendBundle\Form; use BackendBundle\Form\Type\FloatType; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\Extension\Core\Type\FileType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -18,7 +19,7 @@ class PackType extends AbstractType 'label' => 'Nom', ]) ->add('priceInCents', FloatType::class, [ - 'label' => 'Prix' + 'label' => 'Prix (en centimes)' ]) ->add('leagues', EntityType::class, [ 'label' => 'Ligues', @@ -26,6 +27,9 @@ class PackType extends AbstractType 'choice_label' => 'name', 'multiple' => true, 'expanded' => false + ]) + ->add('picture', FileType::class, [ + 'label' => 'Image', ]); } diff --git a/src/BackendBundle/Form/PredictionType.php b/src/BackendBundle/Form/PredictionType.php index 3f89aff05570faef7c4a6a05f782e774f5e0c896..5a3fe1a98c4e5d8fe11b0f67a5d16266612397fb 100644 --- a/src/BackendBundle/Form/PredictionType.php +++ b/src/BackendBundle/Form/PredictionType.php @@ -6,6 +6,7 @@ use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\DateTimeType; use Symfony\Component\Form\Extension\Core\Type\IntegerType; +use Symfony\Component\Form\Extension\Core\Type\RadioType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -59,6 +60,10 @@ class PredictionType extends AbstractType 'min' => '0', 'max' => "100" ] + ]) + ->add('free', RadioType::class, [ + 'label' => 'Prediction gratuite ?', + 'required' => false, ]); } diff --git a/src/BackendBundle/Form/TeamType.php b/src/BackendBundle/Form/TeamType.php index 73100676483990c0735a0adcff3f57e5152703fa..40343368e8e66de2ea3744b66bbe23e2174aec09 100644 --- a/src/BackendBundle/Form/TeamType.php +++ b/src/BackendBundle/Form/TeamType.php @@ -3,6 +3,7 @@ namespace BackendBundle\Form; use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\Extension\Core\Type\FileType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -14,6 +15,9 @@ class TeamType extends AbstractType $builder ->add('name', TextType::class, [ 'label' => 'Nom', + ]) + ->add('picture', FileType::class, [ + 'label' => 'Image', ]); } diff --git a/src/BackendBundle/Repository/NotificationOnDeviceRepository.php b/src/BackendBundle/Repository/NotificationOnDeviceRepository.php index 742d09d7eafb3b2f1d33e4b301b8c0e9d64fc6d9..363e346374c7abb90df47e63c190839cc67f1bd7 100644 --- a/src/BackendBundle/Repository/NotificationOnDeviceRepository.php +++ b/src/BackendBundle/Repository/NotificationOnDeviceRepository.php @@ -16,7 +16,10 @@ use Doctrine\ORM\EntityRepository; class NotificationOnDeviceRepository extends EntityRepository { - public function findNotificationsByDevice(array $notifications, Device $device) + public function findNotificationsByDevice( + array $notifications, + Device $device + ) { return $this->createQueryBuilder('s') ->where('s.notification IN (:notifications)') @@ -29,7 +32,10 @@ class NotificationOnDeviceRepository extends EntityRepository ->getResult(); } - public function updateStatusOnAllDevices(array $devices, Notification $notification) + public function updateStatusOnAllDevices( + array $devices, + Notification $notification + ) { foreach ($devices as $device) { $notifOnDevice = new NotificationOnDevice(); @@ -49,5 +55,7 @@ class NotificationOnDeviceRepository extends EntityRepository ->set('n.status', NotificationOnDevice::STATUS_READ) ->where('n.device = :device') ->setParameter('device', $device); + + $qb->getQuery()->execute(); } -} \ No newline at end of file +} diff --git a/src/BackendBundle/Repository/PackRepository.php b/src/BackendBundle/Repository/PackRepository.php index 8c4f659f266e831a4abb6ca36c46f87a6c4f0943..53ece9fcf6c8aea3ed87be8fd0a807daa2416115 100644 --- a/src/BackendBundle/Repository/PackRepository.php +++ b/src/BackendBundle/Repository/PackRepository.php @@ -28,4 +28,16 @@ class PackRepository extends EntityRepository } + public function findPacksBySport(string $sport) + { + $qb = $this->createQueryBuilder('p'); + $qb + + ->select('p') + ->join('p.leagues', 'l', 'WITH', 'l.sport = :sport') + ->setParameter('sport', $sport); + + return $qb->getQuery()->getResult(); + } + } \ No newline at end of file diff --git a/src/BackendBundle/Repository/PredictionRepository.php b/src/BackendBundle/Repository/PredictionRepository.php index e2d9989e143826afd4af67e0e7a9575ac9f9bf63..fb9a4b5afd3201a9785a8903db2bdca4d1a0d658 100644 --- a/src/BackendBundle/Repository/PredictionRepository.php +++ b/src/BackendBundle/Repository/PredictionRepository.php @@ -39,4 +39,17 @@ class PredictionRepository extends EntityRepository return $qb; } + + public function getFreePredictions(string $sport) + { + $qb = $this->createQueryBuilder('p'); + + $qb + ->select('p') + ->join('p.league', 'l', 'WITH' , 'p.league = l') + ->where('l.sport = :sport') + ->setParameter('sport', $sport); + + return $qb->getQuery()->getResult(); + } } diff --git a/src/BackendBundle/Resources/views/pack/form.html.twig b/src/BackendBundle/Resources/views/pack/form.html.twig index e9d05110d768473df57b5a8c13751de1c93709ad..6c0f58af217e320be8c4d67638388b7666b11a9c 100644 --- a/src/BackendBundle/Resources/views/pack/form.html.twig +++ b/src/BackendBundle/Resources/views/pack/form.html.twig @@ -37,6 +37,14 @@ </div> </div> + <div class="form-group is-empty has-primary"> + {{ form_label(form.picture, null, {'label_attr': {'class': "col-sm-2 control-label"}}) }} + <div class="col-sm-10"> + {{ form_widget(form.picture, {'attr' : {'class': "form-control"}}) }} + </div> + {{ form_errors(form.picture) }} + </div> + <button type="submit" class="modal-action modal-close waves-effect waves-green waves-light btn">Ajouter</button> {{ form_end(form, {'render_rest': false}) }} </div> diff --git a/src/BackendBundle/Resources/views/pack/list.html.twig b/src/BackendBundle/Resources/views/pack/list.html.twig index 5d1f8f1c760a11eadf851dd3c51fbe3e407248e0..650c950af6b455545fc3c66f297ae59ac27c3b00 100644 --- a/src/BackendBundle/Resources/views/pack/list.html.twig +++ b/src/BackendBundle/Resources/views/pack/list.html.twig @@ -26,7 +26,7 @@ <tr id="{{ element.id }}"> <td>{{ element.id }}</td> <td>{{ element.name }}</td> - <td>{{ element.priceInCents }}</td> + <td>{{ element.priceInCents / 100 }}€</td> <td>{{ leagues|join(', ') }}</td> <td><a href="{{ path('backend_entitybrowser_edit', {'name': name, 'id': element.id}) }}" class="btn btn-info">Modifier<div class="ripple-container"></div></a></td> <td> diff --git a/src/BackendBundle/Resources/views/prediction/add_score.html.twig b/src/BackendBundle/Resources/views/prediction/add_score.html.twig index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..648d9d2093c65f7fc7e6154a7ab80d17c90c0349 100644 --- a/src/BackendBundle/Resources/views/prediction/add_score.html.twig +++ b/src/BackendBundle/Resources/views/prediction/add_score.html.twig @@ -0,0 +1,37 @@ +{% extends '@Backend/layout/dashboard.html.twig' %} + +{% block title %}Ajouter le score à ce match{% endblock %} + +{% block subcontent %} + <div class="row"> + <div class="col-sm-8 col-sm-offset-2 col-xs-12"> + <h3 class="text-center text-primary">Ajouter une nouvelle ou éditer une {{ name | trans }}</h3> + {{ form_start(form, {'attr': {'class': 'form-horizontal'}}) }} + <div class="row"> + <div class="col-xs-12"> + <div class="form-group is-empty has-primary"> + {{ form_label(form.score, null, {'label_attr': {'class': "col-md-4 col-xs-12 control-label"}}) }} + <div class="col-md-8 col-xs-12"> + {{ form_widget(form.score, {'attr' : {'class': "form-control js-example-basic-single"}}) }} + {{ form_errors(form.score) }} + </div> + </div> + </div> + <div class="col-xs-12"> + <div class="form-group is-empty has-primary"> + {{ form_label(form.winner, null, {'label_attr': {'class': "col-md-4 col-xs-12 control-label"}}) }} + <div class="col-md-8 col-xs-12"> + {{ form_widget(form.winner, {'attr' : {'class': "form-control js-example-basic-single"}}) }} + {{ form_errors(form.winner) }} + </div> + </div> + </div> + </div> + + <div class="col-xs-12 text-center"> + <button type="submit" class="btn btn-lg btn-raised btn-success">Valider</button> + </div> + {{ form_end(form, {'render_rest': false}) }} + </div> + </div> +{% endblock %} \ No newline at end of file diff --git a/src/BackendBundle/Resources/views/prediction/form.html.twig b/src/BackendBundle/Resources/views/prediction/form.html.twig index 719078437ee0d71bd8ebd07440233999587f1e49..55dcc8c9a51ef2037857e29620c0b7219ab1798a 100644 --- a/src/BackendBundle/Resources/views/prediction/form.html.twig +++ b/src/BackendBundle/Resources/views/prediction/form.html.twig @@ -88,6 +88,18 @@ </div> </div> + <div class="row"> + <div class="col-xs-12"> + <div class="form-group is-empty"> + {{ form_label(form.free, null, {'label_attr': {'class': "col-md-3 col-xs-12 control-label"}}) }} + <div class="col-md-9 col-xs-12"> + {{ form_widget(form.free, {'attr' : {'class': "form-control"}}) }} + {{ form_errors(form.free) }} + </div> + </div> + </div> + </div> + <div class="col-xs-12 text-center"> <button type="submit" class="btn btn-lg btn-raised btn-success">Valider</button> </div> diff --git a/src/BackendBundle/Resources/views/prediction/list.html.twig b/src/BackendBundle/Resources/views/prediction/list.html.twig index 2c78ead196fe7977663ae741d7a4ee6ec72d7a23..b2258077368c5b071b0eda65ee41b36ff1f9aafa 100644 --- a/src/BackendBundle/Resources/views/prediction/list.html.twig +++ b/src/BackendBundle/Resources/views/prediction/list.html.twig @@ -17,9 +17,10 @@ <th>Côte victoire équipe 1</th> <th>Côte victoire équipe 2</th> <th>Côte match nul</th> + <th>Prédiction gratuite ?</th> <th>Score final</th> - <th>Modifier</th> - <th>Selectionnerr</th> + <th>Actions</th> + <th>Selectionner</th> </tr> </thead> <tbody> @@ -33,8 +34,12 @@ <td>{{ element.predictionWinFirst }} %</td> <td>{{ element.predictionWinSecond }} %</td> <td>{{ element.predictionDraw }} %</td> + <td>{% if element.free %}Oui{% else %}Non{% endif %}</td> <td>{{ element.score }}</td> - <td><a href="{{ path('backend_entitybrowser_edit', {'name': name, 'id': element.id}) }}" class="btn btn-info">Modifier<div class="ripple-container"></div></a></td> + <td> + <a href="{{ path('backend_entitybrowser_edit', {'name': name, 'id': element.id}) }}" class="btn btn-info">Modifier<div class="ripple-container"></div></a> + <a href="{{ path('backend_entitybrowser_addscore', {'name': name, 'id': element.id}) }}" class="btn btn-warning">Ajouter le score<div class="ripple-container"></div></a> + </td> <td> <div class="checkbox"> <label> diff --git a/src/BackendBundle/Resources/views/team/form.html.twig b/src/BackendBundle/Resources/views/team/form.html.twig index 5bee3ac3e54d45cbaaf28b6a7d310e0a01241a37..2ecf9c3bac4dbddd7a8e879117b61f5ec04e592f 100644 --- a/src/BackendBundle/Resources/views/team/form.html.twig +++ b/src/BackendBundle/Resources/views/team/form.html.twig @@ -14,13 +14,18 @@ <h3 class="text-center text-primary">Ajouter une nouvelle ou éditer une {{ name | trans }}</h3> {{ form_start(form, {'attr': {'class': 'form-horizontal'}}) }} <div class="row"> - <div class="col-sm-6"> - <div class="form-group is-empty has-primary"> - {{ form_label(form.name, null, {'label_attr': {'class': "col-sm-3 control-label"}}) }} - <div class="col-sm-9"> - {{ form_widget(form.name, {'attr' : {'class': "form-control"}}) }} - {{ form_errors(form.name) }} - </div> + <div class="form-group is-empty has-primary"> + {{ form_label(form.name, null, {'label_attr': {'class': "col-sm-3 control-label"}}) }} + <div class="col-sm-9"> + {{ form_widget(form.name, {'attr' : {'class': "form-control"}}) }} + {{ form_errors(form.name) }} + </div> + </div> + <div class="form-group is-empty has-primary"> + {{ form_label(form.picture, null, {'label_attr': {'class': "col-sm-3 control-label"}}) }} + <div class="col-sm-9"> + {{ form_widget(form.picture, {'attr' : {'class': "form-control"}}) }} + {{ form_errors(form.picture) }} </div> </div> </div> diff --git a/web/img/application/pack/wimbledon.png b/web/img/application/pack/wimbledon.png new file mode 100644 index 0000000000000000000000000000000000000000..16caf3c4bbe9b451ac0ab31cff7fb7f37b13fa80 Binary files /dev/null and b/web/img/application/pack/wimbledon.png differ diff --git a/web/img/application/team/nadal.png b/web/img/application/team/nadal.png new file mode 100644 index 0000000000000000000000000000000000000000..166fd2fd43bd7b61e099337e15b6bbd4716e0d3c Binary files /dev/null and b/web/img/application/team/nadal.png differ