diff --git a/app/model/Database/Entity/Suffix.php b/app/model/Database/Entity/Suffix.php index 9ed5475..c9b2e8b 100644 --- a/app/model/Database/Entity/Suffix.php +++ b/app/model/Database/Entity/Suffix.php @@ -9,6 +9,7 @@ use App\Model\Database\Entity\Attributes\TId; * @ORM\Entity(repositoryClass="App\Model\Database\Repository\SuffixRepository") * @ORM\HasLifecycleCallbacks * + * @property int $id * @property String $text */ class Suffix extends AbstractEntity diff --git a/app/model/Database/Entity/Translation.php b/app/model/Database/Entity/Translation.php index f998761..34271de 100644 --- a/app/model/Database/Entity/Translation.php +++ b/app/model/Database/Entity/Translation.php @@ -11,6 +11,7 @@ use App\Model\Database\Entity\Attributes\TId; * @ORM\Table(name="`translation`") * @ORM\HasLifecycleCallbacks * + * @property int $id * @property Dictionary $dictionary * @property Language $lang1 * @property Language $lang2 diff --git a/app/model/Database/Facade/TermFacade.php b/app/model/Database/Facade/TermFacade.php index 4f0065d..6e1b6e1 100644 --- a/app/model/Database/Facade/TermFacade.php +++ b/app/model/Database/Facade/TermFacade.php @@ -2,7 +2,9 @@ namespace App\Model\Database\Facade; +use App\Model\Database\Entity\Dictionary; use App\Model\Database\Entity\Term; +use App\Model\Database\Entity\Translation; use App\Model\Database\EntityManager; @@ -27,7 +29,7 @@ class TermFacade /** * @param mixed[] $data */ - public function findByString() + public function findByString(String $term,Dictionary $d,String $clen = null) { $query = $this->em->createQueryBuilder('t')->select('t') ->addSelect('s1') @@ -36,18 +38,18 @@ class TermFacade ->leftJoin('t.suffix1','s1') ->leftJoin('t.suffix2','s2'); if ($this->direction == 1) { - $query->where('t.string1 LIKE :str')->setParameter('str',"test"."%"); + $query->where('t.string1 LIKE :str')->setParameter('str', $term."%"); $query->orderBy('t.string1,t.id','ASC'); } else if ($this->direction == 2) { - $query->where('t.string2 LIKE :str')->setParameter('str', "test"."%"); + $query->where('t.string2 LIKE :str')->setParameter('str', $term."%"); $query->orderBy('t.string2','ASC'); $query->addOrderBy('t.order2','ASC'); } - $query->andWhere('t.dictionary = :dict')->setParameter(':dict',1); - //if ($this->clen) - // $query->andWhere('t.member LIKE :clen')->setParameter('clen','%'."".'%'); + $query->andWhere('t.dictionary = :dict')->setParameter(':dict',$d->id); + if ($clen) + $query->andWhere('t.member LIKE :clen')->setParameter('clen','%'.$clen.'%'); - return $query->getQuery()->getResult(); + return $query->getQuery(); } } diff --git a/app/modules/Front/Home/HomePresenter.php b/app/modules/Front/Home/HomePresenter.php index 38e0aaa..f3dd25a 100644 --- a/app/modules/Front/Home/HomePresenter.php +++ b/app/modules/Front/Home/HomePresenter.php @@ -70,36 +70,25 @@ final class HomePresenter extends BaseFrontPresenter protected function doSearch($query,$translation,$term,$clen = null,$paginate = true) { + $t = $this->em->getTranslationRepository()->find($translation); if ($term) $this->term = $term; if ($translation) $this->translation = $translation; $this->slug = $this->translations[$translation]["slug"]; $this->termFacade->setDirection(1); - $result = $this->termFacade->findByString(); - - //$repo_query = "\\App\\Model\\Database\\Repository\\$query"; - /* - if ($term) $this->term = $term; - if ($translation) $this->translation = $translation; - $this->slug = $this->translations[$translation]["slug"]; - $query = new $repo_query($t->getDictionary(),$this->term,$t->getDirection()); - - if ($clen) $query->withClen($clen); - $result = $this->em->getTermRepository()->fetch($query)->setFetchJoinCollection(FALSE); - if ($paginate) { - $this["paginator"]->setItemCount(count($result)); - $result->applyPaginator($this['paginator']); - $offset = $this['paginator']->getOffset(); + $this["paginator"]->setItemCount(500); + $offset = $this["paginator"]->getOffset(); $itemsPerPage = $this['paginator']->getItemsPerPage(); } - */ - $t = $this->em->getTranslationRepository()->find($translation); + $q = $this->termFacade->findByString($term,$t->dictionary,$clen); + $q->setMaxResults(500)->setFirstResult($offset)->getMaxResults($itemsPerPage); + $this->template->translation = $t; - return $result; + return $q->getResult(); } /** @@ -111,6 +100,8 @@ final class HomePresenter extends BaseFrontPresenter $paginator->ajax = false; $paginator->canSetItemsPerPage = true; + $paginator->setItemsPerPage(100); + //$paginator->templateFile = __DIR__ . '/my_awesome_template.latte'; return $paginator; @@ -131,7 +122,7 @@ final class HomePresenter extends BaseFrontPresenter public function searchFormSucceeded(UI\Form $form,$values) { - $translation = $values->translation; + $translation = $values->translation; $clen = $values->clen; $term = $values->string;