diff --git a/app/model/Database/Entity/PronunciationTypes.php b/app/model/Database/Entity/PronunciationType.php similarity index 100% rename from app/model/Database/Entity/PronunciationTypes.php rename to app/model/Database/Entity/PronunciationType.php diff --git a/app/model/Database/Entity/Translation.php b/app/model/Database/Entity/Translation.php index 4bac9ce..d5ba049 100644 --- a/app/model/Database/Entity/Translation.php +++ b/app/model/Database/Entity/Translation.php @@ -7,7 +7,7 @@ use Doctrine\ORM\Mapping as ORM; use App\Model\Database\Entity\Attributes\TId; /** - * @ORM\Entity(repositoryClass="App\Model\Database\Repository\TermRepository") + * @ORM\Entity(repositoryClass="App\Model\Database\Repository\TranslationRepository") * @ORM\Table(name="`translation`") * @ORM\HasLifecycleCallbacks */ @@ -71,7 +71,7 @@ class Translation extends AbstractEntity */ protected $direction; - public function getDirection() + public function getDirection() : int { return $this->direction; } diff --git a/app/model/Database/Facade/TermFacade.php b/app/model/Database/Facade/TermFacade.php new file mode 100644 index 0000000..4f0065d --- /dev/null +++ b/app/model/Database/Facade/TermFacade.php @@ -0,0 +1,53 @@ +em = $em; + } + + public function setDirection(int $direction) + { + $this->direction = $direction; + } + /** + * @param mixed[] $data + */ + public function findByString() + { + $query = $this->em->createQueryBuilder('t')->select('t') + ->addSelect('s1') + ->addSelect('s2') + ->from(Term::class,'t') + ->leftJoin('t.suffix1','s1') + ->leftJoin('t.suffix2','s2'); + if ($this->direction == 1) { + $query->where('t.string1 LIKE :str')->setParameter('str',"test"."%"); + $query->orderBy('t.string1,t.id','ASC'); + } else if ($this->direction == 2) { + $query->where('t.string2 LIKE :str')->setParameter('str', "test"."%"); + $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','%'."".'%'); + + return $query->getQuery()->getResult(); + } + +} diff --git a/app/model/Database/Repository/Advanced/TermsQuery.php b/app/model/Database/Repository/TermsQuery.php similarity index 100% rename from app/model/Database/Repository/Advanced/TermsQuery.php rename to app/model/Database/Repository/TermsQuery.php diff --git a/app/modules/Front/Home/HomePresenter.php b/app/modules/Front/Home/HomePresenter.php index 52c7385..7cade9a 100644 --- a/app/modules/Front/Home/HomePresenter.php +++ b/app/modules/Front/Home/HomePresenter.php @@ -14,12 +14,21 @@ use App\Model\Database\EntityManager; use App\Model\Database\Entity\Dictionary; use App\Model\Database\Entity\Translation; use App\Model\Database\Repository\TranslationRepository; +use App\Model\Database\Repository\TermsFullQuery; +use App\Model\Database\Repository\TermsQuickQuery; +use App\Model\Database\Facade\TermFacade; + final class HomePresenter extends BaseFrontPresenter { /** @inject @var \App\Model\Database\EntityManager */ public $em; + /** @inject */ + public VisualPaginatorFactory $visualPaginatorFactory; + /** @inject */ + public TermFacade $termFacade; + private $translations; private $dictionaries; @@ -61,24 +70,33 @@ 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 $query($t->dictionary,$this->term,$t->direction); - + + $query = new $repo_query($t->getDictionary(),$this->term,$t->getDirection()); + if ($clen) $query->withClen($clen); - $result = $this->repoTerms->fetch($query)->setFetchJoinCollection(FALSE); - + $result = $this->em->getTermRepository()->fetch($query)->setFetchJoinCollection(FALSE); + if ($paginate) { - $this["paginator"]->setItemCount($result->getTotalCount()); - $result->applyPaginator($paginator); - $offset = $this['paginator']->getOffset(); - $itemsPerPage = $this['paginator']->getItemsPerPage(); + $this["paginator"]->setItemCount($result->getTotalCount()); + $result->applyPaginator($this['paginator']); + $offset = $this['paginator']->getOffset(); + $itemsPerPage = $this['paginator']->getItemsPerPage(); } - + */ + $t = $this->em->getTranslationRepository()->find($translation); $this->template->translation = $t; return $result; @@ -117,9 +135,8 @@ final class HomePresenter extends BaseFrontPresenter $clen = $values->clen; $term = $values->string; - $result = $this->doSearch('\\App\\Model\\Database\\Repository\\TermsQuery',$translation,$term,$clen); - - $this->template->result = $result; + $result = $this->doSearch('TermsQuery',$translation,$term,$clen); + $this->template->result = $result; } public function searchFormSucceededIpa(UI\Form $form,$values) @@ -128,7 +145,7 @@ final class HomePresenter extends BaseFrontPresenter $term = $values->string; $clen = $values->clen; - $result = $this->doSearch('\\App\\Model\\Database\\Repository\\TermsFullQuery',$translation,$term,$clen); + $result = $this->doSearch('TermsFullQuery',$translation,$term,$clen); $this->template->result = $result; } @@ -138,7 +155,7 @@ final class HomePresenter extends BaseFrontPresenter $term = $values->string; $translation = $values->translation; - $result = $this->doSearch('\\App\\Model\\Database\\Repository\\TermsFullQuery',$translation,$term,null); + $result = $this->doSearch('TermsFullQuery',$translation,$term,null); $this->template->result = $result; } @@ -166,7 +183,7 @@ final class HomePresenter extends BaseFrontPresenter if ($this->getRequest()->isMethod('GET') && $this->term) { $this['searchForm']['string']->setValue($this->term); $t = $this->slugs[$this->slug]; - $result = $this->doSearch('\\App\\Model\\Database\\Repository\\TermsQuery',$t->id,$this->term); + $result = $this->doSearch('TermsQuery',$t->id,$this->term); if ($result) $this->template->result = $result; } @@ -190,7 +207,7 @@ final class HomePresenter extends BaseFrontPresenter } } if ($term) { - $query = new \App\Model\Database\Repository\TermsFullQuery($translation->dictionary,$term,$translation->direction); + $query = new TermsFullQuery($translation->dictionary,$term,$translation->direction); $result = $this->repoTerms->fetch($query); $this->template->result = $result; @@ -206,7 +223,7 @@ final class HomePresenter extends BaseFrontPresenter $dictionary = $term->dictionary; - $query = new \App\Model\Database\Repository\TermsFullQuery($dictionary,$term->string1,1,false); + $query = new TermsFullQuery($dictionary,$term->string1,1,false); $result = $this->repoTerms->fetch($query); $this->template->result = $result; @@ -224,7 +241,7 @@ final class HomePresenter extends BaseFrontPresenter if ($this->getRequest()->isMethod('GET')) { if ($this->term) { $this['searchForm']['string']->setValue($this->term); - $result = $this->doSearch('\\App\\Model\\Database\\Repository\\TermsFullQuery',$this->slugs[$this->slug]->id,$this->term); + $result = $this->doSearch('TermsFullQuery',$this->slugs[$this->slug]->id,$this->term); if ($result) $this->template->result = $result; } } @@ -237,7 +254,7 @@ final class HomePresenter extends BaseFrontPresenter if ($this->getRequest()->isMethod('GET')) { if ($this->term) { $this['searchForm']['string']->setValue($this->term); - $result = $this->doSearch('\\App\\Model\\Database\\Repository\\TermsFullQuery',$this->slugs[$this->slug]->id,$this->term); + $result = $this->doSearch('TermsFullQuery',$this->slugs[$this->slug]->id,$this->term); if ($result) $this->template->result = $result; } } @@ -249,7 +266,7 @@ final class HomePresenter extends BaseFrontPresenter { $translation = $this->repoTranslations->find($translation); - $query = new \App\Model\Database\Repository\TermsQuickQuery($translation->dictionary,$typedText,$translation->direction); + $query = new TermsQuickQuery($translation->dictionary,$typedText,$translation->direction); $result = $this->repoTerms->fetch($query); $map = []; diff --git a/app/modules/Front/Home/templates/default.latte b/app/modules/Front/Home/templates/default.latte index 3c7d75c..230ad7c 100644 --- a/app/modules/Front/Home/templates/default.latte +++ b/app/modules/Front/Home/templates/default.latte @@ -53,8 +53,8 @@ $( document ).ready(function() { {foreach $result as $term} {dump $term} -