Initial commit: is_imageslider out of the box. v2.3.2

This commit is contained in:
Isabelle Anno
2025-11-19 13:30:22 +01:00
commit 2f4716f567
100 changed files with 8635 additions and 0 deletions

View File

@@ -0,0 +1,68 @@
<?php
declare(strict_types=1);
namespace Oksydan\IsImageslider\Hook;
use Oksydan\IsImageslider\Cache\TemplateCache;
use Oksydan\IsImageslider\Configuration\SliderConfiguration;
use Oksydan\IsImageslider\Presenter\ImageSlidePresenter;
use Oksydan\IsImageslider\Repository\ImageSliderRepository;
abstract class AbstractCacheableDisplayHook extends AbstractDisplayHook
{
/**
* @var ImageSliderRepository
*/
protected $slideRepository;
/**
* @var ImageSlidePresenter
*/
protected $slidePresenter;
/**
* @var TemplateCache
*/
protected $templateCache;
public function __construct(
\Module $module,
\Context $context,
SliderConfiguration $sliderConfiguration,
ImageSliderRepository $slideRepository,
ImageSlidePresenter $slidePresenter,
TemplateCache $templateCache
) {
parent::__construct($module, $context, $sliderConfiguration);
$this->slideRepository = $slideRepository;
$this->slidePresenter = $slidePresenter;
$this->templateCache = $templateCache;
}
public function execute(array $params): string
{
if (!$this->shouldBlockBeDisplayed($params)) {
return '';
}
$this->templateCache->clearTemplateCacheIfNeeded($this->context->shop->id);
if (!$this->isTemplateCached()) {
$this->assignTemplateVariables($params);
}
return $this->module->fetch($this->getTemplateFullPath(), $this->getCacheKey());
}
protected function getCacheKey(): string
{
return $this->module->getCacheId();
}
protected function isTemplateCached(): bool
{
return $this->module->isCached($this->getTemplateFullPath(), $this->getCacheKey());
}
}

View File

@@ -0,0 +1,49 @@
<?php
declare(strict_types=1);
namespace Oksydan\IsImageslider\Hook;
use Oksydan\IsImageslider\Configuration\SliderConfiguration;
abstract class AbstractDisplayHook extends AbstractHook
{
protected $sliderConfiguration;
public function __construct(
\Module $module,
\Context $context,
SliderConfiguration $sliderConfiguration
) {
parent::__construct($module, $context);
$this->sliderConfiguration = $sliderConfiguration;
}
public function execute(array $params): string
{
if (!$this->shouldBlockBeDisplayed($params)) {
return '';
}
$this->assignTemplateVariables($params);
return $this->module->fetch($this->getTemplateFullPath());
}
protected function assignTemplateVariables(array $params)
{
}
protected function shouldBlockBeDisplayed(array $params)
{
return true;
}
public function getTemplateFullPath(): string
{
return "module:{$this->module->name}/views/templates/hook/{$this->getTemplate()}";
}
abstract protected function getTemplate(): string;
}

View File

@@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
namespace Oksydan\IsImageslider\Hook;
abstract class AbstractHook implements HookInterface
{
protected $module;
protected $context;
public function __construct(\Module $module, \Context $context)
{
$this->module = $module;
$this->context = $context;
}
}

View File

@@ -0,0 +1,55 @@
<?php
declare(strict_types=1);
namespace Oksydan\IsImageslider\Hook;
class DisplayHeader extends AbstractCacheableDisplayHook
{
private const TEMPLATE_FILE = 'head.tpl';
protected function getTemplate(): string
{
return DisplayHeader::TEMPLATE_FILE;
}
protected function assignTemplateVariables(array $params)
{
$slide = $this->getSlide();
$this->context->smarty->assign([
'image' => $slide['image_url'] ?? null,
]);
}
/**
* @return array
*/
private function getSlide(): array
{
$now = new \DateTime();
$slides = $this->slideRepository->getActiveSliderByLandAndStoreId(
$this->context->language->id,
$this->context->shop->id,
true,
1,
$now
);
foreach ($slides as &$slide) {
$slide = $this->slidePresenter->present($slide);
}
return count($slides) ? reset($slides) : [];
}
protected function getCacheKey(): string
{
return parent::getCacheKey() . '_' . ($this->context->isMobile() ? 'mobile' : 'desktop');
}
protected function shouldBlockBeDisplayed(array $params)
{
return $this->context->controller->getPageName() === 'index';
}
}

View File

@@ -0,0 +1,53 @@
<?php
declare(strict_types=1);
namespace Oksydan\IsImageslider\Hook;
class DisplayHome extends AbstractCacheableDisplayHook
{
private const TEMPLATE_FILE = 'slider.tpl';
protected function getTemplate(): string
{
return DisplayHome::TEMPLATE_FILE;
}
protected function assignTemplateVariables(array $params)
{
$this->context->smarty->assign([
'homeslider' => [
'slides' => $this->getSlides(),
'speed' => $this->sliderConfiguration->getSliderSpeed(),
'pause' => $this->sliderConfiguration->getSliderPauseOnHover(),
'wrap' => $this->sliderConfiguration->getSliderWrap(),
],
]);
}
/**
* @return array
*/
private function getSlides(): array
{
$now = new \DateTime();
$slides = $this->slideRepository->getActiveSliderByLandAndStoreId(
$this->context->language->id,
$this->context->shop->id,
true,
0, // 0 means no limit
$now
);
foreach ($slides as &$slide) {
$slide = $this->slidePresenter->present($slide);
}
return $slides;
}
protected function getCacheKey(): string
{
return parent::getCacheKey() . '_' . ($this->context->isMobile() ? 'mobile' : 'desktop');
}
}

View File

@@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace Oksydan\IsImageslider\Hook;
interface HookInterface
{
public function execute(array $params);
}

View File

@@ -0,0 +1,61 @@
<?php
namespace Oksydan\IsImageslider\Hook;
class WidgetCapability extends AbstractCacheableDisplayHook
{
private const TEMPLATE_FILE = 'slider.tpl';
protected function getTemplate(): string
{
return WidgetCapability::TEMPLATE_FILE;
}
protected function getCacheKey(): string
{
return parent::getCacheKey() . '_' . ($this->context->isMobile() ? 'mobile' : 'desktop');
}
/**
* @return array
*/
private function getSlides(): array
{
$now = new \DateTime();
$slides = $this->slideRepository->getActiveSliderByLandAndStoreId(
$this->context->language->id,
$this->context->shop->id,
true,
0, // 0 means no limit
$now
);
foreach ($slides as &$slide) {
$slide = $this->slidePresenter->present($slide);
}
return $slides;
}
public function getWidgetVariables($params): array
{
return [
'homeslider' => [
'slides' => $this->getSlides(),
'speed' => $this->sliderConfiguration->getSliderSpeed(),
'pause' => $this->sliderConfiguration->getSliderPauseOnHover(),
'wrap' => $this->sliderConfiguration->getSliderWrap(),
],
];
}
protected function assignTemplateVariables(array $params)
{
$this->context->smarty->assign($this->getWidgetVariables($params));
}
public function renderWidget($params): string
{
return $this->execute($params);
}
}