Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

event template coded & styled by layout #35

Merged
merged 4 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .db/dummy.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
INSERT INTO event (title, event_time, event_place) VALUES ('Patecni grilovana zebra', '2023-10-26 10:38:10', 'Snyt - Vinohrady');
INSERT INTO event (title, event_time, event_place) VALUES ('Patecni grilovana ryba', '2023-10-26 10:38:10', 'Snyt - Vinohrady');
INSERT INTO event (title) VALUES ('Zahradka otevrena');
INSERT INTO event (title, event_time, event_place) VALUES ('Patecni mega-rizek', '2023-10-26 10:38:10', 'Snyt - Vinohrady');
INSERT INTO event (title) VALUES ('Na cepu nove Plzen 10');
INSERT INTO event (title, event_time, event_place) VALUES ('Patecni grilovane kure', '2023-10-26 10:38:10', 'Snyt - Vinohrady');
INSERT INTO event (title) VALUES ('Zahradka zavrena');
INSERT INTO event (title) VALUES ('Hledame kuchare');
9 changes: 9 additions & 0 deletions .db/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CREATE TABLE event (
id INT UNSIGNED AUTO_INCREMENT NOT NULL,
title VARCHAR(255) NOT NULL,
event_time TIMESTAMP DEFAULT NULL,
event_place VARCHAR(255) DEFAULT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY(id)
);
19 changes: 19 additions & 0 deletions app/Model/BaseRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace App\Model;

use Dibi\Connection;

abstract class BaseRepository
{
public function __construct(private Connection $database)
{
}

public function getDibiConnection(): Connection
{
return $this->database;
}
}
41 changes: 41 additions & 0 deletions app/Model/Repository/EventRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace App\Model\Repository;

use App\Model\BaseRepository;

class EventRepository extends BaseRepository
{
private const TABLE = 'event';

public function findAll(): array
{
$result = $this->getDibiConnection()
->select('*')
->from(self::TABLE);

return $result->fetchAssoc('id');
}

public function getAllCount(): int
{
$result = $this->getDibiConnection()
->select('COUNT(id)')
->from(self::TABLE);

return $result->fetchSingle();
}

public function findAllForPaginator(int $limit, int $offset): array
{
$result = $this->getDibiConnection()
->select('*')
->from(self::TABLE)
->limit($limit)
->offset($offset);

return $result->fetchAssoc('id');
}
}
2 changes: 1 addition & 1 deletion app/Module/BasePresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

use Nette\Application\UI\Presenter;

class BasePresenter extends Presenter
abstract class BasePresenter extends Presenter
{
}
17 changes: 16 additions & 1 deletion app/Module/User/Event/EventPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,27 @@

namespace App\Module\User\Event;

use App\Model\Repository\EventRepository;
use App\Module\User\UserPresenter;
use Nette\Utils\Paginator;

class EventPresenter extends UserPresenter
{
public function actionDefault(): void
public function __construct(protected EventRepository $eventRepository)
{
parent::__construct();
}

public function actionDefault(int $page = 1): void
{
$eventAllCount = $this->eventRepository->getAllCount();

$paginator = new Paginator();
$paginator->setItemCount($eventAllCount);
$paginator->setItemsPerPage(6);
$paginator->setPage($page);

$this->template->events = $this->eventRepository->findAllForPaginator($paginator->getLength(), $paginator->getOffset());
$this->template->paginator = $paginator;
}
}
232 changes: 103 additions & 129 deletions app/Module/User/Event/templates/other/event.latte
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{varType Nette\Utils\Paginator $paginator}
{varType array $events}
{block event}

<div class="event">
Expand All @@ -14,139 +16,111 @@
</div>
</div>

<ul class="event__row-wrap">
<li class="event__row">
<div class="event__column">
<a href="#" class="event__link">
<div class="event__item-image-wrap">
<img src="{$basePath}/assets/image/content/beer-min.jpg" class="event__item-image">
</div>
<div class="event__text-block-wrap">
<div class="event__text-block">
<div class="event__text-block event__text-block__date-block">
<span>event</span>
<span>20 Dec</span>
</div>
<div class="event__text-block event__text-block__description-block">
<p>Learem ipsum dolor sit amet, consecteurer</p>
</div>
<div class="event__text-block event__text-block__button-block">
<span>read more</span>
</div>
</div>
</div>
</a>
</div>
<div class="event__column">
<a href="#" class="event__link">
<div class="event__item-image-wrap">
<img src="{$basePath}/assets/image/content/rest-min.jpg" class="event__item-image">
</div>
<div class="event__text-block-wrap">
<div class="event__text-block">
<div class="event__text-block event__text-block__date-block">
<span>event</span>
<span>20 Dec</span>
</div>
<div class="event__text-block event__text-block__description-block">
<p>Learem ipsum dolor sit amet, consecteurer</p>
</div>
<div class="event__text-block event__text-block__button-block">
<span>read more</span>
</div>
</div>
</div>
</a>
</div>
<div class="event__column">
<a href="#" class="event__link">
<div class="event__item-image-wrap">
<img src="{$basePath}/assets/image/content/burger-min.jpg" class="event__item-image">
</div>
<div class="event__text-block-wrap">
<div class="event__text-block">
<div class="event__text-block event__text-block__date-block">
<span>event</span>
<span>20 Dec</span>
</div>
<div class="event__text-block event__text-block__description-block">
<p>Learem ipsum dolor sit amet, consecteurer</p>
</div>
<div class="event__text-block event__text-block__button-block">
<span>read more</span>
</div>
</div>
</div>
</a>
</div>
</li>
<li class="event__row">
<div class="event__column">
<a href="#" class="event__link">
<div class="event__item-image-wrap">
<img src="{$basePath}/assets/image/content/beer-min.jpg" class="event__item-image">
</div>
<div class="event__text-block-wrap">
<div class="event__text-block">
<div class="event__text-block event__text-block__date-block">
<span>event</span>
<span>20 Dec</span>
</div>
<div class="event__text-block event__text-block__description-block">
<p>Learem ipsum dolor sit amet, consecteurer</p>
</div>
<div class="event__text-block event__text-block__button-block">
<span>read more</span>
</div>
{snippet event}
<ul class="event__row-wrap">
<li class="event__row">
{foreach $events as $key => $event}
<div class="event__column">
<a href="#" class="event__link">
<div class="event__item-image-wrap">
<img src="{$basePath}/assets/image/content/beer-min.jpg" class="event__item-image">
</div>
</div>
</a>
</div>
<div class="event__column">
<a href="#" class="event__link">
<div class="event__item-image-wrap">
<img src="{$basePath}/assets/image/content/rest-min.jpg" class="event__item-image">
</div>
<div class="event__text-block-wrap">
<div class="event__text-block">
<div class="event__text-block event__text-block__date-block">
<span>event</span>
<span>20 Dec</span>
</div>
<div class="event__text-block event__text-block__description-block">
<p>Learem ipsum dolor sit amet, consecteurer</p>
</div>
<div class="event__text-block event__text-block__button-block">
<span>read more</span>
</div>
</div>
</div>
</a>
</div>
<div class="event__column">
<a href="#" class="event__link">
<div class="event__item-image-wrap">
<img src="{$basePath}/assets/image/content/burger-min.jpg" class="event__item-image">
</div>
<div class="event__text-block-wrap">
<div class="event__text-block">
<div class="event__text-block event__text-block__date-block">
<span>event</span>
<span>20 Dec</span>
</div>
<div class="event__text-block event__text-block__description-block">
<p>Learem ipsum dolor sit amet, consecteurer</p>
</div>
<div class="event__text-block event__text-block__button-block">
<span>read more</span>
<div class="event__text-block-wrap">
<div class="event__text-block">
<div class="event__text-block event__text-block__date-block">
<span>event</span>
<span>{($event->event_time ?? $event->created_at)|date:'j. n.'}</span>
</div>
<div class="event__text-block event__text-block__description-block">
<p>{$event->title}</p>
</div>
<div class="event__text-block event__text-block__button-block">
<span>read more</span>
</div>
</div>
</div>
</div>
</a>
</div>
</li>
</ul>
</a>
</div>
{var $isLastItemInRow = $iterator->counter % 3 === 0}
{var $isEventToShow = array_key_last($events) !== $key}
{if $isLastItemInRow && $isEventToShow}
</li>
<li class="event__row">
{/if}
{/foreach}
</li>
</ul>
<div class="event__paginator">
{var $iamOnFirstPage = $paginator->isFirst()}
{var $iamOnLastPage = $paginator->isLast()}
{var $currentPage = $paginator->getPage()}
{var $pageCount = $paginator->getPageCount()}
<a n:href="default, $currentPage - 1" class="event__paginator__arrow-link{if $iamOnFirstPage} disabled{/if}">
<svg class="event__paginator__arrow event__paginator__arrow--left">
<use xlink:href="{$basePath}/assets/image/icon/general.svg#icon-arrow-dropdown-thin"></use>
</svg>
</a>
<ul class="event__paginator__list">
{var $iamOnFirstOrSecondPage = in_array($currentPage, [1, 2])}
{var $iamOnMoreThanThirdPage = $currentPage > 3}
{var $areMoreThanTwoPagesBeforeMe = ($pageCount - $currentPage) > 2}
{var $iamNotOnLastOrOneBeforeLastPage = !$iamOnLastPage && ($currentPage !== ($pageCount - 1))}

