From 431961ed8f0b8a5ade5e523fe6f1e528dfb9f262 Mon Sep 17 00:00:00 2001 From: Jaroslav Drzik Date: Sun, 23 Jan 2022 21:31:02 +0100 Subject: [PATCH] Nette 3.0 fixes --- ...ciationTypes.php => PronunciationType.php} | 0 app/model/Database/Entity/Translation.php | 4 +- app/model/Database/Facade/TermFacade.php | 53 +++++++ .../Repository/{Advanced => }/TermsQuery.php | 0 app/modules/Front/Home/HomePresenter.php | 61 +++++--- .../Front/Home/templates/default.latte | 4 +- composer.json | 3 +- composer.lock | 147 +++++++++++++++++- config/app/services.neon | 3 + docker-compose.yml | 3 +- 10 files changed, 249 insertions(+), 29 deletions(-) rename app/model/Database/Entity/{PronunciationTypes.php => PronunciationType.php} (100%) create mode 100644 app/model/Database/Facade/TermFacade.php rename app/model/Database/Repository/{Advanced => }/TermsQuery.php (100%) diff --git a/app/model/Database/Entity/PronunciationTypes.php b/app/model/Database/Entity/PronunciationType.php similarity index 100% rename from app/model/Database/Entity/PronunciationTypes.php rename to app/model/Database/Entity/PronunciationType.php diff --git a/app/model/Database/Entity/Translation.php b/app/model/Database/Entity/Translation.php index 4bac9ce..d5ba049 100644 --- a/app/model/Database/Entity/Translation.php +++ b/app/model/Database/Entity/Translation.php @@ -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; } diff --git a/app/model/Database/Facade/TermFacade.php b/app/model/Database/Facade/TermFacade.php new file mode 100644 index 0000000..4f0065d --- /dev/null +++ b/app/model/Database/Facade/TermFacade.php @@ -0,0 +1,53 @@ +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(); + } + +} diff --git a/app/model/Database/Repository/Advanced/TermsQuery.php b/app/model/Database/Repository/TermsQuery.php similarity index 100% rename from app/model/Database/Repository/Advanced/TermsQuery.php rename to app/model/Database/Repository/TermsQuery.php diff --git a/app/modules/Front/Home/HomePresenter.php b/app/modules/Front/Home/HomePresenter.php index 52c7385..7cade9a 100644 --- a/app/modules/Front/Home/HomePresenter.php +++ b/app/modules/Front/Home/HomePresenter.php @@ -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 = []; diff --git a/app/modules/Front/Home/templates/default.latte b/app/modules/Front/Home/templates/default.latte index 3c7d75c..230ad7c 100644 --- a/app/modules/Front/Home/templates/default.latte +++ b/app/modules/Front/Home/templates/default.latte @@ -53,8 +53,8 @@ $( document ).ready(function() { {foreach $result as $term} {dump $term} - - {if $translation->direction == 1} + + {if $translation->getDirection() == 1} {$term->string1}{if $term->suffix1} {$term->suffix1->text}{/if} {$term->string2}{if $term->suffix2} {$term->suffix2->text}{/if} {else} diff --git a/composer.json b/composer.json index e32b5bf..3b11d6f 100644 --- a/composer.json +++ b/composer.json @@ -40,7 +40,8 @@ "nettrine/migrations": "^0.7.0", "nettrine/fixtures": "^0.6.0", "contributte/pdf": "^6.1", - "aleswita/visualpaginator": "^4.0" + "aleswita/visualpaginator": "^4.0", + "contributte/nextras-orm-query-object": "^0.5.0" }, "require-dev": { "ninjify/qa": "^0.13", diff --git a/composer.lock b/composer.lock index 1900c63..91d6488 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c8eeafe21edd871737d5947f6972f640", + "content-hash": "67e07b326406b0442c4d943d193336b5", "packages": [ { "name": "aleswita/visualpaginator", @@ -1201,6 +1201,74 @@ }, "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", "version": "v6.1.0", @@ -4713,6 +4781,83 @@ }, "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", "version": "v9.99.100", diff --git a/config/app/services.neon b/config/app/services.neon index 6c4fc43..85bdfb5 100644 --- a/config/app/services.neon +++ b/config/app/services.neon @@ -46,6 +46,9 @@ services: # Paginator =============== - AlesWita\VisualPaginator\VisualPaginatorFactory + # Facades ================= + - App\Model\Database\Facade\TermFacade + latte: macros: - App\Model\Latte\Macros::register diff --git a/docker-compose.yml b/docker-compose.yml index 05354ad..810630b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -38,11 +38,12 @@ services: database: image: dockette/postgres:10 environment: + - "POSTGRES_HOST_AUTH_METHOD=trust" - POSTGRES_PASSWORD=webapp - POSTGRES_USER=webapp # - POSTGRES_DB=webapp volumes: - - ../../data/postgres10:/var/lib/postgresql/data + - /data/postgres10:/var/lib/postgresql/data adminer: image: dockette/adminer:dg ports: