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

Fix création de Label : on doit spécifier la langue à chaque fois

parent 720091ab
No related branches found
No related tags found
No related merge requests found
......@@ -20,7 +20,7 @@ use Symfony\Component\Uid\UuidV1;
class BalexInitializeCommand extends Command
{
protected static $defaultName = "app:balex:initialize";
protected static $defaultDescription = "Initialisation de l'appli Balex. Création lexiques zéros et lexiques nouveaux mots pour chaque langue. Création du label système 'merged";
protected static $defaultDescription = "Initialisation de l'appli Balex. Création lexiques zéros et lexiques nouveaux mots pour chaque langue. Création du label système 'merged'";
/**
* @var EntityManagerInterface
......@@ -64,12 +64,14 @@ class BalexInitializeCommand extends Command
$newWordsLexicon->setCategory(Lexicon::TYPE_NEW_WORDS);
$newWordsLexicon->setLanguage($language);
$this->em->persist($newWordsLexicon);
}
$this->em->flush();
$mergeLabel = new Label(Label::LABEL_CATEGORY_SYSTEM);
$mergeLabel->setName(Label::LABEL_MERGED);
$this->em->persist($mergeLabel);
// Création du label système 'merged' qui est apposé au headword lors du merge API de deux entrées
$mergeLabel = new Label(Label::LABEL_CATEGORY_SYSTEM);
$mergeLabel->setName(Label::LABEL_MERGED);
$mergeLabel->setLanguage($language);
$this->em->persist($mergeLabel);
}
$this->em->flush();
......
......@@ -97,6 +97,7 @@ class ApiGraphyListController extends AppBaseController
$graphyList = new GraphyList($data['category']);
$graphyList->setCreatedBy($this->getUser());
$graphyList->setLanguage($data['language']);
$graphyList->getLabel()->setLanguage($data['language']);
$graphyList->setName($data['name']);
$this->doctrine->getManager()->persist($graphyList);
$this->success[] = sprintf("Liste %s de type %s créée pour la langue %s", $data['name'], $data['category'], $data['language']);
......
......@@ -71,12 +71,13 @@ class ApiLabelController extends AppBaseController
* @OA\RequestBody(
* required=true,
* @OA\JsonContent(
* required={"name", "category", "masters_type"},
* required={"name", "category", "masters_type", "language"},
* @OA\Property(property="name", type="string"),
* @OA\Property(property="category", type="string", example="morphological OR general OR list OR milestone OR institutional"),
* @OA\Property(property="masters_type", type="string", example="user OR group OR public"),
* @OA\Property(property="master_id", type="integer"),
* @OA\Property(property="milestone", type="date")
* @OA\Property(property="language", type="string")
* )
* )
* @OA\Tag(name="Labels")
......@@ -97,6 +98,9 @@ class ApiLabelController extends AppBaseController
if (!in_array($data['masters_type'], Label::MASTERS_TYPES)) {
return $this->createJsonResponse(401, ['error' => sprintf("Le type de masters de label %s n'existe pas", $data['masters_type'])]);
}
if (!in_array($data['language'], $this->getLanguages())) {
return $this->createJsonResponse(401, ['error' => sprintf("Pas de langue trouvée pour: %s", $data['language'])]);
}
$milestone = $data['milestone'] ?? null;
if ($data['category'] === Label::LABEL_CATEGORY_MILESTONE &&
......@@ -105,6 +109,7 @@ class ApiLabelController extends AppBaseController
}
$label = new Label($data['category']);
$label->setLanguage($data['language']);
$mastersType = $data['mastersType'];
$masterId = $data['master_id'] ?? null;
......
......@@ -367,6 +367,7 @@ class AppBaseController extends AbstractController
$mergedLabel = $this->doctrine->getRepository(Label::class)->findOneBy([
'category' => Label::LABEL_CATEGORY_SYSTEM,
'name' => Label::LABEL_MERGED,
'language' => $targetEntry->getLanguage(),
]);
$targetEntry->getHeadword()->addLabel($mergedLabel);
......
......@@ -37,7 +37,9 @@ class GraphyListController extends AbstractController
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$graphyList->getLexicon()->setLanguage($form->get('language')->getData());
$language = $form->get('language')->getData();
$graphyList->getLexicon()->setLanguage($language);
$graphyList->getLabel()->setLanguage($language);
$graphyListRepository->add($graphyList, true);
return $this->redirectToRoute('app_graphy_list_index');
......
......@@ -104,7 +104,7 @@ class WiktionaryManager
// On ajoute automatiquement les labels extraits du wiktionnaire sur le mot-vedette
foreach ($morphologicalLabels as $morphologicalLabel) {
$label = $this->getOrCreateMorphologicalLabel($morphologicalLabel);
$label = $this->getOrCreateMorphologicalLabel($morphologicalLabel, $entry->getLanguage());
$entry->getHeadword()->addLabel($label);
}
......@@ -208,7 +208,7 @@ class WiktionaryManager
return $result;
}
public function getOrCreateMorphologicalLabel($morphologicalLabel)
public function getOrCreateMorphologicalLabel($morphologicalLabel, $language)
{
$label = $this->doctrine->getRepository(Label::class)->findOneBy([
'user' => null,
......@@ -220,6 +220,7 @@ class WiktionaryManager
if (!$label) {
$label = new Label(Label::LABEL_CATEGORY_MORPHOLOGICAL);
$label->setName($morphologicalLabel);
$label->setLanguage($language);
$this->doctrine->getManager()->persist($label);
$this->doctrine->getManager()->flush();
}
......
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