Skip to content

Commit 84c12db

Browse files
templates & calendar initial code
1 parent 9375146 commit 84c12db

File tree

7 files changed

+219
-21
lines changed

7 files changed

+219
-21
lines changed

app/base/tools/Utils/HtmlPartsRenderer.php

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,25 +1796,25 @@ public function renderOrderShipment(OrderShipment $shipment) : string
17961796
return (string)$table;
17971797
}
17981798

1799-
public function renderCalendar(\DateTime $date, string $view = 'month'): string
1799+
public function renderCalendar(\DateTime $date, string $view = 'month', array $cellsContent = []): string
18001800
{
18011801
switch ($view) {
18021802
case 'day':
1803-
return $this->renderDayView($date);
1803+
return $this->renderDayView($date, cellsContent: $cellsContent);
18041804
case 'week':
1805-
return $this->renderWeekView($date);
1805+
return $this->renderWeekView($date, cellsContent: $cellsContent);
18061806
case 'month':
18071807
default:
1808-
return $this->renderMonthView($date);
1808+
return $this->renderMonthView($date, cellsContent: $cellsContent);
18091809
}
18101810
}
18111811

1812-
protected function renderMonthView(\DateTime $date): string
1812+
protected function renderMonthView(\DateTime $date, array $cellsContent = []): string
18131813
{
18141814
$start = (clone $date)->modify('first day of this month');
18151815
$end = (clone $date)->modify('last day of this month');
18161816

1817-
$startWeekDay = (int)$start->format('N'); // 1 = lun, 7 = dom
1817+
$startWeekDay = (int)$start->format('N'); // 1 = mon, 7 = sun
18181818
$daysInMonth = (int)$date->format('t');
18191819

18201820
$table = $this->containerMake(
@@ -1845,15 +1845,16 @@ protected function renderMonthView(\DateTime $date): string
18451845
TagElement::class,
18461846
['options' => [
18471847
'tag' => 'tr',
1848+
'attributes' => ['class' => 'thead-dark'],
18481849
]]
18491850
);
1850-
foreach (['Mon','Tue','Wed','Thu','Fri','Sat','Sun'] as $d) {
1851+
foreach (['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'] as $d) {
18511852
$row->addChild(
18521853
$this->containerMake(
18531854
TagElement::class,
18541855
['options' => [
18551856
'tag' => 'th',
1856-
'text' => $this->getUtils()->translate($d),
1857+
'text' => substr($this->getUtils()->translate($d), 0, 3),
18571858
]]
18581859
)
18591860
);
@@ -1884,23 +1885,21 @@ protected function renderMonthView(\DateTime $date): string
18841885

18851886
while ($currentDay <= $daysInMonth) {
18861887
$current = (clone $start)->setDate($start->format('Y'), $start->format('m'), $currentDay);
1887-
$isToday = $current->format('Y-m-d') === date('Y-m-d');
18881888

1889-
$class = $isToday ? 'table-primary fw-bold' : '';
1889+
$class = $this->getCalendarDayClasses($current);
18901890

18911891
$currentRow->addChild(
18921892
$this->containerMake(
18931893
TagElement::class,
18941894
['options' => [
18951895
'tag' => 'td',
1896-
'text' => (string)$currentDay,
1896+
'text' => '<div>' . (string)$currentDay . '</div><div>' . ((string)($cellsContent[$current->format('Y-m-d')] ?? '')) . '</div>',
18971897
'attributes' => ['class' => $class],
18981898
]]
18991899
)
19001900
);
19011901

19021902
if ($current->format('N') == 7) {
1903-
$tbody->addChild($currentRow);
19041903
$currentRow = $this->containerMake(
19051904
TagElement::class,
19061905
['options' => [
@@ -1916,7 +1915,7 @@ protected function renderMonthView(\DateTime $date): string
19161915
return (string)$table;
19171916
}
19181917

1919-
protected function renderWeekView(\DateTime $date, string $formatDate = 'D d/m'): string
1918+
protected function renderWeekView(\DateTime $date, string $formatDate = 'D d/m', array $cellsContent = []): string
19201919
{
19211920
$startOfWeek = (clone $date)->modify('monday this week');
19221921

@@ -1932,6 +1931,7 @@ protected function renderWeekView(\DateTime $date, string $formatDate = 'D d/m')
19321931
TagElement::class,
19331932
['options' => [
19341933
'tag' => 'thead',
1934+
'attributes' => ['class' => 'thead-dark'],
19351935
]]
19361936
);
19371937
$tbody = $this->containerMake(
@@ -1971,14 +1971,13 @@ protected function renderWeekView(\DateTime $date, string $formatDate = 'D d/m')
19711971
);
19721972
for ($i=0; $i<7; $i++) {
19731973
$d = (clone $startOfWeek)->modify("+$i day");
1974-
$isToday = $d->format('Y-m-d') === date('Y-m-d');
1975-
$class = $isToday ? 'table-primary fw-bold' : '';
1974+
$class = $this->getCalendarDayClasses($d);
19761975
$row->addChild(
19771976
$this->containerMake(
19781977
TagElement::class,
19791978
['options' => [
19801979
'tag' => 'td',
1981-
'text' => '',
1980+
'text' => (string)($cellsContent[$d->format('Y-m-d')] ?? ''),
19821981
'attributes' => ['class' => $class, 'style' => 'height:100px'],
19831982
]]
19841983
)
@@ -1988,7 +1987,7 @@ protected function renderWeekView(\DateTime $date, string $formatDate = 'D d/m')
19881987
return (string)$table;
19891988
}
19901989

1991-
protected function renderDayView(\DateTime $date, string $formatDate = 'l d F Y'): string
1990+
protected function renderDayView(\DateTime $date, string $formatDate = 'l d F Y', array $cellsContent = []): string
19921991
{
19931992
$table = $this->containerMake(
19941993
TagElement::class,
@@ -2020,6 +2019,7 @@ protected function renderDayView(\DateTime $date, string $formatDate = 'l d F Y'
20202019
TagElement::class,
20212020
['options' => [
20222021
'tag' => 'tr',
2022+
'attributes' => ['class' => 'thead-dark'],
20232023
'children' => [
20242024
$this->containerMake(TagElement::class, ['options' => [
20252025
'tag' => 'th',
@@ -2046,7 +2046,7 @@ protected function renderDayView(\DateTime $date, string $formatDate = 'l d F Y'
20462046
]]),
20472047
$this->containerMake(TagElement::class, ['options' => [
20482048
'tag' => 'td',
2049-
'text' => '',
2049+
'text' => (string)($cellsContent[$h] ?? ''),
20502050
'attributes' => ['style' => 'height:40px;'],
20512051
]]),
20522052
]
@@ -2057,4 +2057,13 @@ protected function renderDayView(\DateTime $date, string $formatDate = 'l d F Y'
20572057

20582058
return (string)$table;
20592059
}
2060+
2061+
private function getCalendarDayClasses($current) : string
2062+
{
2063+
$classes = [$current->format('Y-m-d')];
2064+
if ($current->format('Y-m-d') === date('Y-m-d')) {
2065+
$classes[] = 'table-primary fw-bold';
2066+
}
2067+
return implode(' ', $classes);
2068+
}
20602069
}

app/site/controllers/Frontend/Commerce/BookDetail.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public static function getRouteVerbs(): array
6060
*/
6161
public function getTemplateName(): string
6262
{
63-
return 'commerce/downloadable_detail';
63+
return 'commerce/book_detail';
6464
}
6565

6666
/**
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
<?php
2+
3+
/**
4+
* SiteBase
5+
* PHP Version 8.3
6+
*
7+
* @category CMS / Framework
8+
* @package Degami\Sitebase
9+
* @author Mirko De Grandis <degami@github.com>
10+
* @license MIT https://opensource.org/licenses/mit-license.php
11+
* @link https://github.com/degami/sitebase
12+
*/
13+
14+
namespace App\Site\Controllers\Frontend\Commerce;
15+
16+
use App\App;
17+
use Degami\Basics\Exceptions\BasicException;
18+
use App\Base\Abstracts\Controllers\FrontendPage;
19+
use App\Base\Abstracts\Controllers\FrontendPageWithLang;
20+
use App\Base\Routing\RouteInfo;
21+
use App\Base\Tools\Utils\SiteData;
22+
use App\Site\Models\Book;
23+
use App\Site\Models\DownloadableProduct;
24+
use DI\DependencyException;
25+
use DI\NotFoundException;
26+
27+
/**
28+
* Books List Page
29+
*/
30+
class BooksList extends FrontendPageWithLang
31+
{
32+
/**
33+
* @var RouteInfo|null route info object
34+
*/
35+
protected ?RouteInfo $route_info = null;
36+
37+
/**
38+
* @var string page title
39+
*/
40+
protected ?string $page_title = 'Books';
41+
42+
/**
43+
* gets route group
44+
*
45+
* @return string
46+
*/
47+
public static function getRouteGroup(): string
48+
{
49+
return '';
50+
}
51+
52+
/**
53+
* return route path
54+
*
55+
* @return array
56+
*/
57+
public static function getRoutePath(): array
58+
{
59+
return [
60+
'frontend.commerce.bookslist' => 'books',
61+
'frontend.commerce.bookslist.withlang' => '/{lang:[a-z]{2}}/books',
62+
];
63+
}
64+
65+
/**
66+
* {@inheritdoc}
67+
*
68+
* @return string
69+
*/
70+
public function getTemplateName(): string
71+
{
72+
return 'commerce/books_list';
73+
}
74+
75+
/**
76+
* {@inheritdoc}
77+
*
78+
* @return bool
79+
*/
80+
public static function isEnabled(): bool
81+
{
82+
return App::installDone() && boolval(\App\App::getInstance()->getEnvironment()->getVariable('ENABLE_COMMERCE'));
83+
}
84+
85+
/**
86+
* {@inheritdoc}
87+
*
88+
* @return array
89+
* @throws BasicException
90+
* @throws DependencyException
91+
* @throws NotFoundException
92+
*/
93+
public function getTemplateData(): array
94+
{
95+
/** @var \App\Base\Abstracts\Models\BaseCollection $collection */
96+
$collection = $this->containerCall([Book::class, 'getCollection']);
97+
$collection->addCondition(['locale' => $this->getCurrentLocale()]);
98+
$data = $this->containerCall([$collection, 'paginate'] /*, ['page_size' => 10]*/);
99+
return $this->template_data += [
100+
'page_title' => $this->getUtils()->translate('Books', locale: $this->getCurrentLocale()),
101+
'products' => $data['items'],
102+
'total' => $data['total'],
103+
'current_page' => $data['page'],
104+
'paginator' => $this->getHtmlRenderer()->renderPaginator($data['page'], $data['total'], $this, $data['page_size']),
105+
];
106+
}
107+
108+
/**
109+
* {@inheritdoc}
110+
*
111+
* @return string
112+
* @throws BasicException
113+
* @throws DependencyException
114+
* @throws NotFoundException
115+
*/
116+
public function getCurrentLocale(): string
117+
{
118+
if (!$this->locale) {
119+
$this->locale = parent::getCurrentLocale();
120+
if ($this->locale == null) {
121+
$this->locale = SiteData::DEFAULT_LOCALE;
122+
}
123+
}
124+
$this->getApp()->setCurrentLocale($this->locale);
125+
return $this->locale;
126+
}
127+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/**
3+
* @var $object \App\Base\Abstracts\Models\FrontendModel
4+
*/
5+
$this->layout('frontend::layout', ['title' => $object->getPageTitle()] + get_defined_vars()) ?>
6+
7+
<?php $this->start('head') ?>
8+
<link rel="canonical" href="<?= $object->getFrontendUrl();?>" />
9+
<?= $this->section('head'); ?>
10+
<?php $this->stop() ?>
11+
12+
<div class="row">
13+
<div class="col-md-10">
14+
15+
<h1 class="giftcard-title"><?php echo $object->getTitle();?></h1>
16+
<div class="giftcard-content"><?php echo $object->getContent();?></div>
17+
18+
<?php if (($gallery = $object->getGallery()) && count($gallery)) : ?>
19+
<div class="page-gallery">
20+
<div class="row gallery">
21+
<?php foreach ($gallery as $image) : ?>
22+
<?php echo $image->getThumb("300x200", null, 'img-fluid img-thumbnail', ['data-gallery-id' => 'gallery-'.$object->getId(), "data-gallery-src" => $image->getImageUrl(), 'data-gallery-desc' => $image->getFileName()]); ?>
23+
<?php endforeach; ?>
24+
</div>
25+
</div>
26+
<?php endif; ?>
27+
28+
</div>
29+
<div class="col-md-2">
30+
31+
<?= $form; ?>
32+
33+
</div>
34+
</div>
35+
36+
<?= $this->section('content'); ?>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/**
3+
* @var $paginator array
4+
* @var $products array
5+
* @var $page_title string
6+
*/
7+
$this->layout('frontend::layout', ['title' => $this->sitebase()->translate('Books')] + get_defined_vars()) ?>
8+
9+
<h1 class="page-title"><?php echo $page_title;?></h1>
10+
<div class="row">
11+
<div class="col-md-12">
12+
<ul class="books-list">
13+
<?php foreach ($products as $key => $product) :?>
14+
<li>
15+
<div>
16+
<a href="<?= $product->getFrontendUrl(); ?>" class="book-detail">
17+
<span class="book-title"><?= $product->getTitle(); ?></span>
18+
</a>
19+
</div>
20+
<div class="book-description"><?= $this->sitebase()->summarize($product->getContent(), 20); ?></div>
21+
</li>
22+
<?php endforeach;?>
23+
</ul>
24+
<?= $paginator; ?>
25+
</div>
26+
</div>

templates/frontend/commerce/downloadables_list.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
33
* @var $paginator array
4-
* @var $news array
4+
* @var $products array
55
* @var $page_title string
66
*/
77
$this->layout('frontend::layout', ['title' => $this->sitebase()->translate('Downloadables')] + get_defined_vars()) ?>

templates/frontend/commerce/giftcards_list.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
33
* @var $paginator array
4-
* @var $news array
4+
* @var $products array
55
* @var $page_title string
66
*/
77
$this->layout('frontend::layout', ['title' => $this->sitebase()->translate('Gift Cards')] + get_defined_vars()) ?>

0 commit comments

Comments
 (0)