Repository fix

This commit is contained in:
2022-01-14 17:18:49 +01:00
parent 0fb9f639da
commit d14b1eccde
17 changed files with 482 additions and 217 deletions

View File

@@ -0,0 +1,18 @@
<?php declare(strict_types = 1);
namespace App\Model\Database\Repository;
use App\Model\Database\Entity\DictType;
/**
* @method DictType|NULL find($id, ?int $lockMode = NULL, ?int $lockVersion = NULL)
* @method DictType|NULL findOneBy(array $criteria, array $orderBy = NULL)
* @method DictType[] findAll()
* @method DictType[] findBy(array $criteria, array $orderBy = NULL, ?int $limit = NULL, ?int $offset = NULL)
* @extends AbstractRepository<DictType>
*/
class DictTypeRepository extends AbstractRepository
{
}

View File

@@ -1,38 +0,0 @@
<?php
namespace App;
use Kdyby;
use Nette;
class DictTypes extends Nette\Object
{
private $em;
private $dicttypes;
public function __construct(Kdyby\Doctrine\EntityManager $em)
{
$this->em = $em;
$this->dicttypes = $em->getRepository(DictType::class);
}
public function find($value)
{
return $this->dicttypes->find($value);
}
public function findBy($criteria = [],$orderBy = [])
{
return $this->dicttypes->findBy($criteria,$orderBy);
}
public function findPairs($criteria,$value,$orderBy,$key)
{
return $this->dicttypes->findPairs($criteria,$value,$orderBy,$key);
}
public function findAssoc($criteria, $key = NULL)
{
return $this->dicttypes->findAssoc($criteria,$key);
}
}

View File

@@ -1,27 +0,0 @@
<?php
namespace App;
use Kdyby;
use Nette;
class Dictionaries extends Nette\Object
{
private $em;
private $dictionaries;
public function __construct(Kdyby\Doctrine\EntityManager $em)
{
$this->em = $em;
$this->dictionaries = $em->getRepository(Dictionary::class);
}
public function findAll($criteria = [],$orderBy = [])
{
return $this->dictionaries->findBy($criteria,$orderBy);
}
public function findPairs($criteria,$value,$orderBy,$key)
{
return $this->dictionaries->findPairs($criteria,$value,$orderBy,$key);
}
}

View File

@@ -0,0 +1,18 @@
<?php declare(strict_types = 1);
namespace App\Model\Database\Repository;
use App\Model\Database\Entity\Dictionary;
/**
* @method Dictionary|NULL find($id, ?int $lockMode = NULL, ?int $lockVersion = NULL)
* @method Dictionary|NULL findOneBy(array $criteria, array $orderBy = NULL)
* @method Dictionary[] findAll()
* @method Dictionary[] findBy(array $criteria, array $orderBy = NULL, ?int $limit = NULL, ?int $offset = NULL)
* @extends AbstractRepository<Dictionary>
*/
class DictionaryRepository extends AbstractRepository
{
}

View File

@@ -0,0 +1,16 @@
<?php declare(strict_types = 1);
namespace App\Model\Database\Repository;
use App\Model\Database\Entity\Pronunciation;
/**
* @method Pronunciation|NULL find($id, ?int $lockMode = NULL, ?int $lockVersion = NULL)
* @method Pronunciation|NULL findOneBy(array $criteria, array $orderBy = NULL)
* @method Pronunciation[] findAll()
* @method Pronunciation[] findBy(array $criteria, array $orderBy = NULL, ?int $limit = NULL, ?int $offset = NULL)
* @extends AbstractRepository<Pronunciation>
*/
class PronunciationRepository extends AbstractRepository
{
}

View File

@@ -1,33 +0,0 @@
<?php
namespace App;
use Kdyby;
use Nette;
class Pronunciations extends Nette\Object
{
private $em;
private $pronunciations;
public function __construct(Kdyby\Doctrine\EntityManager $em)
{
$this->em = $em;
$this->pronunciations = $em->getRepository(Pronunciation::class);
}
public function find($value)
{
return $this->pronunciations->find($value);
}
public function findBy($criteria = [],$orderBy = [])
{
return $this->pronunciations->findBy($criteria,$orderBy);
}
public function findPairs($criteria,$value,$orderBy,$key)
{
return $this->pronunciations->findPairs($criteria,$value,$orderBy,$key);
}
}

View File

@@ -0,0 +1,18 @@
<?php declare(strict_types = 1);
namespace App\Model\Database\Repository;
use App\Model\Database\Entity\TermFlag;
/**
* @method TermFlag|NULL find($id, ?int $lockMode = NULL, ?int $lockVersion = NULL)
* @method TermFlag|NULL findOneBy(array $criteria, array $orderBy = NULL)
* @method TermFlag[] findAll()
* @method TermFlag[] findBy(array $criteria, array $orderBy = NULL, ?int $limit = NULL, ?int $offset = NULL)
* @extends AbstractRepository<TermFlag>
*/
class TermFlagRepository extends AbstractRepository
{
}

View File

@@ -1,37 +0,0 @@
<?php
namespace App;
use Kdyby;
use Nette;
class TermFlags extends Nette\Object
{
private $em;
private $termFlags;
public function __construct(Kdyby\Doctrine\EntityManager $em)
{
$this->em = $em;
$this->termFlags = $em->getRepository(TermFlag::class);
}
public function find($value)
{
return $this->termFlags->find($value);
}
public function findBy($criteria = [],$orderBy = [])
{
return $this->termFlags->findBy($criteria,$orderBy);
}
public function findPairs($criteria,$value,$orderBy,$key)
{
return $this->termFlags->findPairs($criteria,$value,$orderBy,$key);
}
public function findAssoc($criteria,$key)
{
return $this->termFlags->findAssoc($criteria,$key);
}
}

View File

@@ -0,0 +1,18 @@
<?php declare(strict_types = 1);
namespace App\Model\Database\Repository;
use App\Model\Database\Entity\Term;
/**
* @method Term|NULL find($id, ?int $lockMode = NULL, ?int $lockVersion = NULL)
* @method Term|NULL findOneBy(array $criteria, array $orderBy = NULL)
* @method Term[] findAll()
* @method Term[] findBy(array $criteria, array $orderBy = NULL, ?int $limit = NULL, ?int $offset = NULL)
* @extends AbstractRepository<Term>
*/
class TermRepository extends AbstractRepository
{
}

View File

@@ -1,46 +0,0 @@
<?php
namespace App;
use Kdyby;
use Nette;
class Terms extends Nette\Object
{
private $em;
private $termsDao;
private $terms;
public function __construct(Kdyby\Doctrine\EntityManager $em)
{
$this->em = $em;
$this->terms = $em->getRepository(Term::class);
$this->termsDao = $em->getDao(Term::class);
}
public function findAll($criteria = [],$orderBy = [])
{
return $this->terms->findBy($criteria,$orderBy);
}
public function findBy($criteria = [],$orderBy = [])
{
return $this->terms->findBy($criteria,$orderBy);
}
public function find($id)
{
return $this->terms->find($id);
}
public function findPairs($criteria,$value,$orderBy,$key)
{
return $this->terms->findPairs($criteria,$value,$orderBy,$key);
}
public function fetch($query)
{
return $this->termsDao->fetch($query);
}
}

View File

@@ -0,0 +1,16 @@
<?php declare(strict_types = 1);
namespace App\Model\Database\Repository;
use App\Model\Database\Entity\Translation;
/**
* @method Translation|NULL find($id, ?int $lockMode = NULL, ?int $lockVersion = NULL)
* @method Translation|NULL findOneBy(array $criteria, array $orderBy = NULL)
* @method Translation[] findAll()
* @method Translation[] findBy(array $criteria, array $orderBy = NULL, ?int $limit = NULL, ?int $offset = NULL)
* @extends AbstractRepository<Translation>
*/
class TranslationRepository extends AbstractRepository
{
}

