Skip to content

Commit

Permalink
Merge pull request #57 from VEAF/feature/52-add-perun-player-edition
Browse files Browse the repository at this point in the history
Feature/52 add perun player edition
  • Loading branch information
mitch10593 authored Feb 13, 2021
2 parents 271b50b + 059462e commit 1a6fd98
Show file tree
Hide file tree
Showing 17 changed files with 505 additions and 435 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"symfony/validator": "4.4.*",
"symfony/web-link": "4.4.*",
"symfony/yaml": "4.4.*",
"tetranz/select2entity-bundle": "^3.1",
"twig/extra-bundle": "^2.12|^3.0",
"twig/twig": "^2.12|^3.0"
},
Expand Down
55 changes: 54 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@
Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle::class => ['all' => true],
Karser\Recaptcha3Bundle\KarserRecaptcha3Bundle::class => ['all' => true],
Knp\Bundle\TimeBundle\KnpTimeBundle::class => ['all' => true],
Tetranz\Select2EntityBundle\TetranzSelect2EntityBundle::class => ['all' => true],
];
3 changes: 3 additions & 0 deletions config/packages/tetranz.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
services:
Tetranz\Select2EntityBundle\Service\AutocompleteService:
alias: tetranz_select2entity.autocomplete_service
4 changes: 3 additions & 1 deletion config/packages/twig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ twig:
exception_controller: null
globals:
cdn_veaf: '%cdn_veaf%'
form_themes: ['bootstrap_4_layout.html.twig']
form_themes:
- 'bootstrap_4_layout.html.twig'
- '@TetranzSelect2Entity/Form/fields.html.twig'
78 changes: 78 additions & 0 deletions src/Controller/Admin/Dcs/PlayerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@

namespace App\Controller\Admin\Dcs;

use App\Form\PlayerLinkType;
use App\Perun\Entity\Player;
use Kilik\TableBundle\Components\Column;
use Kilik\TableBundle\Components\Filter;
use Kilik\TableBundle\Components\Table;
use Kilik\TableBundle\Services\TableService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Tetranz\Select2EntityBundle\Service\AutocompleteService;

/**
* @Route("/admin/dcs/player")
Expand Down Expand Up @@ -79,4 +82,79 @@ public function _listAction(TableService $tableService, Request $request)
{
return $tableService->handleRequest($this->getTable(), $request);
}

/**
* Used on player link form
*
* @Route("/autocomplete", name="admin_dcs_player_autocomplete")
*/
public function search(AutocompleteService $autocompleteService, Request $request): Response
{
$result = $autocompleteService->getAutocompleteResults($request, PlayerLinkType::class);

return new JsonResponse($result);
}

/**
* @Route("/{player}/edit", name="admin_dcs_player_edit")
*/
public function edit(Request $request, Player $player): Response
{
$form = $this->createForm(PlayerLinkType::class, $player);

$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$user = $player->getUser();
$user->setPlayer($player); // User own the OneToOne relation
$this->getDoctrine()->getManager()->flush();
$this->addFlash('success', 'Le joueur a été enregistré');

return $this->redirectToRoute('admin_dcs_player_view', ['player' => $player->getId()]);
}

return $this->render('admin/dcs/player/edit.html.twig', [
'form' => $form->createView(),
'player' => $player,
]);
}

/**
* @Route("/{player}/remove-link", name="admin_dcs_player_remove_link")
*/
public function removeLink(Request $request, Player $player): Response
{
$form = $this->createFormBuilder()->setMethod('POST')->getForm();

$form->handleRequest($request);

if (null === $player->getUser()) {
return $this->redirectToRoute('admin_dcs_player_view', ['player' => $player->getId()]);
}

if ($form->isSubmitted() && $form->isValid()) {
$user = $player->getUser();
$user->setPlayer(null); // User own the OneToOne relation
$this->getDoctrine()->getManager()->flush();
$this->addFlash('success', 'Le joueur a été enregistré');

return $this->redirectToRoute('admin_dcs_player_view', ['player' => $player->getId()]);
}

return $this->render('admin/dcs/player/remove_link.html.twig', [
'form' => $form->createView(),
'player' => $player,
]);
}

