Nette 3.0 fixes

This commit is contained in:
2022-01-23 21:31:02 +01:00
parent 9b57474dee
commit 431961ed8f
10 changed files with 249 additions and 29 deletions

View File

@@ -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;
}

View File

@@ -0,0 +1,53 @@
<?php declare(strict_types = 1);
namespace App\Model\Database\Facade;
use App\Model\Database\Entity\Term;
use App\Model\Database\EntityManager;
class TermFacade
{
/** @var EntityManager */
private $em;
private $direction;
public function __construct(
EntityManager $em
)
{
$this->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();
}
}

View File

@@ -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 = [];

View File

@@ -53,8 +53,8 @@ $( document ).ready(function() {
</tr>
{foreach $result as $term}
{dump $term}
<tr data-url="{link getInfo! $term->id}" n:snippet="term-$term->id">
{if $translation->direction == 1}
<tr>
{if $translation->getDirection() == 1}
<td>{$term->string1}{if $term->suffix1}&nbsp;{$term->suffix1->text}{/if}</td>
<td>{$term->string2}{if $term->suffix2}&nbsp;{$term->suffix2->text}{/if}</td>
{else}