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

Release new version 2.3.0 #40

Merged
merged 22 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
9 changes: 8 additions & 1 deletion config/common.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
parameters:
images_directory: '%kernel.project_dir%/modules/is_imageslider/img/'
images_uri: '/modules/is_imageslider/img/'
module_uri: !php/const _MODULE_DIR_
images_uri: '%module_uri%is_imageslider/img/'
placeholder_img: '/modules/is_imageslider/views/img/placeholder.jpeg'

services:
Expand Down Expand Up @@ -73,6 +74,12 @@ services:
parent: 'oksydan.is_imageslider.hook.abstract_cacheable_display_hook'
public: true

# Modification of the module into a widget
oksydan.is_imageslider.hook.widget_capability:
class: Oksydan\IsImageslider\Hook\WidgetCapability
parent: 'oksydan.is_imageslider.hook.abstract_cacheable_display_hook'
public: true

oksydan.is_imageslider.cache.template_cache:
class: Oksydan\IsImageslider\Cache\TemplateCache
public: true
Expand Down
24 changes: 22 additions & 2 deletions is_imageslider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
use Oksydan\IsImageslider\Hook\HookInterface;
use Oksydan\IsImageslider\Installer\ImageSliderInstaller;
use PrestaShop\PrestaShop\Adapter\SymfonyContainer;
use PrestaShop\PrestaShop\Core\Module\WidgetInterface;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;

class Is_imageslider extends Module
class Is_imageslider extends Module implements WidgetInterface
{
public $multistoreCompatibility = self::MULTISTORE_COMPATIBILITY_YES;

Expand All @@ -29,7 +30,7 @@ public function __construct()
* https://www.waynet.pl/
*/
$this->author = 'Igor Stępień';
$this->version = '2.2.0';
$this->version = '2.3.0';
$this->need_instance = 0;

$this->bootstrap = true;
Expand All @@ -40,6 +41,11 @@ public function __construct()
$this->ps_versions_compliancy = ['min' => '8.0.0', 'max' => _PS_VERSION_];
}

public function isUsingNewTranslationSystem(): bool
{
return true;
}

/**
* @return bool
*/
Expand Down Expand Up @@ -135,4 +141,18 @@ private function getHookObject($methodName)

return $hook instanceof HookInterface ? $hook : null;
}

public function renderWidget($hookName, array $configuration)
{
$widgetCapability = $this->get('oksydan.is_imageslider.hook.widget_capability');

return $widgetCapability->renderWidget($configuration);
}

public function getWidgetVariables($hookName, array $configuration)
{
$widgetCapability = $this->get('oksydan.is_imageslider.hook.widget_capability');

return $widgetCapability->getWidgetVariables($configuration);
}
}
8 changes: 4 additions & 4 deletions src/Entity/ImageSliderLang.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ public function setDescription(string $description): ImageSliderLang
}

/**
* @return string
* @return string|null
*/
public function getImage(): string
public function getImage(): ?string
{
return $this->image;
}
Expand All @@ -199,9 +199,9 @@ public function setImage(string $image): ImageSliderLang
}

/**
* @return string
* @return string|null
*/
public function getImageMobile(): string
public function getImageMobile(): ?string
{
return $this->imageMobile;
}
Expand Down
18 changes: 15 additions & 3 deletions src/Form/DataHandler/ImageSliderFormDataHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,12 @@ public function update($id, array $data): int
$langId = (int) $language['id_lang'];
$imageSliderLang = $imageSlide->getImageSliderLangByLangId($langId);

$newImageSliderLang = false;
if (null === $imageSliderLang) {
continue;
$imageSliderLang = new ImageSliderLang();
$lang = $this->langRepository->findOneById($langId);
$imageSliderLang->setLang($lang);
$newImageSliderLang = true;
}

$imageSliderLang
Expand All @@ -137,14 +141,22 @@ public function update($id, array $data): int
->setDescription($data['description'][$langId] ?? '');

if (!empty($data['image'][$langId])) {
$this->eraseFile($imageSliderLang->getImage());
if ($imageSliderLang->getImage() !== null) {
$this->eraseFile($imageSliderLang->getImage());
}
$imageSliderLang->setImage($this->uploadFile($data['image'][$langId]));
}

if (!empty($data['image_mobile'][$langId])) {
$this->eraseFile($imageSliderLang->getImageMobile());
if ($imageSliderLang->getImage() !== null) {
$this->eraseFile($imageSliderLang->getImageMobile());
}
$imageSliderLang->setImageMobile($this->uploadFile($data['image_mobile'][$langId]));
}

if ($newImageSliderLang) {
$imageSlide->addImageSliderLang($imageSliderLang);
}
}

$this->entityManager->flush();
Expand Down
61 changes: 61 additions & 0 deletions src/Hook/WidgetCapability.php
Original file line number Diff line number Diff line change
@@ -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);
}
}
6 changes: 3 additions & 3 deletions src/Installer/ImageSliderInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ public function createTables(): bool
->setData($databaseData)
->buildQuery();

return $createTableAction->execute() &&
$addColumnsAction->execute() &&
$modifyColumnsAction->execute();
return $createTableAction->execute()
&& $addColumnsAction->execute()
&& $modifyColumnsAction->execute();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Repository/ImageSliderRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function getHighestPosition(): int
$qb = $this
->createQueryBuilder('s')
->select('s.position')
->orderBy('s.position', 'ASC')
->orderBy('s.position', 'DESC')
->setMaxResults(1)
->getQuery();

Expand Down