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; 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\Table(name="`translation`")
* @ORM\HasLifecycleCallbacks * @ORM\HasLifecycleCallbacks
*/ */
@@ -71,7 +71,7 @@ class Translation extends AbstractEntity
*/ */
protected $direction; protected $direction;
public function getDirection() public function getDirection() : int
{ {
return $this->direction; 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\Dictionary;
use App\Model\Database\Entity\Translation; use App\Model\Database\Entity\Translation;
use App\Model\Database\Repository\TranslationRepository; 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 final class HomePresenter extends BaseFrontPresenter
{ {
/** @inject @var \App\Model\Database\EntityManager */ /** @inject @var \App\Model\Database\EntityManager */
public $em; public $em;
/** @inject */
public VisualPaginatorFactory $visualPaginatorFactory;
/** @inject */
public TermFacade $termFacade;
private $translations; private $translations;
private $dictionaries; private $dictionaries;
@@ -61,24 +70,33 @@ final class HomePresenter extends BaseFrontPresenter
protected function doSearch($query,$translation,$term,$clen = null,$paginate = true) protected function doSearch($query,$translation,$term,$clen = null,$paginate = true)
{ {
$t = $this->em->getTranslationRepository()->find($translation);
if ($term) $this->term = $term; if ($term) $this->term = $term;
if ($translation) $this->translation = $translation; if ($translation) $this->translation = $translation;
$this->slug = $this->translations[$translation]["slug"]; $this->slug = $this->translations[$translation]["slug"];
$query = new $query($t->dictionary,$this->term,$t->direction); $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 $repo_query($t->getDictionary(),$this->term,$t->getDirection());
if ($clen) $query->withClen($clen); if ($clen) $query->withClen($clen);
$result = $this->repoTerms->fetch($query)->setFetchJoinCollection(FALSE); $result = $this->em->getTermRepository()->fetch($query)->setFetchJoinCollection(FALSE);
if ($paginate) { if ($paginate) {
$this["paginator"]->setItemCount($result->getTotalCount()); $this["paginator"]->setItemCount($result->getTotalCount());
$result->applyPaginator($paginator); $result->applyPaginator($this['paginator']);
$offset = $this['paginator']->getOffset(); $offset = $this['paginator']->getOffset();
$itemsPerPage = $this['paginator']->getItemsPerPage(); $itemsPerPage = $this['paginator']->getItemsPerPage();
} }
*/
$t = $this->em->getTranslationRepository()->find($translation);
$this->template->translation = $t; $this->template->translation = $t;
return $result; return $result;
@@ -117,8 +135,7 @@ final class HomePresenter extends BaseFrontPresenter
$clen = $values->clen; $clen = $values->clen;
$term = $values->string; $term = $values->string;
$result = $this->doSearch('\\App\\Model\\Database\\Repository\\TermsQuery',$translation,$term,$clen); $result = $this->doSearch('TermsQuery',$translation,$term,$clen);
$this->template->result = $result; $this->template->result = $result;
} }
@@ -128,7 +145,7 @@ final class HomePresenter extends BaseFrontPresenter
$term = $values->string; $term = $values->string;
$clen = $values->clen; $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; $this->template->result = $result;
} }
@@ -138,7 +155,7 @@ final class HomePresenter extends BaseFrontPresenter
$term = $values->string; $term = $values->string;
$translation = $values->translation; $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; $this->template->result = $result;
} }
@@ -166,7 +183,7 @@ final class HomePresenter extends BaseFrontPresenter
if ($this->getRequest()->isMethod('GET') && $this->term) { if ($this->getRequest()->isMethod('GET') && $this->term) {
$this['searchForm']['string']->setValue($this->term); $this['searchForm']['string']->setValue($this->term);
$t = $this->slugs[$this->slug]; $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; if ($result) $this->template->result = $result;
} }
@@ -190,7 +207,7 @@ final class HomePresenter extends BaseFrontPresenter
} }
} }
if ($term) { 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); $result = $this->repoTerms->fetch($query);
$this->template->result = $result; $this->template->result = $result;
@@ -206,7 +223,7 @@ final class HomePresenter extends BaseFrontPresenter
$dictionary = $term->dictionary; $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); $result = $this->repoTerms->fetch($query);
$this->template->result = $result; $this->template->result = $result;
@@ -224,7 +241,7 @@ final class HomePresenter extends BaseFrontPresenter
if ($this->getRequest()->isMethod('GET')) { if ($this->getRequest()->isMethod('GET')) {
if ($this->term) { if ($this->term) {
$this['searchForm']['string']->setValue($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; if ($result) $this->template->result = $result;
} }
} }
@@ -237,7 +254,7 @@ final class HomePresenter extends BaseFrontPresenter
if ($this->getRequest()->isMethod('GET')) { if ($this->getRequest()->isMethod('GET')) {
if ($this->term) { if ($this->term) {
$this['searchForm']['string']->setValue($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; if ($result) $this->template->result = $result;
} }
} }
@@ -249,7 +266,7 @@ final class HomePresenter extends BaseFrontPresenter
{ {
$translation = $this->repoTranslations->find($translation); $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); $result = $this->repoTerms->fetch($query);
$map = []; $map = [];

View File

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

View File

@@ -40,7 +40,8 @@
"nettrine/migrations": "^0.7.0", "nettrine/migrations": "^0.7.0",
"nettrine/fixtures": "^0.6.0", "nettrine/fixtures": "^0.6.0",
"contributte/pdf": "^6.1", "contributte/pdf": "^6.1",
"aleswita/visualpaginator": "^4.0" "aleswita/visualpaginator": "^4.0",
"contributte/nextras-orm-query-object": "^0.5.0"
}, },
"require-dev": { "require-dev": {
"ninjify/qa": "^0.13", "ninjify/qa": "^0.13",

147
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "c8eeafe21edd871737d5947f6972f640", "content-hash": "67e07b326406b0442c4d943d193336b5",
"packages": [ "packages": [
{ {
"name": "aleswita/visualpaginator", "name": "aleswita/visualpaginator",
@@ -1201,6 +1201,74 @@
}, },
"time": "2020-12-20T15:17:11+00:00" "time": "2020-12-20T15:17:11+00:00"
}, },
{
"name": "contributte/nextras-orm-query-object",
"version": "v0.5.0",
"source": {
"type": "git",
"url": "https://github.com/contributte/nextras-orm-query-object.git",
"reference": "6b19a11fed7d8b5fdaf07665096a99231f1051a5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/contributte/nextras-orm-query-object/zipball/6b19a11fed7d8b5fdaf07665096a99231f1051a5",
"reference": "6b19a11fed7d8b5fdaf07665096a99231f1051a5",
"shasum": ""
},
"require": {
"nextras/dbal": "^4.0.0",
"php": ">=7.2"
},
"require-dev": {
"mockery/mockery": "^1.3.0",
"nette/di": "^3.0.1",
"nextras/orm": "^4.0.0",
"ninjify/nunjuck": "^0.4",
"ninjify/qa": "^0.13",
"phpstan/phpstan": "^1.0.0",
"phpstan/phpstan-deprecation-rules": "^1.0.0",
"phpstan/phpstan-nette": "^1.0.0",
"phpstan/phpstan-strict-rules": "^1.0.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "0.5.x-dev"
}
},
"autoload": {
"psr-4": {
"Contributte\\Nextras\\Orm\\QueryObject\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Milan Felix Šulc",
"homepage": "https://f3l1x.io"
}
],
"description": "QueryObjects for Nextras ORM",
"homepage": "https://github.com/contributte/nextras-orm-query-object",
"support": {
"issues": "https://github.com/contributte/nextras-orm-query-object/issues",
"source": "https://github.com/contributte/nextras-orm-query-object/tree/v0.5.0"
},
"funding": [
{
"url": "https://contributte.org/partners.html",
"type": "custom"
},
{
"url": "https://github.com/f3l1x",
"type": "github"
}
],
"time": "2022-01-04T19:52:26+00:00"
},
{ {
"name": "contributte/pdf", "name": "contributte/pdf",
"version": "v6.1.0", "version": "v6.1.0",
@@ -4713,6 +4781,83 @@
}, },
"time": "2021-08-13T12:31:10+00:00" "time": "2021-08-13T12:31:10+00:00"
}, },
{
"name": "nextras/dbal",
"version": "v4.0.4",
"source": {
"type": "git",
"url": "https://github.com/nextras/dbal.git",
"reference": "05c44e728bd9362699c7a0b65ed458fcb62d02ac"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nextras/dbal/zipball/05c44e728bd9362699c7a0b65ed458fcb62d02ac",
"reference": "05c44e728bd9362699c7a0b65ed458fcb62d02ac",
"shasum": ""
},
"require": {
"php": ">=7.1"
},
"require-dev": {
"mockery/mockery": "~1.3.0",
"nette/caching": "~3.0",
"nette/di": "~3.0",
"nette/finder": "~2.5",
"nette/neon": "~3.0",
"nette/tester": "~2.3.1",
"nette/utils": "~3.0",
"phpstan/extension-installer": "1.0.5",
"phpstan/phpstan": "1.0.0",
"phpstan/phpstan-deprecation-rules": "1.0.0",
"phpstan/phpstan-strict-rules": "1.0.0",
"symfony/config": "~4.4 || ~5.0",
"symfony/dependency-injection": "~4.4 || ~5.0",
"symfony/http-kernel": "~4.4 || ~5.0",
"tracy/tracy": "~2.7"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.0-dev"
}
},
"autoload": {
"psr-4": {
"Nextras\\Dbal\\": "src/"
},
"files": [
"srcCompat/compatibility.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nextras Project",
"homepage": "https://github.com/nextras/dbal/graphs/contributors"
}
],
"description": "Nextras database abstraction layer",
"homepage": "https://github.com/nextras/dbal",
"keywords": [
"database",
"dbal",
"nextras"
],
"support": {
"issues": "https://github.com/nextras/dbal/issues",
"source": "https://github.com/nextras/dbal/tree/v4.0.4"
},
"funding": [
{
"url": "https://github.com/hrach",
"type": "github"
}
],
"time": "2022-01-09T20:39:43+00:00"
},
{ {
"name": "paragonie/random_compat", "name": "paragonie/random_compat",
"version": "v9.99.100", "version": "v9.99.100",

View File

@@ -46,6 +46,9 @@ services:
# Paginator =============== # Paginator ===============
- AlesWita\VisualPaginator\VisualPaginatorFactory - AlesWita\VisualPaginator\VisualPaginatorFactory
# Facades =================
- App\Model\Database\Facade\TermFacade
latte: latte:
macros: macros:
- App\Model\Latte\Macros::register - App\Model\Latte\Macros::register

View File

@@ -38,11 +38,12 @@ services:
database: database:
image: dockette/postgres:10 image: dockette/postgres:10
environment: environment:
- "POSTGRES_HOST_AUTH_METHOD=trust"
- POSTGRES_PASSWORD=webapp - POSTGRES_PASSWORD=webapp
- POSTGRES_USER=webapp - POSTGRES_USER=webapp
# - POSTGRES_DB=webapp # - POSTGRES_DB=webapp
volumes: volumes:
- ../../data/postgres10:/var/lib/postgresql/data - /data/postgres10:/var/lib/postgresql/data
adminer: adminer:
image: dockette/adminer:dg image: dockette/adminer:dg
ports: ports: