From 3ea68da8f28312fc825ce2e5d7807a22f2c31e34 Mon Sep 17 00:00:00 2001 From: Jeremy Guiselin <jeremy.guiselin@student.ecp.fr> Date: Thu, 9 Feb 2017 19:15:02 -0500 Subject: [PATCH] Clean repo + correct bug on delete --- .../Controller/DefaultController.php | 6 ++- .../Controller/EntityBrowserController.php | 2 +- .../Controller/NotificationController.php | 34 ++++++++++------ src/BackendBundle/Entity/League.php | 40 +++++++++++++++++++ src/BackendBundle/Form/LeagueType.php | 8 +++- .../Repository/DeviceRepository.php | 8 ++++ .../Repository/LeagueOnDeviceRepository.php | 2 +- .../Repository/LeagueRepository.php | 2 +- .../Repository/NotificationRepository.php | 1 + .../Repository/PredictionRepository.php | 3 +- .../Resources/views/league/form.html.twig | 18 ++++++++- .../Resources/views/league/list.html.twig | 4 ++ .../views/notification/list.html.twig | 23 +++++++---- .../Resources/views/prediction/list.html.twig | 3 ++ .../Resources/views/team/list.html.twig | 3 ++ web/js/ajax-select-and-delete.js | 2 +- 16 files changed, 129 insertions(+), 30 deletions(-) diff --git a/src/ApiBundle/Controller/DefaultController.php b/src/ApiBundle/Controller/DefaultController.php index c108c3c..89a6440 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 f9914cf..6d6cec3 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 453fb0f..78c1666 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 ec8950e..d9204cf 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 7f82557..7581253 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 619ae05..a3e04b4 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 8a4e9c3..63891cf 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 7e05c0d..fe773ca 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 1aca913..379f08b 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 fb9a4b5..f2913a5 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 12a4268..d5ea455 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 5f60bbd..b5a64b1 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 e017ed7..37a2dfc 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 b225807..47a94ad 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 8ecda19..29ed91b 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 3f90ec0..9cb9f50 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']) { -- GitLab