Skip to content
Snippets Groups Projects
Commit a5398c71 authored by Pierre-Raphaël Giraud's avatar Pierre-Raphaël Giraud
Browse files

.

parent a9597064
No related branches found
No related tags found
No related merge requests found
Showing
with 615 additions and 549 deletions
.DS_Store 0 → 100644
File added
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<title>{% block title %}Welcome!{% endblock %}</title> <title>{% block title %}Welcome!{% endblock %}</title>
<link rel="icon" type="image/x-icon" href="{{ asset('favicon.ico') }}" /> <link rel="icon" type="image/x-icon" href="{{ asset('favicon.ico') }}" />
<link rel="apple-touch-icon" href="{{ asset('apple-touch-icon.png') }} /">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Material Design fonts --> <!-- Material Design fonts -->
<link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Roboto:300,400,500,700"> <link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Roboto:300,400,500,700">
......
...@@ -11,7 +11,7 @@ monolog: ...@@ -11,7 +11,7 @@ monolog:
handlers: handlers:
main: main:
type: fingers_crossed type: fingers_crossed
action_level: error action_level: warning
handler: nested handler: nested
nested: nested:
type: stream type: stream
......
...@@ -10,7 +10,10 @@ security: ...@@ -10,7 +10,10 @@ security:
password: $2y$12$fDfPfwAymIT0xEtPDVxATuh39PEh1q7x45d9IOM5e3J87KQtRAcVa password: $2y$12$fDfPfwAymIT0xEtPDVxATuh39PEh1q7x45d9IOM5e3J87KQtRAcVa
roles: 'ROLE_ADMIN' roles: 'ROLE_ADMIN'
betskills: betskills:
password: $2y$12$tkAwLaRwYIXSjr3iPFBYlebEKX.wLxLp10w8o3oAhkPQTbdLBQHoq password: $2a$04$uKSPdigufFVA0judefbqPObYoNlJOpN25g9VT1Ml.A9yfZ4qmVU8i
roles: 'ROLE_ADMIN'
PR:
password: $2a$07$2Cy7Fwzqa1mJSFqIWjaGy.D9QVkj3MNFkz2DoF/DGj1QL2OAlOGIy
roles: 'ROLE_ADMIN' roles: 'ROLE_ADMIN'
firewalls: firewalls:
......
...@@ -29,7 +29,8 @@ ...@@ -29,7 +29,8 @@
"sensio/framework-extra-bundle": "^3.0.2", "sensio/framework-extra-bundle": "^3.0.2",
"incenteev/composer-parameter-handler": "^2.0", "incenteev/composer-parameter-handler": "^2.0",
"jms/serializer-bundle": "^1.1", "jms/serializer-bundle": "^1.1",
"friendsofsymfony/rest-bundle": "^2.1" "friendsofsymfony/rest-bundle": "^2.1",
"guzzlehttp/guzzle": "^6.3",
}, },
"require-dev": { "require-dev": {
"sensio/generator-bundle": "^3.0", "sensio/generator-bundle": "^3.0",
......
This diff is collapsed.
File added
...@@ -59,7 +59,7 @@ class DefaultController extends FOSRestController ...@@ -59,7 +59,7 @@ class DefaultController extends FOSRestController
return $this->handleView($view); return $this->handleView($view);
} catch (\Exception $e) { } catch (\Exception $e) {
$this->getLogger()->err($e->getMessage()); $this->getLogger()->err('Error while retrieving the leagues for this sport (' . $sport . ') : ' . $e->getMessage());
$view = View::create() $view = View::create()
->setStatusCode(400) ->setStatusCode(400)
->setData($e->getMessage()); ->setData($e->getMessage());
...@@ -142,8 +142,13 @@ class DefaultController extends FOSRestController ...@@ -142,8 +142,13 @@ class DefaultController extends FOSRestController
$view = View::create(); $view = View::create();
// log the transaction
$this->get('logger')->warning(print_r($request->getContent(), true));
if ($request->getMethod() === 'POST') { if ($request->getMethod() === 'POST') {
$content = (array)\GuzzleHttp\json_decode($request->getContent()); $this->getLogger()->info('Trying to decode : ' . $request->getContent());
//$content = (array)\GuzzleHttp\json_decode($request->getContent());
$content = json_decode($request->getContent(), true);
$deviceRepository = $this->getDeviceRepository(); $deviceRepository = $this->getDeviceRepository();
if ($device = $deviceRepository->findOneBy(['uuid' => $content['uuid']])) { if ($device = $deviceRepository->findOneBy(['uuid' => $content['uuid']])) {
$deviceRepository->updateInfo($content,$device); $deviceRepository->updateInfo($content,$device);
...@@ -169,7 +174,11 @@ class DefaultController extends FOSRestController ...@@ -169,7 +174,11 @@ class DefaultController extends FOSRestController
{ {
$view = View::create(); $view = View::create();
// log the transaction
$this->get('logger')->warning(print_r($request->getContent(), true));
if ($request->getMethod() === 'POST') { if ($request->getMethod() === 'POST') {
$this->getLogger()->info('Trying to decode : ' . $request->getContent());
$content = (array)\GuzzleHttp\json_decode($request->getContent()); $content = (array)\GuzzleHttp\json_decode($request->getContent());
$deviceRepository = $this->getDeviceRepository(); $deviceRepository = $this->getDeviceRepository();
$device = $deviceRepository->findOneBy(['uuid' => $content['uuid']]); $device = $deviceRepository->findOneBy(['uuid' => $content['uuid']]);
...@@ -178,7 +187,7 @@ class DefaultController extends FOSRestController ...@@ -178,7 +187,7 @@ class DefaultController extends FOSRestController
$notificationRepository->savePurchase($device, $content['transactionId'], $content['leagues']); $notificationRepository->savePurchase($device, $content['transactionId'], $content['leagues']);
} catch (\Exception $e) { } catch (\Exception $e) {
$view->setStatusCode(400); $view->setStatusCode(400);
$this->getLogger()->err($e->getMessage()); $this->getLogger()->err('Error saving the transaction : ' . $e->getMessage());
} }
return $this->handleView($view); return $this->handleView($view);
......
File added
File added
File added
...@@ -13,7 +13,7 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; ...@@ -13,7 +13,7 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
class EntityBrowserController extends Controller class EntityBrowserController extends Controller
{ {
const DEFAULT_PAGE_RESULT = 20; const DEFAULT_PAGE_RESULT = 2000000;
/** /**
* @param string $name * @param string $name
......
...@@ -24,7 +24,7 @@ class NotificationController extends Controller ...@@ -24,7 +24,7 @@ class NotificationController extends Controller
const NOTIFICATION_API_URL = 'https://fcm.googleapis.com/fcm/send'; const NOTIFICATION_API_URL = 'https://fcm.googleapis.com/fcm/send';
const SERVER_KEY = "AAAA6m6eLXI:APA91bHDsojOIQaWHX5nGNGS9Thyn6MAZZvLvvfEEdWmzbOjD7lYqkghcER69wRkiaRb4zfEQ5P5V8ckdVjGUf58CmMqYNhsRPCy75OeugN85oHCOCBvYn7I7czIsy2pScYKgB2eWC0wRxsyw7-iEMwpzf6eZFWM8w"; const SERVER_KEY = "AAAA6m6eLXI:APA91bHDsojOIQaWHX5nGNGS9Thyn6MAZZvLvvfEEdWmzbOjD7lYqkghcER69wRkiaRb4zfEQ5P5V8ckdVjGUf58CmMqYNhsRPCy75OeugN85oHCOCBvYn7I7czIsy2pScYKgB2eWC0wRxsyw7-iEMwpzf6eZFWM8w";
const SENDER_ID = "1006878207346"; const SENDER_ID = "1006878207346";
const DEFAULT_PAGE_RESULT = 20; const DEFAULT_PAGE_RESULT = 200000000;
/** /**
* @param Request $request * @param Request $request
...@@ -46,9 +46,11 @@ class NotificationController extends Controller ...@@ -46,9 +46,11 @@ class NotificationController extends Controller
$devices = $this->getDoctrine()->getRepository('BackendBundle:Device')->findAll(); $devices = $this->getDoctrine()->getRepository('BackendBundle:Device')->findAll();
$client = new Client(); $client = new Client();
foreach ($devices as $device) {
/*foreach ($devices as $device) {
if ($device->getLocale() === 'fr') { if ($device->getLocale() === 'fr') {
$message = [ $message = [
'notification' => [ 'notification' => [
...@@ -82,11 +84,52 @@ class NotificationController extends Controller ...@@ -82,11 +84,52 @@ class NotificationController extends Controller
] ]
]); ]);
} }
} }*/
$messageFR = [
'notification' => [
'title' => $notification->getFrenchTitle(),
'body' => $notification->getFrenchContent(),
"content_available" => 1
],
//'to' => $device->getToken(),
'to' => '/topics/fr',
'priority' => 'high'
];
$messageEN = [
'notification' => [
'title' => $notification->getEnglishTitle(),
'body' => $notification->getEnglishContent(),
"content_available" => 1
],
//'to' => $device->getToken(),
'to' => '/topics/en',
'priority' => 'high'
];
$client->request('POST', self::NOTIFICATION_API_URL, [
'body' => json_encode($messageFR),
'headers'=> [
'Authorization' => 'key='.self::SERVER_KEY,
'Content-Type' => 'application/json',
],
'verify' => false,
]);
$client->request('POST', self::NOTIFICATION_API_URL, [
'body' => json_encode($messageEN),
'headers'=> [
'Authorization' => 'key='.self::SERVER_KEY,
'Content-Type' => 'application/json',
],
'verify' => false,
]);
$notification->setDate(new \DateTime()); $notification->setDate(new \DateTime());
$em = $this->getDoctrine()->getEntityManager(); $em = $this->getDoctrine()->getEntityManager();
$em->persist($notification); $em->persist($notification);
$em->flush();
$this->getDoctrine()->getRepository('BackendBundle:NotificationOnDevice')->updateStatusOnAllDevices($devices, $notification); $this->getDoctrine()->getRepository('BackendBundle:NotificationOnDevice')->updateStatusOnAllDevices($devices, $notification);
$this->addFlash('success', 'La notification a bien été envoyée'); $this->addFlash('success', 'La notification a bien été envoyée');
return $this->redirectToRoute('backend_notification_list', ['page' => 1]); return $this->redirectToRoute('backend_notification_list', ['page' => 1]);
......
<?php
/**
* Created by PhpStorm.
* User: jeremyguiselin
* Date: 23/09/2016
* Time: 08:22
*/
namespace BackendBundle\Controller;
use BackendBundle\Entity\Notification;
use Doctrine\ORM\Tools\Pagination\Paginator;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\BadResponseException;
use GuzzleHttp\Exception\ClientException;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
class NotificationController extends Controller
{
const NOTIFICATION_API_URL = 'https://fcm.googleapis.com/fcm/send';
const SERVER_KEY = "AIzaSyCFdGq-rjzznFOEzDifZGsRoeWT8LFAc9s";
const SENDER_ID = "1006878207346";
const DEFAULT_PAGE_RESULT = 20;
/**
* @param Request $request
* @return Response
*
* @Route("/admin/notification/create")
*/
public function createAction(Request $request)
{
$notification = new Notification();
$form = $this->createForm('BackendBundle\\Form\\NotificationType', $notification);
if ($request->getMethod() === Request::METHOD_POST) {
$form->handleRequest($request);
if ($form->isValid()) {
$devices = $this->getDoctrine()->getRepository('BackendBundle:Device')->findAll();
$client = new Client();
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',[
'form' => $form->createView()
]);
}
/**
* @param Request $request
* @param int $page
* @return Response
*
* @Route("/admin/notification/list/{page}")
*/
public function listAction(Request $request, int $page)
{
$em = $this->getDoctrine()->getManager();
if (!isset($page)) {
$page = 1;
}
$repository = $em->getRepository('BackendBundle:Notification');
$query = $repository->getAll();
$firstResult = $page === 1 ? 0 : self::DEFAULT_PAGE_RESULT * ($page-1) - 1;
$pagination = new Paginator($query);
$totalItems = count($pagination);
$pagesCount = ceil($totalItems / self::DEFAULT_PAGE_RESULT) >= 1 ? ceil($totalItems / self::DEFAULT_PAGE_RESULT) : 1;
$pagination->getQuery()
->setMaxResults(self::DEFAULT_PAGE_RESULT)
->setFirstResult($firstResult)
;
return $this->render(
'BackendBundle:notification:list.html.twig',
[
'elements' => $pagination,
'countPages' => $pagesCount,
'page' => $page
]
);
}
}
\ No newline at end of file
...@@ -164,6 +164,7 @@ class League ...@@ -164,6 +164,7 @@ class League
*/ */
public function getPredictionsNumber() public function getPredictionsNumber()
{ {
return 999;
return $this->predictionsNumber; return $this->predictionsNumber;
} }
...@@ -264,4 +265,9 @@ class League ...@@ -264,4 +265,9 @@ class League
{ {
return $this->englishDescription; return $this->englishDescription;
} }
public function __toString()
{
return $this->getName() . ' - ' . $this->getFrenchDescription() ;
}
} }
...@@ -24,7 +24,7 @@ class Transaction ...@@ -24,7 +24,7 @@ class Transaction
/** /**
* @var string * @var string
* *
* @ORM\Column(name="store_transaction_id", type="string", length=255, unique=true) * @ORM\Column(name="store_transaction_id", type="string", length=255)
*/ */
private $storeTransactionId; private $storeTransactionId;
......
...@@ -27,8 +27,7 @@ class PredictionType extends AbstractType ...@@ -27,8 +27,7 @@ class PredictionType extends AbstractType
]) ])
->add('league', EntityType::class, [ ->add('league', EntityType::class, [
'label' => 'Ligue', 'label' => 'Ligue',
'class' => 'BackendBundle\Entity\League', 'class' => 'BackendBundle\Entity\League'
'choice_label' => 'name'
]) ])
->add('date', DateTimeType::class, [ ->add('date', DateTimeType::class, [
'format' => "yyyy-MM-dd HH:mm", 'format' => "yyyy-MM-dd HH:mm",
......
...@@ -55,8 +55,12 @@ class DeviceRepository extends EntityRepository ...@@ -55,8 +55,12 @@ class DeviceRepository extends EntityRepository
$device $device
->setModel($data['model']) ->setModel($data['model'])
->setPlatform($data['platform']) ->setPlatform($data['platform']);
->setToken($data['token']) if ($device->getToken() === 'tokenCannotBeCreated' || !$device->getToken()) {
$device->setToken($data['token']);
}
$device
->setLocale($data['locale']) ->setLocale($data['locale'])
->setVersion($data['version']); ->setVersion($data['version']);
} }
......
...@@ -33,9 +33,10 @@ class LeagueRepository extends EntityRepository ...@@ -33,9 +33,10 @@ class LeagueRepository extends EntityRepository
$qb = $this->getEntityManager()->getRepository('BackendBundle:Prediction')->createQueryBuilder('p'); $qb = $this->getEntityManager()->getRepository('BackendBundle:Prediction')->createQueryBuilder('p');
$qb $qb
->select('count(p.id) AS predictions, l.name AS name, min(p.date) as minDate, max(p.date) as maxDate') ->select('count(p.id) AS predictions, l.id AS leagueId, l.name AS name, min(p.date) as minDate, max(p.date) as maxDate')
->join('p.league', 'l', Join::WITH, 'p.league = l') ->join('p.league', 'l', Join::WITH, 'p.league = l')
->where('l in (:leagues)') ->where('l in (:leagues)')
->andWhere('p.score IS NULL')
->setParameter('leagues', $leagues) ->setParameter('leagues', $leagues)
->groupBy('l'); ->groupBy('l');
...@@ -43,7 +44,7 @@ class LeagueRepository extends EntityRepository ...@@ -43,7 +44,7 @@ class LeagueRepository extends EntityRepository
$qb = $this->getEntityManager()->getRepository('BackendBundle:LeagueOnDevice')->createQueryBuilder('ld'); $qb = $this->getEntityManager()->getRepository('BackendBundle:LeagueOnDevice')->createQueryBuilder('ld');
$qb $qb
->select('ld.status AS status, l.name AS name') ->select('ld.status AS status, l.id AS leagueId, l.name AS name')
->join('ld.league', 'l', Join::WITH, 'ld.league = l') ->join('ld.league', 'l', Join::WITH, 'ld.league = l')
->where('l in (:leagues)') ->where('l in (:leagues)')
->setParameter('leagues', $leagues) ->setParameter('leagues', $leagues)
...@@ -56,7 +57,7 @@ class LeagueRepository extends EntityRepository ...@@ -56,7 +57,7 @@ class LeagueRepository extends EntityRepository
$predictions = []; $predictions = [];
foreach ($leagueResult as $r) { foreach ($leagueResult as $r) {
$predictions[$r['name']] = [ $predictions[$r['leagueId']] = [
'number' => (int) $r['predictions'], 'number' => (int) $r['predictions'],
'min_date' => $r['minDate'], 'min_date' => $r['minDate'],
'max_date' => $r['maxDate'] 'max_date' => $r['maxDate']
...@@ -64,18 +65,21 @@ class LeagueRepository extends EntityRepository ...@@ -64,18 +65,21 @@ class LeagueRepository extends EntityRepository
} }
foreach ($leagueOnDeviceResult as $r) { foreach ($leagueOnDeviceResult as $r) {
$predictions[$r['name']]['status'] = $r['status']; $predictions[$r['leagueId']]['status'] = $r['status'];
} }
foreach ($leagues as $league) { foreach ($leagues as $league) {
if (isset ($predictions[$league->getName()])) { if (isset ($predictions[$league->getId()])) {
$prediction = $predictions[$league->getName()]; $prediction = $predictions[$league->getId()];
$league->setPredictionsNumber($prediction['number']); $league->setPredictionsNumber($prediction['number']);
$league->setMinDate($prediction['min_date']); $league->setMinDate($prediction['min_date']);
$league->setMaxDate($prediction['max_date']); $league->setMaxDate($prediction['max_date']);
$league->setDeviceStatus($prediction['status']); $league->setDeviceStatus($prediction['status']);
} else { } else {
$league->setPredictionsNumber(0); $league->setPredictionsNumber(0);
$league->setMinDate('');
$league->setMaxDate('');
$league->setDeviceStatus('lock');
} }
} }
......
...@@ -5,7 +5,15 @@ ...@@ -5,7 +5,15 @@
{% block subcontent %} {% block subcontent %}
<div class="row"> <div class="row">
<div class="col-sm-12 table-container"> <div class="col-sm-12 table-container">
{% include '@Backend/entity-browser/buttons.html.twig' %} <div>
<div class="left">
<a href="{{ path('backend_notification_create') }}" class="btn btn-lg btn-raised btn-success">Ajouter une nouvelle notification</a>
</div>
<div class="right">
<a onclick="selectAll(this)" id="selectAll" class="btn btn-lg btn-raised btn-info">Selectionner tout</a>
<a onclick="deleteElements()" id="deleteButton" class="btn btn-lg btn-raised btn-danger">Supprimer</a>
</div>
</div>
<table class="table table-striped" cellspacing="0" width="50%"> <table class="table table-striped" cellspacing="0" width="50%">
<thead> <thead>
<tr> <tr>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment