Commit 00c53bf9 authored by Arnaud Bey's avatar Arnaud Bey
Browse files

improve user found forms perf.

parent aba0c5cf
......@@ -16,9 +16,16 @@ class FoundableFormController extends Controller
public function displayFoundAction(Language $language)
{
$user = $this->get('security.token_storage')->getToken()->getUser();
$found = $this->getDoctrine()->getRepository('MagicWordBundle:FoundableForm')->foundByUserAndLanguage($user, $language);
$activities = $this->getDoctrine()->getRepository('MagicWordBundle:Activity')->foundByUserAndLanguage($user, $language);
$foundable = $this->getDoctrine()->getRepository('MagicWordBundle:FoundableForm')->foundableByLanguage($language);
$found = [];
foreach ($activities as $activity) {
foreach ($activity->getFoundForms() as $form) {
$found[] = $form;
}
}
return $this->render('MagicWordBundle:FoundableForm:found.html.twig', [
'found' => $found,
'language' => $language,
......
......@@ -2,6 +2,9 @@
namespace MagicWordBundle\Repository;
use MagicWordBundle\Entity\Player;
use LexiconBundle\Entity\Language;
/**
* GameRepository.
*
......@@ -23,4 +26,20 @@ class ActivityRepository extends \Doctrine\ORM\EntityRepository
return $query->getResult();
}
public function foundByUserAndLanguage(Player $player, Language $language)
{
$dql = 'SELECT a FROM MagicWordBundle:Activity a
LEFT JOIN a.round round
LEFT JOIN round.grid grid
WHERE a.player = :player
AND grid.language = :language
';
$query = $this->_em->createQuery($dql);
$query->setParameter('player', $player);
$query->setParameter('language', $language);
return $query->getResult();
}
}
......@@ -27,28 +27,6 @@ class FoundableRepository extends \Doctrine\ORM\EntityRepository
return $query->getResult();
}
public function foundByUserAndLanguage(Player $player, Language $language)
{
$dql = 'SELECT f FROM MagicWordBundle:FoundableForm f
WHERE EXISTS(
SELECT a FROM MagicWordBundle:Activity a
LEFT JOIN a.round round
LEFT JOIN round.grid grid
WHERE a.player = :player
AND grid.language = :language
AND f MEMBER OF a.foundForms
)
GROUP BY f.form
ORDER BY f.form ASC
';
$query = $this->_em->createQuery($dql);
$query->setParameter('player', $player);
$query->setParameter('language', $language);
return $query->getResult();
}
public function foundableByLanguage(Language $language)
{
$dql = 'SELECT count(DISTINCT w.cleanValue) FROM LexiconBundle:Word w
......
Markdown is supported
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