/**
* @Route("/{player}", name="admin_dcs_player_view")
*/
public function view(Request $request, Player $player): Response
{
return $this->render('admin/dcs/player/view.html.twig', [
'player' => $player,
]);
}

}
13 changes: 12 additions & 1 deletion src/Controller/Admin/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class UserController extends AbstractController
public function getTable(): Table
{
$queryBuilder = $this->getDoctrine()->getRepository(User::class)->createQueryBuilder('u')
->select('u');
->select('u, p')
->leftJoin('u.player', 'p');

$booleanFilterChoices = ['Oui' => true, 'Non' => false];

Expand Down Expand Up @@ -112,6 +113,16 @@ public function getTable(): Table
})
);

$table
->addColumn(
(new Column())->setLabel('Pseudo DCS')
->setSort(['p.lastName' => 'asc'])
->setFilter((new Filter())
->setField('p.lastName')
->setName('p_lastName')
)
);

return $table;
}

Expand Down
9 changes: 7 additions & 2 deletions src/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public function setEmail(string $email): self
*/
public function getUsername(): string
{
return (string) $this->email;
return (string)$this->email;
}

/**
Expand All @@ -227,7 +227,7 @@ public function setRoles(array $roles): self
*/
public function getPassword(): string
{
return (string) $this->password;
return (string)$this->password;
}

public function setPassword(string $password): self
Expand Down Expand Up @@ -427,4 +427,9 @@ public static function getGroupStatuses(string $group)
}
}
}

public function __toString(): string
{
return $this->nickname;
}
}
46 changes: 46 additions & 0 deletions src/Form/PlayerLinkType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace App\Form;

use App\Entity\User;
use App\Perun\Entity\Player;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Tetranz\Select2EntityBundle\Form\Type\Select2EntityType;

class PlayerLinkType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('user', Select2EntityType::class, [
'multiple' => false,
'remote_route' => 'admin_dcs_player_autocomplete',
'remote_params' => [], // static route parameters for request->query
'class' => User::class,
'primary_key' => 'id',
'text_property' => 'nickname',
'property' => 'nickname',
'minimum_input_length' => 3,
'page_limit' => 10,
'allow_clear' => false,
'delay' => 250,
'language' => 'fr',
'placeholder' => 'Sélectionner un utilisateur',
'callback' => function (QueryBuilder $qb, $data) {
$qb->andWhere('e.player is null');

},
]);
}

public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Player::class,
]);
}
}
3 changes: 3 additions & 0 deletions symfony.lock
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,9 @@
"symfony/yaml": {
"version": "v4.4.19"
},
"tetranz/select2entity-bundle": {
"version": "v3.1.0"
},
"theofidry/alice-data-fixtures": {
"version": "1.0",
"recipe": {
Expand Down
2 changes: 1 addition & 1 deletion templates/admin/dcs/player/_list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
{% endblock tableHeadStdFilters %}
{% block tableBodyStdColumns %}
<td>
<a href="#todo"><span class="fa fa-eye"></span></a>
<a href="{{ path('admin_dcs_player_view', {'player': row.object.id}) }}"><span class="fa fa-eye"></span></a>
</td>
{{ parent() }}
{% endblock tableBodyStdColumns %}
45 changes: 45 additions & 0 deletions templates/admin/dcs/player/edit.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{% extends 'admin/layout.html.twig' %}
{% set libKilikTable=true %}
{% set section="admin" %}
{% set subSection="player" %}

{% block pageContent %}
<div class="row mb-4">
<div class="col-md-6">
<div class="bs-component">
<div class="card mb-3">
<h3 class="card-header">Modifier le joueur DCS</h3>
<div class="card-body">
<table class="table">
<tr>
<td>
Dernier Pseudo:
</td>
<td>
{{ player.lastName }}
</td>
</tr>
</table>
{{ form_start(form) }}
{{ form_rest(form) }}
{{ form_errors(form) }}
<div class="row">
<div class="col-sm-6">
<a href="{{ path('admin_dcs_player_view', {'player': player.id}) }}"
class="btn btn-lg btn-primary form-control">
<i class="fa fa-arrow-circle-left"></i> Annuler
</a>
</div>
<div class="col-sm-6">
<button class="btn btn-lg btn-danger form-control " type="submit">
<i class="fa fa-save"></i> Enregistrer
</button>
</div>
</div>
{{ form_end(form) }}
</div>
</div>
</div>
</div>
</div>
{% endblock pageContent %}
Loading

0 comments on commit 1a6fd98

Please sign in to comment.