Skip to content
Snippets Groups Projects
Commit 3ea68da8 authored by Jeremy Guiselin's avatar Jeremy Guiselin
Browse files

Clean repo + correct bug on delete

parent 0d48dfce
Branches
No related tags found
No related merge requests found
Showing
with 129 additions and 30 deletions
......@@ -49,7 +49,9 @@ class DefaultController extends FOSRestController
public function getLeaguesBySportAction(string $uuid, string $sport)
{
try {
while ($device === null) {
$device = $this->getDeviceRepository()->findOneBy(['uuid' => $uuid]);
}
$leagues = $this->getLeagueRepository()->findBySport($sport, $device);
$view = View::create()
->setStatusCode(200)
......
......@@ -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)
{
......
......@@ -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,20 +53,27 @@ 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'
];
}
if ($device->getToken() !== 'BLACKLISTED') {
$client->request('POST', self::NOTIFICATION_API_URL, [
'body' => json_encode($message),
'headers'=> [
......@@ -75,6 +82,7 @@ class NotificationController extends Controller
]
]);
}
}
$notification->setDate(new \DateTime());
$em = $this->getDoctrine()->getEntityManager();
......
......@@ -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;
}
}
......@@ -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',
......
......@@ -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'])
......
......@@ -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();
......
......@@ -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();
}
......
......@@ -21,6 +21,20 @@
</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">
......
......@@ -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
......@@ -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>
......@@ -49,3 +51,10 @@
</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
......@@ -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
......@@ -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
......@@ -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']) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment