diff --git a/app/modules/Front/BaseFrontPresenter.php b/app/modules/Front/BaseFrontPresenter.php index ae60553..9f477cf 100644 --- a/app/modules/Front/BaseFrontPresenter.php +++ b/app/modules/Front/BaseFrontPresenter.php @@ -41,6 +41,7 @@ abstract class BaseFrontPresenter extends UnsecuredPresenter protected function startup() { + $trs = $this->em->getRepository(Translation::class)->findBy([], ['id' => 'ASC', 'direction' => 'ASC']); $drs = $this->em->getRepository(Dictionary::class)->findPairs('id', 'name'); $select = []; @@ -52,10 +53,10 @@ abstract class BaseFrontPresenter extends UnsecuredPresenter $lang = mb_substr($lang1, 0, -1); $lang .= "o-" . $lang2; $slug = Strings::webalize($lang); - $select[$drs[$t->getDictionary()->getId()]][$t->getId()] = $lang; - $translations[$t->getId()]["slug"] = $slug; - $translations[$t->getId()]["lang"] = $lang; - $translations[$t->getId()]["t"] = $t; + $select[$drs[$t->getDictionary()->id]][$t->id] = $lang; + $translations[$t->id]["slug"] = $slug; + $translations[$t->id]["lang"] = $lang; + $translations[$t->id]["t"] = $t; $slugs[$slug] = $t; } $this->translations = $translations; diff --git a/app/modules/Front/Home/HomePresenter.php b/app/modules/Front/Home/HomePresenter.php index 0fa2216..c871921 100644 --- a/app/modules/Front/Home/HomePresenter.php +++ b/app/modules/Front/Home/HomePresenter.php @@ -21,26 +21,6 @@ use App\Model\Database\Facade\TermFacade; final class HomePresenter extends BaseFrontPresenter { - - - /** - * @return AlesWita\Components\VisualPaginator - */ - protected function createComponentPaginator(): VisualPaginator - { - $paginator = $this->visualPaginatorFactory->create(); - - $paginator->ajax = false; - $paginator->canSetItemsPerPage = true; - $paginator->setItemsPerPage(100); - - //$paginator->templateFile = __DIR__ . '/my_awesome_template.latte'; - - return $paginator; - } - - - public function searchFormSucceededIpa(UI\Form $form, $values) { $translation = $values->translation; @@ -96,7 +76,6 @@ final class HomePresenter extends BaseFrontPresenter } else { $id = $this['searchForm']['translation']->value; - dump($id); if (isset($this->translations[$id])) { $t = $this->translations[$id]; $this->redirect('Front:Home:select', $t["slug"], $this['searchForm']['string']->value); @@ -120,15 +99,7 @@ final class HomePresenter extends BaseFrontPresenter public function actionIpa() { - if ($this->getRequest()->isMethod('GET')) { - if ($this->term) { - $this['searchForm']['string']->setValue($this->term); - $result = $this->doSearch('TermsFullQuery', $this->slugs[$this->slug]->id, $this->term); - if ($result) $this->template->result = $result; - } - } - - $this['searchForm']->onSuccess[] = array($this, 'searchFormSucceededIpa'); + $this->redirect('Search:ipa',$this->translation,$this->term); } public function actionInteractive() diff --git a/app/modules/Front/Search/SearchPresenter.php b/app/modules/Front/Search/SearchPresenter.php index 3a38a06..c352875 100644 --- a/app/modules/Front/Search/SearchPresenter.php +++ b/app/modules/Front/Search/SearchPresenter.php @@ -20,15 +20,7 @@ use App\Model\Database\Facade\TermFacade; class SearchPresenter extends BaseFrontPresenter { - /** @inject @var EntityManager */ - public EntityManager $em; - /** @inject */ - public TermFacade $termFacade; - - - /** @persistent */ - public $term; protected function doSearch($query, $translation, $term, $clen = null, $paginate = true) { @@ -36,30 +28,57 @@ class SearchPresenter extends BaseFrontPresenter if ($term) $this->term = $term; if ($translation) $this->translation = $translation; - // $this->slug = $this->translations[$translation]["slug"]; + $this->slug = $this->translations[$translation]["slug"]; $this->termFacade->setDirection(1); - -/* if ($paginate) { - $this["paginator"]->setItemCount(500); + $q = $this->termFacade->findByString($term, $t->dictionary, $clen); + + if ($paginate) { + $paginator = new \Doctrine\ORM\Tools\Pagination\Paginator($q); + $count = count($paginator); + $this["paginator"]->setItemCount($count); $offset = $this["paginator"]->getOffset(); $itemsPerPage = $this['paginator']->getItemsPerPage(); + $q->setFirstResult($offset)->setMaxResults($itemsPerPage); } -*/ - $q = $this->termFacade->findByString($term, $t->dictionary, $clen); - //$q->setMaxResults(500)->setFirstResult($offset)->getMaxResults($itemsPerPage); + $this->template->translation = $t; return $q->getResult(); } - public function renderDefault($translation,$term,$clen,$paginate = false) + public function renderDefault($translation,$term,$clen = '',$paginate = true) { $this['searchForm']['string']->setValue($this->term); $this->template->result = $this->doSearch('TermQuery',$translation,$term,$clen,$paginate); } + public function renderIpa($translation,$term,$clen='',$paginate=true) + { + $this['searchForm']['string']->setValue($this->term); + $result = $this->doSearch('TermsFullQuery', $this->slugs[$this->slug]->id, $this->term); + if ($result) $this->template->result = $result; + + $this['searchForm']->onSuccess[] = array($this, 'searchFormSucceededIpa'); + } + + + /** + * @return AlesWita\Components\VisualPaginator + */ + protected function createComponentPaginator(): VisualPaginator + { + $paginator = $this->visualPaginatorFactory->create(); + + $paginator->ajax = false; + $paginator->canSetItemsPerPage = true; + $paginator->setItemsPerPage(20); + + $paginator->templateFile = __DIR__.'/templates/bootstrap4.latte'; + + return $paginator; + } } diff --git a/app/modules/Front/Search/templates/bootstrap4.latte b/app/modules/Front/Search/templates/bootstrap4.latte new file mode 100644 index 0000000..bce43c0 --- /dev/null +++ b/app/modules/Front/Search/templates/bootstrap4.latte @@ -0,0 +1,39 @@ +{templateType AlesWita\VisualPaginator\Template} + +{php $linkClass = $ajax ? 'page-link ajax' : 'page-link'} + +
+
{/foreach}