Commit 9fbf32ea authored by Sylvain Hatier's avatar Sylvain Hatier Committed by Arnaud Bey
Browse files

WIP : update des modes conquer, constraint avec nouveau lexique

parent c0dded2c
......@@ -5,12 +5,13 @@ namespace LexiconBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use JsonSerializable;
/**
* @ORM\Table(name="lexicon_word")
* @ORM\Entity(repositoryClass="LexiconBundle\Repository\WordRepository")
*/
class Word
class Word implements JsonSerializable
{
/**
* @ORM\Id()
......@@ -145,4 +146,13 @@ class Word
return $this;
}
public function jsonSerialize()
{
return array(
'id' => $this->id,
'value' => $this->value,
'cleanValue' => $this->cleanValue,
);
}
}
......@@ -28,15 +28,15 @@ class LetterManager
{
$string2print="Lettre Language= ".$language->getValue()."\n";
foreach ($letters as $letterValue) {
if (ctype_alnum($letterValue)) {
$letter = new Letter();
$letter->setLanguage($language);
$letter->setValue($letterValue);
$letter->setPoints(isset($weights[$letterValue]) ? $weights[$letterValue] : 1);
// $string2print="Lettre OK ctype_alpha = ".$letterValue."\n";
// if (ctype_alnum($letterValue)) {
$letter = new Letter();
$letter->setLanguage($language);
$letter->setValue($letterValue);
$letter->setPoints(isset($weights[$letterValue]) ? $weights[$letterValue] : 1);
// $string2print="Lettre OK ctype_alpha = ".$letterValue."\n";
$this->em->persist($letter);
}
$this->em->persist($letter);
// }
}
return;
}
......
......@@ -41,6 +41,15 @@ class WordManager
return;
}
public function checkExistence($word, Language $language)
{
$word = $this->em->getRepository('LexiconBundle:Word')->getByLanguageAndContentOrCleaned($language, $word);
return $word;
}
public function createStarts(Language $language, $wordStarts)
{
$languageId = $language->getId();
......
......@@ -36,4 +36,19 @@ class WordRepository extends \Doctrine\ORM\EntityRepository
->getResult()
;
}
public function getByLanguageAndContentOrCleaned($language, $value)
{
$em = $this->_em;
$dql = 'SELECT w FROM LexiconBundle\Entity\Word w
WHERE w.language = :language
AND (w.value = :value OR w.cleanValue = :value)';
$query = $em->createQuery($dql);
$query->setParameter('language', $language)
->setParameter('value', $value)
->setMaxResults(1);
return $query->getOneOrNullResult();
}
}
......@@ -16,7 +16,8 @@ class LetterController extends Controller
*/
public function getInflectionAction(Language $language)
{
$letters = $this->get('mw_manager.letter_language')->getWeightedLettersByLanguage($language);
// $letters = $this->get('mw_manager.letter_language')->getWeightedLettersByLanguage($language);
$letters = $this->get('mw_manager.letter_language')->lottery($language, 4);
return new JsonResponse($letters);
}
......
......@@ -8,32 +8,32 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
use MagicWordBundle\Entity\Lexicon\Inflection;
use MagicWordBundle\Entity\Lexicon\Word;
use LexiconBundle\Entity\Language;
class InflectionController extends Controller
{
/**
* @Route("/inflection/{id}", name="inflection", requirements={
* @Route("/word/{id}", name="word", requirements={
* "page": "\d+"
* })
* @ParamConverter("inflexion", class="MagicWordBundle:Lexicon\Inflection")
* @ParamConverter("inflexion", class="MagicWordBundle:Lexicon\Word")
*/
public function getInfosAction(Inflection $inflection)
public function getInfosAction(Word $word)
{
return $this->render('MagicWordBundle:Lexicon:inflection.html.twig', array('inflection' => $inflection));
return $this->render('MagicWordBundle:Lexicon:word.html.twig', array('word' => $word));
}
/**
* @Route("/inflection/check/{id}", name="check_existence", options={"expose"=true})
* @Route("/word/check/{id}", name="check_existence", options={"expose"=true})
* @ParamConverter("language", class="LexiconBundle:Language")
* @Method("POST")
*/
public function checkExistenceAction(Language $language, Request $request)
{
$inflection = $request->request->get('inflection');
$inflection = $this->get('lexicon_inflection')->checkExistence($inflection, $language);
$word = $request->request->get('word');
$word = $this->get('lexicon_manager.word')->checkExistence($word, $language);
return new JsonResponse($inflection);
return new JsonResponse($word);
}
}
......@@ -5,16 +5,16 @@ namespace MagicWordBundle\Controller\Lexicon;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use LexiconBundle\Entity\Lemma;
use LexiconBundle\Entity\Root;
class LemmaController extends Controller
{
/**
* @Route("/lemma/{id}", name="lemma")
* @ParamConverter("lemma", class="LexiconBundle:Lemma")
* @Route("/root/{id}", name="root")
* @ParamConverter("root", class="LexiconBundle:Root")
*/
public function getInfosAction(Lemma $lemma)
public function getInfosAction(Root $root)
{
return $this->render('MagicWordBundle:Lexicon:lemma.html.twig', array('lemma' => $lemma));
return $this->render('MagicWordBundle:Lexicon:lemma.html.twig', array('root' => $root));
}
}
......@@ -24,7 +24,7 @@ class RushController extends Controller
* @Route("/rush/{id}/save-grid", name="rush_save_grid" , options={"expose"=true})
* @ParamConverter("rush", class="MagicWordBundle:RoundType\Rush")
*/
public function saveConquerGridAction(Rush $rush, Request $request)
public function saveRushGridAction(Rush $rush, Request $request)
{
$this->get('mw_manager.round')->saveRushGrid($rush, $request);
$foundableForms = $rush->getGrid()->getFoundableForms();
......
......@@ -3,7 +3,7 @@
namespace MagicWordBundle\Controller;
use LexiconBundle\Entity\Language;
use LexiconBundle\Entity\Lemma;
use LexiconBundle\Entity\Root;
use MagicWordBundle\Entity\Player;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
......@@ -43,22 +43,22 @@ class WordboxController extends Controller
/**
* @Route("/wordbox/add/{id}", name="add-to-wordbox")
* @ParamConverter("lemma", class="LexiconBundle:Lemma")
* @ParamConverter("root", class="LexiconBundle:Root")
*/
public function addToWordboxAction(Lemma $lemma)
public function addToWordboxAction(Root $root)
{
$this->get('mw_manager.wordbox')->addToWordbox($lemma, 'manual');
$this->get('mw_manager.wordbox')->addToWordbox($root, 'manual');
return $this->redirectToRoute('wordbox');
}
/**
* @Route("/js/wordbox/add/{id}", name="add-to-wordbox-js", options={"expose"=true})
* @ParamConverter("lemma", class="LexiconBundle:Lemma")
* @ParamConverter("root", class="LexiconBundle:Root")
*/
public function addToWordboxJSAction(Lemma $lemma)
public function addToWordboxJSAction(Root $root)
{
$this->get('mw_manager.wordbox')->addToWordbox($lemma, 'manual');
$this->get('mw_manager.wordbox')->addToWordbox($root, 'manual');
return new Response();
}
......
......@@ -27,11 +27,10 @@ class Square
protected $letter;
/**
* @ORM\ManyToOne(targetEntity="Grid", inversedBy="squares", cascade={"remove"})
* @ORM\ManyToOne(targetEntity="Grid", inversedBy="squares")
*/
private $grid;
/**
* Get id.
*
......
......@@ -125,4 +125,28 @@ class Acquisition
{
return $this->wordbox;
}
/**
* Set root.
*
* @param \LexiconBundle\Entity\Root|null $root
*
* @return Acquisition
*/
public function setRoot(\LexiconBundle\Entity\Root $root = null)
{
$this->root = $root;
return $this;
}
/**
* Get root.
*
* @return \LexiconBundle\Entity\Root|null
*/
public function getRoot()
{
return $this->root;
}
}
......@@ -24,74 +24,14 @@ class ConstraintType extends AbstractType
],
));
$builder->add('category', EntityType::class, array(
'class' => 'LexiconBundle:Category',
'placeholder' => '- category -',
$builder->add('feature', EntityType::class, array(
'class' => 'LexiconBundle:Feature',
'placeholder' => '- feature -',
'required' => false,
'empty_data' => null,
'choice_label' => 'value',
'attr' => array('class' => 'form-control'),
'label' => 'category',
'translation_domain' => 'messages',
'choice_translation_domain' => 'messages',
));
$builder->add('number', EntityType::class, array(
'class' => 'LexiconBundle:Number',
'placeholder' => '- number -',
'required' => false,
'empty_data' => null,
'choice_label' => 'value',
'attr' => array('class' => 'form-control'),
'label' => 'number',
'translation_domain' => 'messages',
'choice_translation_domain' => 'messages',
));
$builder->add('gender', EntityType::class, array(
'class' => 'LexiconBundle:Gender',
'placeholder' => '- gender -',
'required' => false,
'empty_data' => null,
'choice_label' => 'value',
'attr' => array('class' => 'form-control'),
'label' => 'gender',
'translation_domain' => 'messages',
'choice_translation_domain' => 'messages',
));
$builder->add('tense', EntityType::class, array(
'class' => 'LexiconBundle:Tense',
'placeholder' => '- tense -',
'required' => false,
'empty_data' => null,
'choice_label' => 'value',
'attr' => array('class' => 'form-control verb'),
'label' => 'tense',
'translation_domain' => 'messages',
'choice_translation_domain' => 'messages',
));
$builder->add('person', EntityType::class, array(
'class' => 'LexiconBundle:Person',
'placeholder' => '- person -',
'required' => false,
'empty_data' => null,
'choice_label' => 'value',
'attr' => array('class' => 'form-control verb'),
'label' => 'person',
'translation_domain' => 'messages',
'choice_translation_domain' => 'messages',
));
$builder->add('mood', EntityType::class, array(
'class' => 'LexiconBundle:Mood',
'placeholder' => '- mood -',
'required' => false,
'empty_data' => null,
'choice_label' => 'value',
'attr' => array('class' => 'form-control verb'),
'label' => 'mood',
'label' => 'feature',
'translation_domain' => 'messages',
'choice_translation_domain' => 'messages',
));
......
......@@ -12,10 +12,12 @@ class FindWordType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('inflection', TextType::class, array(
$builder->add(
'inflection',
TextType::class,
array(
'attr' => [
'data-field' => 'inflection',
'pattern' => '[A-Za-z]+',
'placeholder' => 'form',
'translation_domain' => 'messages',
],
......@@ -32,7 +34,7 @@ class FindWordType extends AbstractType
));
$builder->add('lemmaEnough', ChoiceType::class, array(
'label' => 'Is lemma enough ?',
'label' => 'Is root enough ?',
'required' => true,
'choices' => array(
'Non' => '0',
......
......@@ -26,7 +26,7 @@ class RoundMiscType extends AbstractType
$builder->add('language', EntityType::class, array(
'label' => 'game_language',
'class' => 'LexiconBundle:Language',
'choice_label' => 'name',
'choice_label' => 'value',
'attr' => array('class' => 'form-control'),
'translation_domain' => 'messages',
'choice_translation_domain' => 'messages',
......
......@@ -79,7 +79,7 @@ class GridManager
$languageId = $request->request->get('language');
$language = $this->em->getRepository('LexiconBundle:Language')->find($languageId);
$grid = $this->newGrid($language);
$grid = $this->newGrid($language, 4);
$this->addSquares($grid, $request->request->get('squares'));
......@@ -93,7 +93,8 @@ class GridManager
public function updateGrid(Grid $grid, Request $request, $round)
{
$grid->setLanguage($round->getLanguage());
$this->removeSquare($grid);
$this->removeSquares($grid);
$this->removeFoundables($grid);
$this->em->refresh($grid);
......@@ -110,7 +111,7 @@ class GridManager
public function saveInflections(Grid $grid)
{
$this->em->getConnection()->getConfiguration()->setSQLLogger(null);
$inflections = $this->findInflections($grid);
$inflections = $this->findWords($grid);
$this->foundableFormManager->populateFoundables($inflections, $grid);
$this->em->persist($grid);
......@@ -119,14 +120,15 @@ class GridManager
return $grid;
}
private function removeSquare(Grid $grid)
private function removeSquares(Grid $grid)
{
$squares = $grid->getSquares();
foreach ($squares as $square) {
$this->em->remove($square);
}
$this->em->flush();
return;
}
private function removeFoundables(Grid $grid)
......@@ -151,7 +153,7 @@ class GridManager
public function getInflections(Request $request)
{
$grid = $this->createGrid($request, false);
$inflections = $this->findInflections($grid);
$inflections = $this->findWords($grid);
return $inflections;
}
......@@ -159,7 +161,7 @@ class GridManager
public function getFoundableForms(Request $request)
{
$grid = $this->createGrid($request, false);
$inflections = $this->findInflections($grid);
$inflections = $this->findWords($grid);
$this->foundableFormManager->populateFoundables($inflections, $grid);
......@@ -247,7 +249,7 @@ class GridManager
// la détruire dans la grille
$grid[$y][$x] = '_';
$wordLongEnough = strlen($word) > 1;
$wordLongEnough = mb_strlen($word) > 1;
if ($wordLongEnough) {
// vérifier en bdd s'il existe des mots qui commencent par $word à partir de 2 lettres
......
......@@ -94,12 +94,12 @@ class ObjectiveManager
private function handleFindWord($objective)
{
$repo = $this->em->getRepository('LexiconBundle:Lemma');
$objective->getLemmas()->clear();
$repo = $this->em->getRepository('LexiconBundle:Root');
$objective->getRoots()->clear();
if ($objective->getLemmaEnough()) {
$lemmas = $repo->getByContentAndLanguage($objective);
$objective->addLemmas($lemmas);
$roots = $repo->getByContentAndLanguage($objective);
$objective->addRoots($roots);
}
}
......@@ -205,6 +205,7 @@ class ObjectiveManager
if (count($foundables) < $objective->getNumberToFind()) {
$errors[] = 'problème constraint non réalisable round '.$roundName;
}
// no break
default:
break;
}
......
......@@ -65,7 +65,7 @@ class RoundManager
}
$this->em->flush();
return $round;
}
......
......@@ -6,7 +6,7 @@ use JMS\DiExtraBundle\Annotation as DI;
use MagicWordBundle\Entity\Wordbox;
use MagicWordBundle\Entity\Wordbox\Acquisition;
use MagicWordBundle\Entity\Wordbox\AcquisitionType;
use LexiconBundle\Entity\Lemma;
use LexiconBundle\Entity\Root;
/**
* @DI\Service("mw_manager.acquisition")
......@@ -25,13 +25,13 @@ class AcquisitionManager
$this->em = $entityManager;
}
public function create(Wordbox $wordbox, AcquisitionType $acquisitionType, Lemma $lemma)
public function create(Wordbox $wordbox, AcquisitionType $acquisitionType, Root $root)
{
if (!$this->em->getRepository("MagicWordBundle:Wordbox\Acquisition")->findOneBy(array('wordbox' => $wordbox, 'lemma' => $lemma))) {
if (!$this->em->getRepository("MagicWordBundle:Wordbox\Acquisition")->findOneBy(array('wordbox' => $wordbox, 'root' => $root))) {
$acquisition = new Acquisition();
$acquisition->setWordbox($wordbox);
$acquisition->setType($acquisitionType);
$acquisition->setLemma($lemma);
$acquisition->setRoot($root);
$acquisition->setDate(new \DateTime());
$this->em->persist($acquisition);
......
......@@ -15,7 +15,7 @@ class FoundableRepository extends \Doctrine\ORM\EntityRepository
public function getByGridAndCriteria($grid, $objective)
{
$em = $this->_em;
$dql = 'SELECT f FROM MagicWordBundle\Entity\FoundableForm f JOIN f.inflections i JOIN i.lemma l WHERE f.grid = :grid';
$dql = 'SELECT f FROM MagicWordBundle\Entity\FoundableForm f JOIN f.words i JOIN i.root l WHERE f.grid = :grid';
$dql .= $objective->getCategory()
? ' AND l.category = '.$objective->getCategory()->getId()
......@@ -71,8 +71,8 @@ class FoundableRepository extends \Doctrine\ORM\EntityRepository
public function foundableByLanguage(Language $language)
{
$dql = 'SELECT count(DISTINCT i.cleanedContent) FROM LexiconBundle:Inflection i
WHERE i.language = :language';
$dql = 'SELECT count(DISTINCT w.cleanValue) FROM LexiconBundle:Word w
WHERE w.language = :language';
$query = $this->_em->createQuery($dql);
$query->setParameter('language', $language);
......
......@@ -11,10 +11,10 @@ class AcquisitionRepository extends \Doctrine\ORM\EntityRepository
{
$em = $this->_em;
$dql = "SELECT acquisition FROM MagicWordBundle\Entity\Wordbox\Acquisition acquisition
LEFT JOIN acquisition.lemma lemma
WHERE lemma.language = :language
LEFT JOIN acquisition.root root
WHERE root.language = :language
AND acquisition.wordbox = :wordbox
ORDER BY lemma.content ASC
ORDER BY root.value ASC
";
$query = $em->createQuery($dql);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment