Fix nette 3.0

This commit is contained in:
2022-01-30 22:35:13 +01:00
parent 7ecaa70768
commit a4b67569a4
9 changed files with 82 additions and 53 deletions

View File

@@ -41,6 +41,7 @@ abstract class BaseFrontPresenter extends UnsecuredPresenter
protected function startup() protected function startup()
{ {
$trs = $this->em->getRepository(Translation::class)->findBy([], ['id' => 'ASC', 'direction' => 'ASC']); $trs = $this->em->getRepository(Translation::class)->findBy([], ['id' => 'ASC', 'direction' => 'ASC']);
$drs = $this->em->getRepository(Dictionary::class)->findPairs('id', 'name'); $drs = $this->em->getRepository(Dictionary::class)->findPairs('id', 'name');
$select = []; $select = [];
@@ -52,10 +53,10 @@ abstract class BaseFrontPresenter extends UnsecuredPresenter
$lang = mb_substr($lang1, 0, -1); $lang = mb_substr($lang1, 0, -1);
$lang .= "o-" . $lang2; $lang .= "o-" . $lang2;
$slug = Strings::webalize($lang); $slug = Strings::webalize($lang);
$select[$drs[$t->getDictionary()->getId()]][$t->getId()] = $lang; $select[$drs[$t->getDictionary()->id]][$t->id] = $lang;
$translations[$t->getId()]["slug"] = $slug; $translations[$t->id]["slug"] = $slug;
$translations[$t->getId()]["lang"] = $lang; $translations[$t->id]["lang"] = $lang;
$translations[$t->getId()]["t"] = $t; $translations[$t->id]["t"] = $t;
$slugs[$slug] = $t; $slugs[$slug] = $t;
} }
$this->translations = $translations; $this->translations = $translations;

View File

@@ -21,26 +21,6 @@ use App\Model\Database\Facade\TermFacade;
final class HomePresenter extends BaseFrontPresenter final class HomePresenter extends BaseFrontPresenter
{ {
/**
* @return AlesWita\Components\VisualPaginator
*/
protected function createComponentPaginator(): VisualPaginator
{
$paginator = $this->visualPaginatorFactory->create();
$paginator->ajax = false;
$paginator->canSetItemsPerPage = true;
$paginator->setItemsPerPage(100);
//$paginator->templateFile = __DIR__ . '/my_awesome_template.latte';
return $paginator;
}
public function searchFormSucceededIpa(UI\Form $form, $values) public function searchFormSucceededIpa(UI\Form $form, $values)
{ {
$translation = $values->translation; $translation = $values->translation;
@@ -96,7 +76,6 @@ final class HomePresenter extends BaseFrontPresenter
} else { } else {
$id = $this['searchForm']['translation']->value; $id = $this['searchForm']['translation']->value;
dump($id);
if (isset($this->translations[$id])) { if (isset($this->translations[$id])) {
$t = $this->translations[$id]; $t = $this->translations[$id];
$this->redirect('Front:Home:select', $t["slug"], $this['searchForm']['string']->value); $this->redirect('Front:Home:select', $t["slug"], $this['searchForm']['string']->value);
@@ -120,15 +99,7 @@ final class HomePresenter extends BaseFrontPresenter
public function actionIpa() public function actionIpa()
{ {
if ($this->getRequest()->isMethod('GET')) { $this->redirect('Search:ipa',$this->translation,$this->term);
if ($this->term) {
$this['searchForm']['string']->setValue($this->term);
$result = $this->doSearch('TermsFullQuery', $this->slugs[$this->slug]->id, $this->term);
if ($result) $this->template->result = $result;
}
}
$this['searchForm']->onSuccess[] = array($this, 'searchFormSucceededIpa');
} }
public function actionInteractive() public function actionInteractive()

View File

@@ -20,15 +20,7 @@ use App\Model\Database\Facade\TermFacade;
class SearchPresenter extends BaseFrontPresenter class SearchPresenter extends BaseFrontPresenter
{ {
/** @inject @var EntityManager */
public EntityManager $em;
/** @inject */
public TermFacade $termFacade;
/** @persistent */
public $term;
protected function doSearch($query, $translation, $term, $clen = null, $paginate = true) protected function doSearch($query, $translation, $term, $clen = null, $paginate = true)
{ {
@@ -36,30 +28,57 @@ class SearchPresenter extends BaseFrontPresenter
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"];
$this->termFacade->setDirection(1); $this->termFacade->setDirection(1);
$q = $this->termFacade->findByString($term, $t->dictionary, $clen);
/* if ($paginate) {
$this["paginator"]->setItemCount(500); if ($paginate) {
$paginator = new \Doctrine\ORM\Tools\Pagination\Paginator($q);
$count = count($paginator);
$this["paginator"]->setItemCount($count);
$offset = $this["paginator"]->getOffset(); $offset = $this["paginator"]->getOffset();
$itemsPerPage = $this['paginator']->getItemsPerPage(); $itemsPerPage = $this['paginator']->getItemsPerPage();
$q->setFirstResult($offset)->setMaxResults($itemsPerPage);
} }
*/
$q = $this->termFacade->findByString($term, $t->dictionary, $clen);
//$q->setMaxResults(500)->setFirstResult($offset)->getMaxResults($itemsPerPage);
$this->template->translation = $t; $this->template->translation = $t;
return $q->getResult(); return $q->getResult();
} }
public function renderDefault($translation,$term,$clen,$paginate = false) public function renderDefault($translation,$term,$clen = '',$paginate = true)
{ {
$this['searchForm']['string']->setValue($this->term); $this['searchForm']['string']->setValue($this->term);
$this->template->result = $this->doSearch('TermQuery',$translation,$term,$clen,$paginate); $this->template->result = $this->doSearch('TermQuery',$translation,$term,$clen,$paginate);
} }
public function renderIpa($translation,$term,$clen='',$paginate=true)
{
$this['searchForm']['string']->setValue($this->term);
$result = $this->doSearch('TermsFullQuery', $this->slugs[$this->slug]->id, $this->term);
if ($result) $this->template->result = $result;
$this['searchForm']->onSuccess[] = array($this, 'searchFormSucceededIpa');
}
/**
* @return AlesWita\Components\VisualPaginator
*/
protected function createComponentPaginator(): VisualPaginator
{
$paginator = $this->visualPaginatorFactory->create();
$paginator->ajax = false;
$paginator->canSetItemsPerPage = true;
$paginator->setItemsPerPage(20);
$paginator->templateFile = __DIR__.'/templates/bootstrap4.latte';
return $paginator;
}
} }

View File

@@ -0,0 +1,39 @@
{templateType AlesWita\VisualPaginator\Template}
{php $linkClass = $ajax ? 'page-link ajax' : 'page-link'}
<ul class="pagination">
<li n:class="$paginator->isFirst() ? 'page-item disabled' : 'page-item'">
<a n:href="paginate!, page => $paginator->page - 1" class="{$linkClass}">&laquo;</a>
</li>
{foreach $steps as $step}
<li n:class="$step === $paginator->page ? 'page-item active' : 'page-item'">
<a n:href="paginate!, page => $step" class="{$linkClass}">{$step}</a>
</li>
{if $iterator->nextValue > $step + 1}
<li class="page-item disabled">
<span class="page-link">&hellip;</span>
</li>
{/if}
{/foreach}
<li n:class="$paginator->isLast() ? 'page-item disabled' : 'page-item'">
<a n:href="paginate!, page => $paginator->page + 1" class="{$linkClass}">&raquo;</a>
</li>
</ul>
{if $itemsPerPage}
{form itemsPerPage, class => $ajax ? 'form-inline ajax' : 'form-inline'}
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">{label itemsPerPage /}</span>
</div>
{input itemsPerPage, class => "form-control"}
<div class="input-group-append">
{input send, class => "btn btn-outline-secondary"}
</div>
</div>
{/form}
{/if}

View File

@@ -56,7 +56,7 @@ $( document ).ready(function() {
</tr> </tr>
{/foreach} {/foreach}
</table> </table>
{control paginator}
{/ifset} {/ifset}
</div> </div>
{/block} {/block}

View File

@@ -38,7 +38,7 @@ $( document ).ready(function() {
<span class="term">{$term->string1}</span>&nbsp; <span class="term">{$term->string1}</span>&nbsp;
{foreach $term->pronunciations as $pron} {foreach $term->pronunciations as $pron}
<span class="ipa-{$pron->type->id}">[{$pron->ipa}]</span> <span class="ipa-{$pron->type->id}">[{$pron->ipa}]</span>
<img n:if="$pron->filename" class="sound-ipa ajax" src="/images/sound.png" alt="Prehraj" style="vertical-align: middle;" data-sound-id="{$pron->id}" ></image> <img n:if="$pron->filename" class="sound-ipa ajax" src="/assets/images/sound.png" alt="Prehraj" style="vertical-align: middle;" data-sound-id="{$pron->id}" ></image>
{/foreach} {/foreach}
<br/> <br/>
<div style="margin-left: 20px;" class="translations"> <div style="margin-left: 20px;" class="translations">
@@ -51,7 +51,6 @@ $( document ).ready(function() {
{/foreach} {/foreach}
</table> </table>
{/ifset} {/ifset}
{/form}
{control paginator} {control paginator}
</div> </div>
{/block} {/block}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 737 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB