-
Notifications
You must be signed in to change notification settings - Fork 0
/
GalleryController.php
85 lines (70 loc) · 2.78 KB
/
GalleryController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
/*
* DbM Framework
* All code copyright Design by Malina
* DbM: www.dbm.org.pl
*/
declare(strict_types=1);
namespace App\Controller;
use App\Config\ConstantConfig;
use App\Model\GalleryModel;
use Dbm\Classes\BaseController;
use Dbm\Interfaces\DatabaseInterface;
class GalleryController extends BaseController
{
private $model;
public function __construct(DatabaseInterface $database)
{
parent::__construct($database);
$model = new GalleryModel($database);
$this->model = $model;
}
/* @Route: "/gallery" */
public function index()
{
$translation = $this->translation;
$meta = [
'meta.keywords' => $translation->trans('gallery.keywords'),
'meta.description' => $translation->trans('gallery.description'),
'meta.title' => $translation->trans('gallery.title'),
];
$queryGallery = $this->model->getGalleryPhotos(ConstantConfig::GALLERY_INDEX_ITEM_LIMIT);
$this->render('gallery/index.phtml', [
'meta' => $meta,
'gallery' => $queryGallery,
]);
}
/* @Route: "/gallery/ajaxLoadData" */
public function ajaxLoadDataMethod(): void
{
$limit = ConstantConfig::GALLERY_INDEX_ITEM_LIMIT;
$start = (int) $this->requestData('parameters');
if (isset($limit, $start)) {
$queryGallery = $this->model->getGalleryLoadData($start, $limit);
if ($queryGallery) {
echo '<script src="./assets/js/masonry.pkgd.min.js"></script>';
foreach ($queryGallery as $item) {
echo '<div class="col text-center">';
echo '<a class="gallery-item" href="./images/gallery/photo/' . $item->filename . '" data-fancybox="fancyGallery"
data-captiontext="' . $item->title . '" data-captionlink="">';
echo '<img src="./images/gallery/thumb/' . $item->filename . '" class="img-fluid" alt="' . $item->title . '">';
echo '</a>';
echo '</div>';
}
echo "<script>
$('[data-fancybox=\"fancyGallery\"]').fancybox({
protect: true,
caption: function(instance, item) {
var caption = $(this).data('captiontext') || '';
var captionLink = $(this).data('captionlink') || '';
if (item.type === 'image' && caption.length) {
caption = captionLink.length > 8 ? '<a href=\"' + captionLink + '\" target=\"_blank\">' + caption + '</a>' : caption + '<br />';
}
return caption;
}
});
</script>";
}
}
}
}