diff --git a/app/modules/Front/BaseFrontPresenter.php b/app/modules/Front/BaseFrontPresenter.php
index 9149dc8..ae60553 100644
--- a/app/modules/Front/BaseFrontPresenter.php
+++ b/app/modules/Front/BaseFrontPresenter.php
@@ -3,8 +3,115 @@
namespace App\Modules\Front;
use App\Modules\Base\UnsecuredPresenter;
+use Nette;
+use Nette\Utils\Strings;
+use Nette\Application\UI;
+use Dict\OggResponse;
+use Nette\Application\Responses\JsonResponse;
+use AlesWita\VisualPaginator\VisualPaginator;
+use AlesWita\VisualPaginator\VisualPaginatorFactory;
+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;
abstract class BaseFrontPresenter extends UnsecuredPresenter
{
+ /** @inject @var EntityManager */
+ public EntityManager $em;
+ /** @inject */
+ public VisualPaginatorFactory $visualPaginatorFactory;
+ /** @inject */
+ public TermFacade $termFacade;
+ /** @persistent */
+ public $term;
+
+ /** @persistent */
+ public $slug;
+
+ public $translation;
+ public $translations;
+ public $dictionaries;
+ public $drsSelect;
+ public $slugs;
+
+ protected function startup()
+ {
+ $trs = $this->em->getRepository(Translation::class)->findBy([], ['id' => 'ASC', 'direction' => 'ASC']);
+ $drs = $this->em->getRepository(Dictionary::class)->findPairs('id', 'name');
+ $select = [];
+ $translations = [];
+ foreach ($trs as $t) {
+ $lang1 = $t->getLangName1();
+ $lang2 = $t->getLangName2();
+
+ $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;
+ $slugs[$slug] = $t;
+ }
+ $this->translations = $translations;
+ $this->dictionaries = $drs;
+ $this->drsSelect = $select;
+ $this->slugs = $slugs;
+
+ parent::startup();
+ }
+
+ public function handleGetInfo($id)
+ {
+ $term = $this->repoTerms->find($id);
+ $termFlags = $this->repoTermFlags->findAssoc([], 'id');
+
+ $dictionary = $term->dictionary;
+
+ $query = new TermsFullQuery($dictionary, $term->string1, 1, false);
+ $result = $this->repoTerms->fetch($query);
+
+ $this->template->result = $result;
+ $this->template->termFlags = $termFlags;
+
+ $this->setView('info');
+ }
+
+ public function beforeRender()
+ {
+ $dicttypes = $this->em->getDictTypeRepository()->findAssoc([], 'id');
+ $this->template->dicttypes = $dicttypes;
+ $this->template->dictionaries = $this->dictionaries;
+ $this->template->translations = $this->translations;
+ // $this->template->paginator = $this->paginator;
+ }
+
+ protected function createComponentSearchForm()
+ {
+ $form = new UI\Form;
+ $form->addText('string', 'Výraz')
+ ->setRequired('Zadajte výray');
+ $form->addSelect('translation', 'Preklad', $this->drsSelect)
+ ->setDefaultValue(1)
+ ->setRequired('Vyberte slovnik');
+ $form->addText('clen', 'Clen', 5);
+ $form->addSubmit('search', 'Vyhaľadaj');
+ $form->onSuccess[] = array($this, 'searchFormSucceeded');
+ return $form;
+ }
+
+ public function searchFormSucceeded(UI\Form $form, $values)
+ {
+ $translation = $values->translation;
+ $clen = $values->clen;
+ $term = $values->string;
+
+ $this->redirect('Search:default',$translation,$term,$clen);
+
+ }
}
diff --git a/app/modules/Front/Home/HomePresenter.php b/app/modules/Front/Home/HomePresenter.php
index a453983..0fa2216 100644
--- a/app/modules/Front/Home/HomePresenter.php
+++ b/app/modules/Front/Home/HomePresenter.php
@@ -22,74 +22,6 @@ final class HomePresenter extends BaseFrontPresenter
{
- /** @inject @var EntityManager */
- public EntityManager $em;
- /** @inject */
- public VisualPaginatorFactory $visualPaginatorFactory;
- /** @inject */
- public TermFacade $termFacade;
-
-
- private $translations;
- private $dictionaries;
- private $drsSelect;
- private $slugs;
- public $translation;
-
- /** @persistent */
- public $term;
-
- /** @persistent */
- public $slug;
-
- protected function startup()
- {
- $trs = $this->em->getRepository(Translation::class)->findBy([], ['id' => 'ASC', 'direction' => 'ASC']);
- $drs = $this->em->getRepository(Dictionary::class)->findPairs('id', 'name');
- $select = [];
- foreach ($trs as $t) {
- $lang1 = $t->getLangName1();
- $lang2 = $t->getLangName2();
-
- $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;
- $slugs[$slug] = $t;
- }
- $this->translations = $translations;
- $this->dictionaries = $drs;
- $this->drsSelect = $select;
- $this->slugs = $slugs;
-
- parent::startup();
- }
-
- 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);
-
- if ($paginate) {
- $this["paginator"]->setItemCount(500);
- $offset = $this["paginator"]->getOffset();
- $itemsPerPage = $this['paginator']->getItemsPerPage();
- }
- $q = $this->termFacade->findByString($term, $t->dictionary, $clen);
- $q->setMaxResults(500)->setFirstResult($offset)->getMaxResults($itemsPerPage);
-
- $this->template->translation = $t;
-
- return $q->getResult();
- }
/**
* @return AlesWita\Components\VisualPaginator
@@ -107,31 +39,7 @@ final class HomePresenter extends BaseFrontPresenter
return $paginator;
}
- protected function createComponentSearchForm()
- {
- $form = new UI\Form;
- $form->addText('string', 'Výraz')
- ->setRequired('Zadajte výray');
- $form->addSelect('translation', 'Preklad', $this->drsSelect)
- ->setDefaultValue(1)
- ->setRequired('Vyberte slovnik');
- $form->addText('clen', 'Clen', 5);
- $form->addSubmit('search', 'Vyhaľadaj');
- $form->onSuccess[] = array($this, 'searchFormSucceeded');
- return $form;
- }
- public function searchFormSucceeded(UI\Form $form, $values)
- {
- $translation = $values->translation;
- $clen = $values->clen;
- $term = $values->string;
-
- $result = $this->doSearch('TermsQuery', $translation, $term, $clen);
- $this->term = $term;
- dump($result);
- $this->template->result = $result;
- }
public function searchFormSucceededIpa(UI\Form $form, $values)
{
@@ -162,14 +70,6 @@ final class HomePresenter extends BaseFrontPresenter
return $this->sendResponse($oggResp);
}
- public function beforeRender()
- {
- $dicttypes = $this->em->getDictTypeRepository()->findAssoc([], 'id');
- $this->template->dicttypes = $dicttypes;
- $this->template->dictionaries = $this->dictionaries;
- $this->template->translations = $this->translations;
- // $this->template->paginator = $this->paginator;
- }
public function actionDefault()
{
@@ -179,7 +79,6 @@ final class HomePresenter extends BaseFrontPresenter
$result = $this->doSearch('TermsQuery',$t->id,$this->term);
if ($result) $this->template->result = $result;
} else {
- //dumpe($this);
$this->term = $this['searchForm']['string']->getValue();
}
$this['searchForm']->onSuccess[] = array($this, 'searchFormSucceeded');
@@ -213,21 +112,7 @@ final class HomePresenter extends BaseFrontPresenter
$this->setView('ipa');
}
- public function handleGetInfo($id)
- {
- $term = $this->repoTerms->find($id);
- $termFlags = $this->repoTermFlags->findAssoc([], 'id');
-
- $dictionary = $term->dictionary;
-
- $query = new TermsFullQuery($dictionary, $term->string1, 1, false);
- $result = $this->repoTerms->fetch($query);
-
- $this->template->result = $result;
- $this->template->termFlags = $termFlags;
-
- $this->setView('info');
- }
+
public function renderDefault()
{
diff --git a/app/modules/Front/Home/SearchPresenter.php b/app/modules/Front/Home/SearchPresenter.php
deleted file mode 100644
index e69de29..0000000
diff --git a/app/modules/Front/Home/templates/default.latte b/app/modules/Front/Home/templates/default.latte
index 362cc59..2c7002c 100644
--- a/app/modules/Front/Home/templates/default.latte
+++ b/app/modules/Front/Home/templates/default.latte
@@ -1,75 +1 @@
-{block head}
-
-{/block}
-{block content}
-
-
Zadaj vyhladavany vyraz.
-
-
- {form searchForm}
-
-
- | {label string /} | {label translation /} | {label clen /} |
-
-
- | {input string} | {input translation} | {input clen} | {input search} |
-
-
-
- {ifset $result}
-
-
-
- | Vyraz | Preklad | Typ | Member |
-
- {foreach $result as $term}
-
-
- {if $translation->getDirection() == 1}
- | {$term->string1}{if $term->suffix1} {$term->suffix1->text}{/if} |
- {$term->string2}{if $term->suffix2} {$term->suffix2->text}{/if} |
- {else}
- {$term->string2}{if $term->suffix2} {$term->suffix2->text}{/if} |
- {$term->string1}{if $term->suffix1} {$term->suffix1->text}{/if} |
- {/if}
- {$term->type ? $dicttypes[$term->type->id]->shortName : ''} |
- {$term->member} |
-
-
- {/foreach}
-
- {control paginator}
- {/ifset}
- {/form}
-
-{/block}
-
-
+{block #content}
\ No newline at end of file
diff --git a/app/modules/Front/Home/templates/interactive.latte b/app/modules/Front/Home/templates/interactive.latte
index 52abc6d..496ab97 100644
--- a/app/modules/Front/Home/templates/interactive.latte
+++ b/app/modules/Front/Home/templates/interactive.latte
@@ -51,8 +51,6 @@ $(function() {
{/block}
{block content}
-
-
Zadaj vyhladavany vyraz.
{form searchForm}
diff --git a/app/modules/Front/Home/templates/ipa.latte b/app/modules/Front/Home/templates/ipa.latte
index 5a72763..f943ac4 100644
--- a/app/modules/Front/Home/templates/ipa.latte
+++ b/app/modules/Front/Home/templates/ipa.latte
@@ -15,20 +15,11 @@ $( document ).ready(function() {
{/block}
-{block content}
-
-
Zadaj vyhladavany vyraz.
-
- {form searchForm}
-
-
- | {label string /} | {label translation /} | {label clen /} |
-
-
- | {input string} | {input translation} | {input clen} | {input search} |
-
-
+{block content}
+{block form}
+
+{/block}
{ifset $result}
diff --git a/app/modules/Front/Search/templates/default.latte b/app/modules/Front/Search/templates/default.latte
new file mode 100644
index 0000000..ecfb2b3
--- /dev/null
+++ b/app/modules/Front/Search/templates/default.latte
@@ -0,0 +1,64 @@
+{block head}
+
+{/block}
+{block content}
+
+
+
+
+ {ifset $result}
+
+
+
+ | Vyraz | Preklad | Typ | Member |
+
+ {foreach $result as $term}
+
+
+ {if $translation->getDirection() == 1}
+ | {$term->string1}{if $term->suffix1} {$term->suffix1->text}{/if} |
+ {$term->string2}{if $term->suffix2} {$term->suffix2->text}{/if} |
+ {else}
+ {$term->string2}{if $term->suffix2} {$term->suffix2->text}{/if} |
+ {$term->string1}{if $term->suffix1} {$term->suffix1->text}{/if} |
+ {/if}
+ {$term->type ? $dicttypes[$term->type->id]->shortName : ''} |
+ {$term->member} |
+
+
+ {/foreach}
+
+
+ {/ifset}
+
+{/block}
+
+
diff --git a/app/modules/Front/templates/@layout.latte b/app/modules/Front/templates/@layout.latte
index b72cfe3..96bad96 100644
--- a/app/modules/Front/templates/@layout.latte
+++ b/app/modules/Front/templates/@layout.latte
@@ -39,8 +39,22 @@
{$title}
{$flash->message}
-
+
+ {block form}
+
Zadaj vyhladavany vyraz.
+ {form searchForm}
+
+
+ | {label string /} | {label translation /} | {label clen /} |
+
+
+ | {input string} | {input translation} | {input clen} | {input search} |
+
+
+ {/form}
+ {/block}
{include content}
+