View File

@@ -1,33 +0,0 @@
<?php
namespace App;
use Kdyby;
use Nette;
class Translations extends Nette\Object
{
private $em;
private $translations;
public function __construct(Kdyby\Doctrine\EntityManager $em)
{
$this->em = $em;
$this->translations = $em->getRepository(Translation::class);
}
public function find($value)
{
return $this->translations->find($value);
}
public function findBy($criteria = [],$orderBy = [])
{
return $this->translations->findBy($criteria,$orderBy);
}
public function findPairs($criteria,$value,$orderBy,$key)
{
return $this->translations->findPairs($criteria,$value,$orderBy,$key);
}
}

View File

@@ -3,7 +3,14 @@
namespace App\Model\Database; namespace App\Model\Database;
use App\Model\Database\Entity\User; use App\Model\Database\Entity\User;
use App\Model\Database\Entity\Translation;
use App\Model\Database\Repository\UserRepository; use App\Model\Database\Repository\UserRepository;
use App\Model\Database\Repository\TranslationRepository;
use App\Model\Database\Repository\TermRepository;
use App\Model\Database\Repository\TermFlagRepository;
use App\Model\Database\Repository\PronunciationRepository;
use App\Model\Database\Repository\DictTypeRepository;
use App\Model\Database\Repository\DictionaryRepository;
/** /**
* @mixin EntityManager * @mixin EntityManager
@@ -16,4 +23,34 @@ trait TRepositories
return $this->getRepository(User::class); return $this->getRepository(User::class);
} }
public function getTranslationRepository(): TranslationRepository
{
return $this->getRepository(Translation::class);
}
public function getTermRepository(): TermRepository
{
return $this->getRepository(Term::class);
}
public function getTermFlagRepository(): TermFlagRepository
{
return $this->getRepository(TermFlag::class);
}
public function getPronunciationRepository(): PronunciationRepository
{
return $this->getRepository(Pronunciation::class);
}
public function getDictTypeRepository(): DictTypeRepository
{
return $this->getRepository(DictType::class);
}
public function getDictionaryRepository(): DictionaryRepository
{
return $this->getRepository(Dictionary::class);
}
} }

View File

@@ -2,9 +2,281 @@
namespace App\Modules\Front\Home; namespace App\Modules\Front\Home;
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\Modules\Front\BaseFrontPresenter; use App\Modules\Front\BaseFrontPresenter;
final class HomePresenter extends BaseFrontPresenter final class HomePresenter extends BaseFrontPresenter
{ {
/** @inject @var \App\Translations */
public $repoTranslations;
/** @inject @var \App\Pronunciations */
public $repoPronunciations;
/** @inject @var \App\Dictionaries */
public $repoDictionaries;
/** @inject @var \App\DictTypes */
public $repoDictTypes;
/** @inject @var \App\Terms */
public $repoTerms;
/** @inject @var \App\TermFlags */
public $repoTermFlags;
private $translations;
private $dictionaries;
private $drsSelect;
private $slugs;
public $translation;
/** @persistent */
public $term;
/** @persistent */
public $slug;
protected function startup()
{
$trs = $this->repoTranslations->findBy([],['id' => 'ASC','direction'=>'ASC']);
$drs = $this->repoDictionaries->findPairs([],'name',[],'id');
$select = [];
foreach ($trs as $t) {
$lang1 = $t->langName1;
$lang2 = $t->langName2;
$lang = mb_substr($lang1,0,-1);
$lang .= "o-".$lang2;
$slug = Strings::webalize($lang);
$select[$drs[$t->dictionary->id]][$t->id] = $lang;
$translations[$t->id]["slug"] = $slug;
$translations[$t->id]["lang"] = $lang;
$translations[$t->id]["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->repoTranslations->find($translation);
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);
if ($clen) $query->withClen($clen);
$result = $this->repoTerms->fetch($query)->setFetchJoinCollection(FALSE);
if ($paginate) {
$this["paginator"]->setItemCount($result->getTotalCount());
$result->applyPaginator($paginator);
$offset = $this['paginator']->getOffset();
$itemsPerPage = $this['paginator']->getItemsPerPage();
}
$this->template->translation = $t;
return $result;
}
/**
* @return AlesWita\Components\VisualPaginator
*/
protected function createComponentPaginator(): VisualPaginator
{
$paginator = $this->visualPaginatorFactory->create();
$paginator->ajax = false;
$paginator->canSetItemsPerPage = true;
//$paginator->templateFile = __DIR__ . '/my_awesome_template.latte';
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');
return $form;
}
public function searchFormSucceeded(UI\Form $form,$values)
{
$translation = $values->translation;
$clen = $values->clen;
$term = $values->string;
$result = $this->doSearch('\\App\\TermsQuery',$translation,$term,$clen);
$this->template->result = $result;
}
public function searchFormSucceededIpa(UI\Form $form,$values)
{
$translation = $values->translation;
$term = $values->string;
$clen = $values->clen;
$result = $this->doSearch('\\App\\TermsFullQuery',$translation,$term,$clen);
$this->template->result = $result;
}
public function searchFormSucceededInteractive(UI\Form $form,$values)
{
$term = $values->string;
$translation = $values->translation;
$result = $this->doSearch('\\App\\TermsFullQuery',$translation,$term,null);
$this->template->result = $result;
}
public function actionPlay($id = null)
{
$pron = $this->repoPronunciations->find(['id'=>$id]);
$basepath = $this->getHttpRequest()->url->basePath . "/media";
$oggResp = new OggResponse($id,$pron->filename);
return $this->sendResponse($oggResp);
}
public function beforeRender()
{
$dicttypes = $this->repoDictTypes->findAssoc([],'id');
$this->template->dicttypes = $dicttypes;
$this->template->dictionaries = $this->dictionaries;
$this->template->translations = $this->translations;
// $this->template->paginator = $this->paginator;
}
public function actionDefault()
{
if ($this->getRequest()->isMethod('GET') && $this->term) {
$this['searchForm']['string']->setValue($this->term);
$t = $this->slugs[$this->slug];
$result = $this->doSearch('\\App\\TermsQuery',$t->id,$this->term);
if ($result) $this->template->result = $result;
}
$this['searchForm']->onSuccess[] = array($this, 'searchFormSucceeded');
}
public function actionSelect($slug,$term = null)
{
$this['searchForm']->onSuccess[] = array($this, 'searchFormSucceededIpa');
if ($this->getRequest()->isMethod('GET')) {
if (isset($this->slugs[$slug])) {
$t = $this->slugs[$slug];
$this['searchForm']['translation']->setValue($t->id);
$translation = $t;
}
} else {
$id = $this['searchForm']['translation']->value;
if (isset($this->translations[$id])) {
$t = $this->translations[$id];
$this->redirect('Homepage:select',$t["slug"],$this['searchForm']['string']->value);
}
}
if ($term) {
$query = new \App\TermsFullQuery($translation->dictionary,$term,$translation->direction);
$result = $this->repoTerms->fetch($query);
$this->template->result = $result;
$this->template->translation = $translation;
}
$this->setView('ipa');
}
public function handleGetInfo($id)
{
$term = $this->repoTerms->find($id);
$termFlags = $this->repoTermFlags->findAssoc([],'id');
$dictionary = $term->dictionary;
$query = new \App\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()
{
}
public function actionIpa()
{
if ($this->getRequest()->isMethod('GET')) {
if ($this->term) {
$this['searchForm']['string']->setValue($this->term);
$result = $this->doSearch('\\App\\TermsFullQuery',$this->slugs[$this->slug]->id,$this->term);
if ($result) $this->template->result = $result;
}
}
$this['searchForm']->onSuccess[] = array($this, 'searchFormSucceededIpa');
}
public function actionInteractive()
{
if ($this->getRequest()->isMethod('GET')) {
if ($this->term) {
$this['searchForm']['string']->setValue($this->term);
$result = $this->doSearch('\\App\\TermsFullQuery',$this->slugs[$this->slug]->id,$this->term);
if ($result) $this->template->result = $result;
}
}
$this['searchForm']->onSuccess[] = array($this, 'searchFormSucceededInteractive');
}
public function renderAutocomplete($whichData, $typedText = '',$translation = 1)
{
$translation = $this->repoTranslations->find($translation);
$query = new \App\TermsQuickQuery($translation->dictionary,$typedText,$translation->direction);
$result = $this->repoTerms->fetch($query);
$map = [];
foreach ($result as $str) {
$map[] = $str["string1"];
}
return $this->sendResponse(new JsonResponse($map));
}
public function renderIpa()
{
}
public function renderMerge()
{
}
}
} }

View File

@@ -39,7 +39,8 @@
"nettrine/cache": "^0.3.0", "nettrine/cache": "^0.3.0",
"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"
}, },
"require-dev": { "require-dev": {
"ninjify/qa": "^0.13", "ninjify/qa": "^0.13",

66
composer.lock generated
View File

@@ -4,8 +4,72 @@
"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": "9aed70cf6d7812823cc84844d1a5106c", "content-hash": "c8eeafe21edd871737d5947f6972f640",
"packages": [ "packages": [
{
"name": "aleswita/visualpaginator",
"version": "v4.0.2",
"source": {
"type": "git",
"url": "https://github.com/aleswita/VisualPaginator.git",
"reference": "ed0ebfd575fe06fde6436befd6b203c120052df4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/aleswita/VisualPaginator/zipball/ed0ebfd575fe06fde6436befd6b203c120052df4",
"reference": "ed0ebfd575fe06fde6436befd6b203c120052df4",
"shasum": ""
},
"require": {
"latte/latte": "^2.9",
"nette/application": "^3.1",
"nette/forms": "^3.0",
"nette/http": "^3.1",
"nette/utils": "^3.2",
"php": "^7.4|^8.0"
},
"require-dev": {
"nette/bootstrap": "^3.1",
"nette/di": "^3.0",
"nette/robot-loader": "^3.3",
"nette/routing": "^3.0",
"nette/tester": "^2.3",
"ninjify/nunjuck": "^0.3",
"ninjify/qa": "^0.12",
"phpstan/phpstan": "^0.12",
"phpstan/phpstan-deprecation-rules": "^0.12",
"phpstan/phpstan-nette": "^0.12",
"phpstan/phpstan-strict-rules": "^0.12",
"tracy/tracy": "^2.8"
},
"type": "library",
"autoload": {
"psr-4": {
"AlesWita\\VisualPaginator\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Ales Wita"
}
],
"description": "VisualPaginator for Nette Framework.",
"homepage": "https://github.com/aleswita/VisualPaginator",
"keywords": [
"nette",
"paginator",
"visual paginator"
],
"support": {
"issues": "https://github.com/aleswita/VisualPaginator/issues",
"source": "https://github.com/aleswita/VisualPaginator/tree/v4.0.2"
},
"time": "2021-04-06T11:56:08+00:00"
},
{ {
"name": "composer/package-versions-deprecated", "name": "composer/package-versions-deprecated",
"version": "1.11.99.4", "version": "1.11.99.4",

View File

@@ -43,7 +43,8 @@ services:
# Console ================ # Console ================
- {class: App\Model\Console\HelloCommand, tags: {console.command: hello}} - {class: App\Model\Console\HelloCommand, tags: {console.command: hello}}
# Paginator ===============
- AlesWita\VisualPaginator\VisualPaginatorFactory
latte: latte:
macros: macros: