diff --git a/app/model/Database/Repository/DictTypeRepository.php b/app/model/Database/Repository/DictTypeRepository.php new file mode 100644 index 0000000..7dffd52 --- /dev/null +++ b/app/model/Database/Repository/DictTypeRepository.php @@ -0,0 +1,18 @@ + + */ +class DictTypeRepository extends AbstractRepository +{ + + +} diff --git a/app/model/Database/Repository/DictTypes.php b/app/model/Database/Repository/DictTypes.php deleted file mode 100644 index feb24d2..0000000 --- a/app/model/Database/Repository/DictTypes.php +++ /dev/null @@ -1,38 +0,0 @@ -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); - } -} diff --git a/app/model/Database/Repository/Dictionaries.php b/app/model/Database/Repository/Dictionaries.php deleted file mode 100644 index 8720cef..0000000 --- a/app/model/Database/Repository/Dictionaries.php +++ /dev/null @@ -1,27 +0,0 @@ -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); - } -} diff --git a/app/model/Database/Repository/DictionaryRepository.php b/app/model/Database/Repository/DictionaryRepository.php new file mode 100644 index 0000000..7375b65 --- /dev/null +++ b/app/model/Database/Repository/DictionaryRepository.php @@ -0,0 +1,18 @@ + + */ +class DictionaryRepository extends AbstractRepository +{ + + +} diff --git a/app/model/Database/Repository/PronunciationRepository.php b/app/model/Database/Repository/PronunciationRepository.php new file mode 100644 index 0000000..6d6b671 --- /dev/null +++ b/app/model/Database/Repository/PronunciationRepository.php @@ -0,0 +1,16 @@ + + */ +class PronunciationRepository extends AbstractRepository +{ + +} diff --git a/app/model/Database/Repository/Pronunciations.php b/app/model/Database/Repository/Pronunciations.php deleted file mode 100644 index c53472a..0000000 --- a/app/model/Database/Repository/Pronunciations.php +++ /dev/null @@ -1,33 +0,0 @@ -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); - } -} diff --git a/app/model/Database/Repository/TermFlagRepository.php b/app/model/Database/Repository/TermFlagRepository.php new file mode 100644 index 0000000..4c3c80f --- /dev/null +++ b/app/model/Database/Repository/TermFlagRepository.php @@ -0,0 +1,18 @@ + + */ +class TermFlagRepository extends AbstractRepository +{ + + +} diff --git a/app/model/Database/Repository/TermFlags.php b/app/model/Database/Repository/TermFlags.php deleted file mode 100644 index a44a50a..0000000 --- a/app/model/Database/Repository/TermFlags.php +++ /dev/null @@ -1,37 +0,0 @@ -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); - } -} diff --git a/app/model/Database/Repository/TermRepository.php b/app/model/Database/Repository/TermRepository.php new file mode 100644 index 0000000..52484d4 --- /dev/null +++ b/app/model/Database/Repository/TermRepository.php @@ -0,0 +1,18 @@ + + */ +class TermRepository extends AbstractRepository +{ + + +} diff --git a/app/model/Database/Repository/Terms.php b/app/model/Database/Repository/Terms.php deleted file mode 100644 index 483793b..0000000 --- a/app/model/Database/Repository/Terms.php +++ /dev/null @@ -1,46 +0,0 @@ -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); - } - -} diff --git a/app/model/Database/Repository/TranslationRepository.php b/app/model/Database/Repository/TranslationRepository.php new file mode 100644 index 0000000..21f903f --- /dev/null +++ b/app/model/Database/Repository/TranslationRepository.php @@ -0,0 +1,16 @@ + + */ +class TranslationRepository extends AbstractRepository +{ + +} diff --git a/app/model/Database/Repository/Translations.php b/app/model/Database/Repository/Translations.php deleted file mode 100644 index 56bce72..0000000 --- a/app/model/Database/Repository/Translations.php +++ /dev/null @@ -1,33 +0,0 @@ -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); - } -} diff --git a/app/model/Database/TRepositories.php b/app/model/Database/TRepositories.php index 928c459..fcdb946 100644 --- a/app/model/Database/TRepositories.php +++ b/app/model/Database/TRepositories.php @@ -3,7 +3,14 @@ namespace App\Model\Database; use App\Model\Database\Entity\User; +use App\Model\Database\Entity\Translation; 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 @@ -16,4 +23,34 @@ trait TRepositories 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); + } + } diff --git a/app/modules/Front/Home/HomePresenter.php b/app/modules/Front/Home/HomePresenter.php index 344a867..bbd6c04 100644 --- a/app/modules/Front/Home/HomePresenter.php +++ b/app/modules/Front/Home/HomePresenter.php @@ -2,9 +2,281 @@ 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; 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() + { + + } +} + } diff --git a/composer.json b/composer.json index 41c7fb5..e32b5bf 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,8 @@ "nettrine/cache": "^0.3.0", "nettrine/migrations": "^0.7.0", "nettrine/fixtures": "^0.6.0", - "contributte/pdf": "^6.1" + "contributte/pdf": "^6.1", + "aleswita/visualpaginator": "^4.0" }, "require-dev": { "ninjify/qa": "^0.13", diff --git a/composer.lock b/composer.lock index 09b85f0..1900c63 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,72 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "9aed70cf6d7812823cc84844d1a5106c", + "content-hash": "c8eeafe21edd871737d5947f6972f640", "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", "version": "1.11.99.4", diff --git a/config/app/services.neon b/config/app/services.neon index 36bb30e..6c4fc43 100644 --- a/config/app/services.neon +++ b/config/app/services.neon @@ -43,7 +43,8 @@ services: # Console ================ - {class: App\Model\Console\HelloCommand, tags: {console.command: hello}} - + # Paginator =============== + - AlesWita\VisualPaginator\VisualPaginatorFactory latte: macros: