Skip to content
Snippets Groups Projects
Commit 8d9e6a0e authored by Pierre Fleutot's avatar Pierre Fleutot
Browse files

Interface de visualisation des lexiques. Listes: utilisation du paramètre...

Interface de visualisation des lexiques. Listes: utilisation du paramètre "force" pour création si agraphie absente du wiko
parent 3aa794db
No related branches found
No related tags found
No related merge requests found
...@@ -156,7 +156,7 @@ class ApiEntryController extends ApiBaseController ...@@ -156,7 +156,7 @@ class ApiEntryController extends ApiBaseController
return $this->createJsonResponse(401, ['error' => sprintf("Les lexiques cibles doivent tous appartenir à la même langue")]); return $this->createJsonResponse(401, ['error' => sprintf("Les lexiques cibles doivent tous appartenir à la même langue")]);
} }
$forceCreation = $data['force'] ?? false; $forceCreation = isset($data['force']) && $data['force'] === true;
$headword = $this->getHeadwordForWord($data['graphy'], $language); $headword = $this->getHeadwordForWord($data['graphy'], $language);
// On récupère ou on crée le mot-vedette // On récupère ou on crée le mot-vedette
......
...@@ -6,6 +6,7 @@ use App\Entity\Entry; ...@@ -6,6 +6,7 @@ use App\Entity\Entry;
use App\Entity\Graphy; use App\Entity\Graphy;
use App\Entity\GraphyList; use App\Entity\GraphyList;
use App\Form\GraphyListType; use App\Form\GraphyListType;
use App\Manager\WiktionaryManager;
use App\Repository\GraphyListRepository; use App\Repository\GraphyListRepository;
use Doctrine\Persistence\ManagerRegistry; use Doctrine\Persistence\ManagerRegistry;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted; use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
...@@ -106,7 +107,7 @@ class ApiGraphyListController extends ApiBaseController ...@@ -106,7 +107,7 @@ class ApiGraphyListController extends ApiBaseController
} }
/** /**
* Ajout de graphies à la liste PAS DE VALIDATION (on crée la graphie dans Balex sans s'assurer qu'elle existe dans le wiktionnaire) * Ajout de graphies à la liste. PAS DE VALIDATION si force=true (on crée la graphie dans Balex sans s'assurer qu'elle existe dans le wiktionnaire)
* *
* @Route("/add-graphies/{id}", name="api_graphy_list_add_graphies", methods={"POST"}) * @Route("/add-graphies/{id}", name="api_graphy_list_add_graphies", methods={"POST"})
* *
...@@ -125,6 +126,7 @@ class ApiGraphyListController extends ApiBaseController ...@@ -125,6 +126,7 @@ class ApiGraphyListController extends ApiBaseController
* required=true, * required=true,
* @OA\JsonContent( * @OA\JsonContent(
* required={"items"}, * required={"items"},
* @OA\Property(property="force", type="bool", example="false", description="force la création de la graphie même si elle n'est pas trouvée dans le wiktionnaire"),
* @OA\Property(property="items", type="array", * @OA\Property(property="items", type="array",
* example={"salut", "les", "amis"}, * example={"salut", "les", "amis"},
* @OA\Items( * @OA\Items(
...@@ -136,7 +138,7 @@ class ApiGraphyListController extends ApiBaseController ...@@ -136,7 +138,7 @@ class ApiGraphyListController extends ApiBaseController
* @OA\Tag(name="Lists") * @OA\Tag(name="Lists")
* @Security(name="OAuth2") * @Security(name="OAuth2")
*/ */
public function addGraphiesToGraphyList(Request $request, GraphyList $graphyList = null): Response public function addGraphiesToGraphyList(WiktionaryManager $wiktionaryManager, Request $request, GraphyList $graphyList = null): Response
{ {
if (!$graphyList) { if (!$graphyList) {
return $this->createJsonResponse(401, ['error' => sprintf("Pas de liste trouvée pour cette id")]); return $this->createJsonResponse(401, ['error' => sprintf("Pas de liste trouvée pour cette id")]);
...@@ -148,6 +150,7 @@ class ApiGraphyListController extends ApiBaseController ...@@ -148,6 +150,7 @@ class ApiGraphyListController extends ApiBaseController
if ($missingFields = $this->getMissingFields($data, ['items'])) { if ($missingFields = $this->getMissingFields($data, ['items'])) {
return $this->createJsonResponse(401, ['error' => sprintf("Veuillez fournir une valeur pour: %s", implode(', ', $missingFields))]); return $this->createJsonResponse(401, ['error' => sprintf("Veuillez fournir une valeur pour: %s", implode(', ', $missingFields))]);
} }
$forceCreation = isset($data['force']) && $data['force'] === true;
// Pour chaque mot suggéré par l'utilisateur, on cherche la graphie ou on la crée si elle n'existe pas // Pour chaque mot suggéré par l'utilisateur, on cherche la graphie ou on la crée si elle n'existe pas
// et on la lie à la liste // et on la lie à la liste
...@@ -158,10 +161,14 @@ class ApiGraphyListController extends ApiBaseController ...@@ -158,10 +161,14 @@ class ApiGraphyListController extends ApiBaseController
'language' => $language, 'language' => $language,
]); ]);
if (!$graphy) { if (!$graphy) {
$graphy = new Graphy(); if ($forceCreation || $wiktionaryManager->search($item, $language)) {
$graphy->setLanguage($language); $graphy = new Graphy();
$graphy->setValue($item); $graphy->setLanguage($language);
$this->doctrine->getManager()->persist($graphy); $graphy->setValue($item);
$this->doctrine->getManager()->persist($graphy);
} else {
return $this->createJsonResponse(401, ['warning' => sprintf("Le mot «%s» n'existe pas dans le wiktionnaire.", $item)]);
}
} }
$graphyList->addGraphy($graphy); $graphyList->addGraphy($graphy);
......
...@@ -18,81 +18,23 @@ use Symfony\Component\Routing\Annotation\Route; ...@@ -18,81 +18,23 @@ use Symfony\Component\Routing\Annotation\Route;
class LexiconController extends AbstractController class LexiconController extends AbstractController
{ {
/** /**
* @Route("/", name="app_graphy_list_index", methods={"GET"}) * @Route("/", name="app_lexicon_index", methods={"GET"})
*/ */
public function index(LexiconRepository $lexiconRepository): Response public function index(LexiconRepository $lexiconRepository): Response
{ {
return $this->render('graphy_list/index.html.twig', [ return $this->render('lexicon/index.html.twig', [
'lexicons' => $lexiconRepository->findVisible($this->getUser()), 'lexicons' => $lexiconRepository->findAll(),
]); ]);
} }
/** /**
* @Route("/ajouter", name="app_graphy_list_new", methods={"GET", "POST"}) * @Route("/{id}", name="app_lexicon_show", methods={"GET"})
*/
public function new(Request $request, LexiconRepository $lexiconRepository): Response
{
$lexicon = new Lexicon($this->getUser());
$form = $this->createForm(LexiconType::class, $lexicon);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$lexicon->getLexicon()->setLanguage($form->get('language')->getData());
$lexiconRepository->add($lexicon, true);
return $this->redirectToRoute('app_graphy_list_index');
}
return $this->render('genericForm.html.twig', [
'title' => "Créer un lexicone",
'form' => $form->createView(),
'back_url' => $this->generateUrl('app_graphy_list_index'),
]);
}
/**
* @Route("/{id}", name="app_graphy_list_show", methods={"GET"})
* @IsGranted("Lexicon_VIEW", subject="lexicon")
*/ */
public function show(Lexicon $lexicon): Response public function show(Lexicon $lexicon): Response
{ {
return $this->render('graphy_list/show.html.twig', [ return $this->render('lexicon/show.html.twig', [
'lexicon' => $lexicon, 'lexicon' => $lexicon,
]); ]);
} }
/**
* @Route("/{id}/modifier", name="app_graphy_list_edit", methods={"GET", "POST"})
* @IsGranted("Lexicon_EDIT", subject="lexicon")
*/
public function edit(Request $request, Lexicon $lexicon, LexiconRepository $lexiconRepository): Response
{
$form = $this->createForm(LexiconType::class, $lexicon);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$lexiconRepository->add($lexicon, true);
return $this->redirectToRoute('app_graphy_list_index');
}
return $this->render('genericForm.html.twig', [
'title' => "Modifier un lexicone",
'form' => $form->createView(),
'back_url' => $this->generateUrl('app_graphy_list_show', ['id' => $lexicon->getId()]),
]);
}
/**
* @Route("/{id}/supprimer", name="app_graphy_list_delete", methods={"POST"})
* @IsGranted("Lexicon_DELETE", subject="lexicon")
*/
public function delete(Request $request, Lexicon $lexicon, LexiconRepository $lexiconRepository): Response
{
if ($this->isCsrfTokenValid('delete'.$lexicon->getId(), $request->request->get('_token'))) {
$lexiconRepository->remove($lexicon, true);
}
return $this->redirectToRoute('app_graphy_list_index');
}
} }
...@@ -83,6 +83,18 @@ class Entry ...@@ -83,6 +83,18 @@ class Entry
return $this->getHeadword()->getValue(); return $this->getHeadword()->getValue();
} }
public function getFormattedDefinitions()
{
$result = [];
foreach ($this->getAttributes()['Items'] as $item) {
$definitions = $item['Sense']['Definitions'] ?? [];
foreach ($definitions as $definition) {
$result[] = $item['PartOfSpeech'] . ' : ' . $definition['Def'];
}
}
return array_filter($result);
}
/** /**
* @ORM\PrePersist * @ORM\PrePersist
* @ORM\PreUpdate * @ORM\PreUpdate
......
...@@ -73,6 +73,62 @@ class Headword ...@@ -73,6 +73,62 @@ class Headword
$this->labels = new ArrayCollection(); $this->labels = new ArrayCollection();
} }
/**
* @return Label[]
*/
public function getMorphologicalLabels()
{
$result = [];
foreach ($this->getLabels() as $label) {
if ($label->isMorphological()) {
$result[] = $label;
}
}
return $result;
}
/**
* @return Label[]
*/
public function getThematicLabels()
{
$result = [];
foreach ($this->getLabels() as $label) {
if ($label->isThematic()) {
$result[] = $label;
}
}
return $result;
}
/**
* @return Label[]
*/
public function getListLabels()
{
$result = [];
foreach ($this->getLabels() as $label) {
if ($label->isList()) {
$result[] = $label;
}
}
return $result;
}
/**
* @return Label[]
*/
public function getMilestoneLabels()
{
$result = [];
foreach ($this->getLabels() as $label) {
if ($label->isMilestone()) {
$result[] = $label;
}
}
return $result;
}
/** /**
* @ORM\PrePersist * @ORM\PrePersist
* @ORM\PreUpdate * @ORM\PreUpdate
...@@ -196,8 +252,8 @@ class Headword ...@@ -196,8 +252,8 @@ class Headword
} }
/** /**
* @return Collection<int, Label> * @return Collection|Label[]
*/ */
public function getLabels(): Collection public function getLabels(): Collection
{ {
return $this->labels; return $this->labels;
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
{% include "nav.html.twig" %} {% include "nav.html.twig" %}
{% endblock %} {% endblock %}
<div class="container pt-2"> <div class="{% block container %}container {% endblock %} pt-2">
{% block flash_messages %} {% block flash_messages %}
<div id="flashes" class="row"> <div id="flashes" class="row">
<div class="col-md-12"> <div class="col-md-12">
......
{% extends 'base.html.twig' %}
{% block container %}container-fluid{% endblock %}
{% block title %}Lexiques{% endblock %}
{% block body %}
<div class="row justify-content-center m-5">
<div class="col-md-12">
<h3 class="card-title d-flex justify-content-between">
Lexiques
</h3>
<div class="card mt-3">
<div class="card-body">
<table class="table">
<thead>
<tr>
<th>Id</th>
<th>Langue</th>
<th>Type</th>
<th>Utilisateur</th>
<th>Groupe</th>
<th>Entrées</th>
<th>Listes liées</th>
<th>Date création</th>
<th></th>
</tr>
</thead>
<tbody>
{% for lexicon in lexicons %}
{# @var lexicon \App\Entity\Lexicon #}
<tr>
<td>{{ lexicon.id }}</td>
<td>{{ lexicon.language }}</td>
<td>{{ lexicon.category }}</td>
<td>{{ lexicon.user }}</td>
<td>{{ lexicon.group }}</td>
<td>{{ lexicon.entries|join(', ') }}</td>
<td>{% for graphyList in lexicon.graphyLists %}<span class="badge bg-primary">{{ graphyList }}</span> {% endfor %}</td>
<td>{{ lexicon.createdAt ? lexicon.createdAt|date('Y-m-d H:i:s') : '' }}</td>
<td class="text-end">
<a href="{{ path('app_lexicon_show', {'id': lexicon.id}) }}" class="btn btn-dark btn-xs">Voir</a>
</td>
</tr>
{% else %}
<tr>
<td colspan="9">Aucun lexique</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
{% endblock %}
{% extends 'base.html.twig' %}
{% block container %}container-fluid{% endblock %}
{% block title %}Lexique {{ lexicon.id }}{% endblock %}
{% block body %}
<div class="row justify-content-center m-5">
<div class="col-md-12">
<h1>Lexique {{ lexicon.id }}</h1>
<div class="card mt-4">
<div class="card-body">
<h3 class="card-title d-flex justify-content-between">
Entrées
</h3>
<table class="table">
<thead>
<tr>
<th>Mot-vedette</th>
<th>Morphologie</th>
<th>Thématique</th>
<th>Listes</th>
<th>Objectifs</th>
<th>Définitions</th>
<th>Création</th>
<th>Mise à jour</th>
</tr>
</thead>
<tbody>
{% for entry in lexicon.entries %}
{# @var entry \App\Entity\Entry #}
<tr>
<td>{{ entry }}</td>
<td>{% for label in entry.headword.morphologicalLabels %}<span class="badge bg-primary">{{ label }}</span> {% endfor %}</td>
<td>{% for label in entry.headword.thematicLabels %}<span class="badge bg-secondary">{{ label }}</span> {% endfor %}</td>
<td>{% for label in entry.headword.listLabels %}<span class="badge bg-info">{{ label }}</span> {% endfor %}</td>
<td>{% for label in entry.headword.milestoneLabels %}<span class="badge bg-warning">{{ label }}</span> {% endfor %}</td>
<td>
{% for definition in entry.formattedDefinitions %}
<i class="bi-caret-right-fill"></i> {{ definition }}<br>
{% endfor %}
</td>
<td>{{ entry.createdAt ? entry.createdAt|date('Y-m-d H:i:s') : '' }}</td>
<td>{{ entry.updatedAt ? entry.updatedAt|date('Y-m-d H:i:s') : '' }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
{% endblock %}
...@@ -20,6 +20,9 @@ ...@@ -20,6 +20,9 @@
<li class="nav-item"> <li class="nav-item">
<a class="nav-link {{ 'app_user_index' in app.request.attributes.get('_route') ? 'active' }}" href="{{ path('app_user_index') }}">Utilisateurs</a> <a class="nav-link {{ 'app_user_index' in app.request.attributes.get('_route') ? 'active' }}" href="{{ path('app_user_index') }}">Utilisateurs</a>
</li> </li>
<li class="nav-item">
<a class="nav-link {{ 'app_lexicon_index' in app.request.attributes.get('_route') ? 'active' }}" href="{{ path('app_lexicon_index') }}">Lexiques</a>
</li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="{{ path('app.swagger_ui') }}">Swagger</a> <a class="nav-link" href="{{ path('app.swagger_ui') }}">Swagger</a>
</li> </li>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment