refactor
This commit is contained in:
@@ -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()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user