diff --git a/src/ApiBundle/Controller/DefaultController.php b/src/ApiBundle/Controller/DefaultController.php index c108c3c3bed6ce06b59f7ac9e6c9cd16d6cac835..89a644077ee0ace3c6a059253ac57f6851d9c0d8 100644 --- a/src/ApiBundle/Controller/DefaultController.php +++ b/src/ApiBundle/Controller/DefaultController.php @@ -49,7 +49,9 @@ class DefaultController extends FOSRestController public function getLeaguesBySportAction(string $uuid, string $sport) { try { - $device = $this->getDeviceRepository()->findOneBy(['uuid' => $uuid]); + while ($device === null) { + $device = $this->getDeviceRepository()->findOneBy(['uuid' => $uuid]); + } $leagues = $this->getLeagueRepository()->findBySport($sport, $device); $view = View::create() ->setStatusCode(200) @@ -179,7 +181,7 @@ class DefaultController extends FOSRestController $this->getLogger()->err($e->getMessage()); } - return $this->handleView($view); + return $this->handleView($view); } $view->setStatusCode(403); diff --git a/src/BackendBundle/Controller/EntityBrowserController.php b/src/BackendBundle/Controller/EntityBrowserController.php index f9914cff082f0e7f3ee9489ce3d808f2a35320cf..6d6cec36fde451981787ef8b3908c71d9e8c97c1 100644 --- a/src/BackendBundle/Controller/EntityBrowserController.php +++ b/src/BackendBundle/Controller/EntityBrowserController.php @@ -144,7 +144,7 @@ class EntityBrowserController extends Controller * @param Request $request * @return JsonResponse * - * @Route("/admin/{name}/delete", requirements={"name" = "league|prediction|team"}) + * @Route("/admin/{name}/delete", requirements={"name" = "league|prediction|team|notification"}) */ public function deleteAction(string $name, Request $request) { diff --git a/src/BackendBundle/Controller/NotificationController.php b/src/BackendBundle/Controller/NotificationController.php index 453fb0ffda085e15c2b5255a014cdff4529b9c23..78c166647cbdf09caa93b083b913492e74d11f4e 100644 --- a/src/BackendBundle/Controller/NotificationController.php +++ b/src/BackendBundle/Controller/NotificationController.php @@ -22,7 +22,7 @@ class NotificationController extends Controller { const NOTIFICATION_API_URL = 'https://fcm.googleapis.com/fcm/send'; - const SERVER_KEY = "AIzaSyCFdGq-rjzznFOEzDifZGsRoeWT8LFAc9s"; + const SERVER_KEY = "AAAA6m6eLXI:APA91bHDsojOIQaWHX5nGNGS9Thyn6MAZZvLvvfEEdWmzbOjD7lYqkghcER69wRkiaRb4zfEQ5P5V8ckdVjGUf58CmMqYNhsRPCy75OeugN85oHCOCBvYn7I7czIsy2pScYKgB2eWC0wRxsyw7-iEMwpzf6eZFWM8w"; const SENDER_ID = "1006878207346"; const DEFAULT_PAGE_RESULT = 20; @@ -53,27 +53,35 @@ class NotificationController extends Controller $message = [ 'notification' => [ 'title' => $notification->getFrenchTitle(), - 'body' => $notification->getFrenchContent() + 'body' => $notification->getFrenchContent(), + "content_available" => 1 ], - 'to' => $device->getToken() + 'to' => $device->getToken(), + 'priority' => 'high' + ]; } else { $message = [ 'notification' => [ 'title' => $notification->getEnglishTitle(), - 'body' => $notification->getEnglishContent() + 'body' => $notification->getEnglishContent(), + "content_available" => 1 ], - 'to' => $device->getToken() + 'to' => $device->getToken(), + 'priority' => 'high' ]; } - $client->request('POST', self::NOTIFICATION_API_URL, [ - 'body' => json_encode($message), - 'headers'=> [ - 'Authorization' => 'key='.self::SERVER_KEY, - 'Content-Type' => 'application/json', - ] - ]); + if ($device->getToken() !== 'BLACKLISTED') { + + $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()); @@ -132,4 +140,4 @@ class NotificationController extends Controller ); } -} \ No newline at end of file +} diff --git a/src/BackendBundle/Entity/League.php b/src/BackendBundle/Entity/League.php index ec8950e89d0093574e23f98ec7362784a4eea97b..d9204cf3ccf4b9cdeb7f304cab309ad8b696d38d 100644 --- a/src/BackendBundle/Entity/League.php +++ b/src/BackendBundle/Entity/League.php @@ -36,6 +36,20 @@ class League */ private $sport; + /** + * @var string + * + * @ORM\Column(name="french_description", type="string", length=255, nullable=true) + */ + private $frenchDescription; + + /** + * @var string + * + * @ORM\Column(name="english_description", type="string", length=255, nullable=true) + */ + private $englishDescription; + /** * @var string * @@ -224,4 +238,30 @@ class League { $this->unitaryPackName = $unitaryPackName; } + + public function setFrenchDescription($description) + { + $this->frenchDescription = $description; + } + + /** + * @return mixed + */ + public function getFrenchDescription() + { + return $this->frenchDescription; + } + + public function setEnglishDescription($description) + { + $this->englishDescription = $description; + } + + /** + * @return mixed + */ + public function getEnglishDescription() + { + return $this->englishDescription; + } } diff --git a/src/BackendBundle/Form/LeagueType.php b/src/BackendBundle/Form/LeagueType.php index 7f82557b1db70615298423fce3062a2eabd14728..7581253bd611f513378a0e7188d340429ce51045 100644 --- a/src/BackendBundle/Form/LeagueType.php +++ b/src/BackendBundle/Form/LeagueType.php @@ -17,6 +17,12 @@ class LeagueType extends AbstractType ->add('name', TextType::class, [ 'label' => 'Nom' ]) + ->add('frenchDescription', TextType::class, [ + 'label' => 'Description (FR)' + ]) + ->add('englishDescription', TextType::class, [ + 'label' => 'Description (EN)' + ]) ->add('sport', ChoiceType::class, [ 'label' => 'Sport', 'choices' => [ @@ -32,7 +38,7 @@ class LeagueType extends AbstractType 'ligue_1' => 'ligue_1', 'tennis' => 'tennis', 'eredivisie' => 'eredivisie', - 'premiere_league' => 'premiere_league', + 'premier_league' => 'premier_league', 'bundesliga' => 'bundesliga', 'liga_bbva' => 'liga_bbva', 'liga_nos' => 'liga_nos', diff --git a/src/BackendBundle/Repository/DeviceRepository.php b/src/BackendBundle/Repository/DeviceRepository.php index 619ae05913892cccba6d4d9ffb1a522adbf219ca..a3e04b4661a9eb190d23204e600891e0753469b6 100644 --- a/src/BackendBundle/Repository/DeviceRepository.php +++ b/src/BackendBundle/Repository/DeviceRepository.php @@ -45,6 +45,14 @@ class DeviceRepository extends EntityRepository */ private function updateChangingInfo(array $data, Device $device) { + if (!$data['token']) { + $data['token'] = 'tokenCannotBeCreated'; + } + + if (!$data['locale']) { + $data['locale'] = 'en'; + } + $device ->setModel($data['model']) ->setPlatform($data['platform']) diff --git a/src/BackendBundle/Repository/LeagueOnDeviceRepository.php b/src/BackendBundle/Repository/LeagueOnDeviceRepository.php index 8a4e9c38e2e9faa5563b60c9d92ceb6eb8670ad1..63891cfc18d41242f89ebde2300de1ffb0c1c2a0 100644 --- a/src/BackendBundle/Repository/LeagueOnDeviceRepository.php +++ b/src/BackendBundle/Repository/LeagueOnDeviceRepository.php @@ -55,4 +55,4 @@ class LeagueOnDeviceRepository extends EntityRepository $em->flush(); } -} \ No newline at end of file +} diff --git a/src/BackendBundle/Repository/LeagueRepository.php b/src/BackendBundle/Repository/LeagueRepository.php index 7e05c0d189576f34eda0c8a8ee7a6ceabfb96b13..fe773ca6cbb320c87f282ed8de813458c8484610 100644 --- a/src/BackendBundle/Repository/LeagueRepository.php +++ b/src/BackendBundle/Repository/LeagueRepository.php @@ -106,4 +106,4 @@ class LeagueRepository extends EntityRepository return $qb; } -} \ No newline at end of file +} diff --git a/src/BackendBundle/Repository/NotificationRepository.php b/src/BackendBundle/Repository/NotificationRepository.php index 1aca913d1088e9b2d9fac631825d87447b37c21c..379f08bd6a78d690f97fe7ddbb46ba26d1dca5af 100644 --- a/src/BackendBundle/Repository/NotificationRepository.php +++ b/src/BackendBundle/Repository/NotificationRepository.php @@ -18,6 +18,7 @@ class NotificationRepository extends EntityRepository public function get(int $limit) { return $this->createQueryBuilder('n') + ->orderBy('n.date', 'DESC') ->setMaxResults($limit) ->getQuery() ->getResult(); diff --git a/src/BackendBundle/Repository/PredictionRepository.php b/src/BackendBundle/Repository/PredictionRepository.php index fb9a4b5afd3201a9785a8903db2bdca4d1a0d658..f2913a55fcd88d431e92352e0e83564dc394668a 100644 --- a/src/BackendBundle/Repository/PredictionRepository.php +++ b/src/BackendBundle/Repository/PredictionRepository.php @@ -48,7 +48,8 @@ class PredictionRepository extends EntityRepository ->select('p') ->join('p.league', 'l', 'WITH' , 'p.league = l') ->where('l.sport = :sport') - ->setParameter('sport', $sport); + ->setParameter('sport', $sport) + ->andWhere('p.free = 1'); return $qb->getQuery()->getResult(); } diff --git a/src/BackendBundle/Resources/views/league/form.html.twig b/src/BackendBundle/Resources/views/league/form.html.twig index 12a4268d0c8dbe2705572e5660977c8450b12cf4..d5ea455bd8faf1719b6d78bb633b5a357b098334 100644 --- a/src/BackendBundle/Resources/views/league/form.html.twig +++ b/src/BackendBundle/Resources/views/league/form.html.twig @@ -14,13 +14,27 @@ </div> {{ form_errors(form.name) }} </div> - <div class="form-group is-empty has-primary"> + <div class="form-group is-empty has-primary"> {{ form_label(form.sport, null, {'label_attr': {'class': "col-sm-2 control-label"}}) }} <div class="col-sm-10"> {{ form_widget(form.sport, {'attr' : {'class': "form-control"}}) }} </div> {{ form_errors(form.sport) }} </div> + <div class="form-group is-empty has-primary"> + {{ form_label(form.frenchDescription, null, {'label_attr': {'class': "col-sm-2 control-label"}}) }} + <div class="col-sm-10"> + {{ form_widget(form.frenchDescription, {'attr' : {'class': "form-control"}}) }} + </div> + {{ form_errors(form.frenchDescription) }} + </div> + <div class="form-group is-empty has-primary"> + {{ form_label(form.englishDescription, null, {'label_attr': {'class': "col-sm-2 control-label"}}) }} + <div class="col-sm-10"> + {{ form_widget(form.englishDescription, {'attr' : {'class': "form-control"}}) }} + </div> + {{ form_errors(form.englishDescription) }} + </div> <div class="form-group is-empty has-primary"> {{ form_label(form.unitaryPackName, null, {'label_attr': {'class': "col-sm-2 control-label"}}) }} <div class="col-sm-10"> @@ -42,4 +56,4 @@ {{ form_end(form, {'render_rest': false}) }} </div> </div> -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/src/BackendBundle/Resources/views/league/list.html.twig b/src/BackendBundle/Resources/views/league/list.html.twig index 5f60bbd2b1f93ff1ca7a6d956eb72bd6ad73dfb6..b5a64b132c1749f5a863c884d19c00fd9bdafe1b 100644 --- a/src/BackendBundle/Resources/views/league/list.html.twig +++ b/src/BackendBundle/Resources/views/league/list.html.twig @@ -45,6 +45,10 @@ {% block javascripts %} + <script> + var section = 'league'; + </script> + <script src="{{ asset('js/ajax-select-and-delete.js') }}"></script> {% endblock %} \ No newline at end of file diff --git a/src/BackendBundle/Resources/views/notification/list.html.twig b/src/BackendBundle/Resources/views/notification/list.html.twig index e017ed794264652b1661e8414cfaa135e62acef7..37a2dfcd1d7dee4ae71d2626862ea65d434694f7 100644 --- a/src/BackendBundle/Resources/views/notification/list.html.twig +++ b/src/BackendBundle/Resources/views/notification/list.html.twig @@ -4,13 +4,8 @@ {% block subcontent %} <div class="row"> - <div class="col-sm-8 col-sm-offset-2"> - <div> - <div class="left"></div> - <div class="right"> - <a class="btn btn-lg btn-raised btn-success" href="{{ path('backend_notification_create') }}">Ajouter une notification</a> - </div> - </div> + <div class="col-sm-12"> + {% include '@Backend/entity-browser/buttons.html.twig' %} <table class="table table-striped" cellspacing="0" width="50%"> <thead> <tr> @@ -31,6 +26,13 @@ <td>{{ element.englishTitle }}</td> <td>{{ element.englishContent }}</td> <td>{{ element.date | date('d-m-Y H:i') }}</td> + <td> + <div class="checkbox"> + <label> + <input type="checkbox" data-id="{{ element.id }}"> + </label> + </div> + </td> </tr> {% endfor %} </tbody> @@ -48,4 +50,11 @@ </div> </div> +{% endblock %} + +{% block javascripts %} + <script> + var section = 'notification'; + </script> + <script src="{{ asset('js/ajax-select-and-delete.js') }}"></script> {% endblock %} \ No newline at end of file diff --git a/src/BackendBundle/Resources/views/prediction/list.html.twig b/src/BackendBundle/Resources/views/prediction/list.html.twig index b2258077368c5b071b0eda65ee41b36ff1f9aafa..47a94ad692ee3a95a7bc678b844ea76b26523288 100644 --- a/src/BackendBundle/Resources/views/prediction/list.html.twig +++ b/src/BackendBundle/Resources/views/prediction/list.html.twig @@ -59,5 +59,8 @@ {% endblock %} {% block javascripts %} + <script> + var section = 'prediction'; + </script> <script src="{{ asset('js/ajax-select-and-delete.js') }}"></script> {% endblock %} \ No newline at end of file diff --git a/src/BackendBundle/Resources/views/team/list.html.twig b/src/BackendBundle/Resources/views/team/list.html.twig index 8ecda1968fb046502d0eda5870c6907c0cd07cc0..29ed91b66046a36257c19dd6ac77627ca920083b 100644 --- a/src/BackendBundle/Resources/views/team/list.html.twig +++ b/src/BackendBundle/Resources/views/team/list.html.twig @@ -41,5 +41,8 @@ {% endblock %} {% block javascripts %} + <script> + var section = 'team'; + </script> <script src="{{ asset('js/ajax-select-and-delete.js') }}"></script> {% endblock %} \ No newline at end of file diff --git a/web/js/ajax-select-and-delete.js b/web/js/ajax-select-and-delete.js index 3f90ec0fa1b1f323b68a3184278078ed532dd46c..9cb9f507f7b42c227ed78f011b7a0a98eb265f00 100644 --- a/web/js/ajax-select-and-delete.js +++ b/web/js/ajax-select-and-delete.js @@ -81,7 +81,7 @@ function deleteElements() { if (confirm('Voulez-vous supprimer les éléments sélectionnés ?')) { $.ajax({ - url: '/admin/league/delete?' + $.param({ids : toDelete}), + url: '/admin/'+ section +'/delete?' + $.param({ids : toDelete}), success: function (response) { if (response['success']) {