{if !$iamOnFirstOrSecondPage}
<li class="event__paginator__item">
<a n:href="default, 1" class="event__paginator__item-link ajax">
<span class="event__paginator__item-number">1</span>
</a>
</li>
{/if}

{if $iamOnMoreThanThirdPage}
<li class="event__paginator__item event__paginator__item--special">
<span class="event__paginator__item-number">...</span>
</li>
{/if}

{if !$iamOnFirstPage}
<li class="event__paginator__item">
<a n:href="default, $currentPage - 1" class="event__paginator__item-link ajax">
<span class="event__paginator__item-number">{$currentPage - 1}</span>
</a>
</li>
{/if}

<li class="event__paginator__item event__paginator__item--current">
<span class="event__paginator__item-number">{$currentPage}</span>
</li>

{if !$iamOnLastPage}
<li class="event__paginator__item">
<a n:href="default, $currentPage + 1" class="event__paginator__item-link">
<span class="event__paginator__item-number">{$currentPage + 1}</span>
</a>
</li>
{/if}

{if $areMoreThanTwoPagesBeforeMe}
<li class="event__paginator__item event__paginator__item--special">
<span class="event__paginator__item-number">...</span>
</li>
{/if}

{if $iamNotOnLastOrOneBeforeLastPage}
<li class="event__paginator__item">
<a n:href="default, $pageCount" class="event__paginator__item-link ajax">
<span class="event__paginator__item-number">{$pageCount}</span>
</a>
</li>
{/if}
</ul>
<a n:href="default, $currentPage + 1" class="event__paginator__arrow-link{if $iamOnLastPage} disabled{/if} ajax">
<svg class="event__paginator__arrow event__paginator__arrow--right">
<use xlink:href="{$basePath}/assets/image/icon/general.svg#icon-arrow-dropdown-thin"></use>
</svg>
</a>
</div>
{/snippet}
</div>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/Module/templates/@layout.latte
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
{include footer}

{block scripts}
<script src="https://nette.github.io/resources/js/3/netteForms.min.js"></script>
<script src="{$basePath}/assets/dist/bundle.js"></script>
<script src="https://nette.github.io/resources/js/3/netteForms.min.js"></script>
<script src="{$basePath}/assets/dist/bundle.js"></script>
{/block}
</body>
</html>
Loading