Skip to content

Commit

Permalink
Merge pull request #139 from JaroslawZielinski/feature/138-widget-wit…
Browse files Browse the repository at this point in the history
…h-static-selected-verse-tweak

task #138: Widget with Static Selected Verse Tweak
  • Loading branch information
JaroslawZielinski authored Jan 31, 2025
2 parents 4dc291c + 265f1c2 commit f89496c
Show file tree
Hide file tree
Showing 9 changed files with 239 additions and 4 deletions.
30 changes: 30 additions & 0 deletions Block/Widget/Email/Static/Random.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace JaroslawZielinski\TorahVerse\Block\Widget\Email\Static;

class Random extends \JaroslawZielinski\TorahVerse\Block\Widget\Static\Random
{
/**
* @inheritDoc
*/
protected function _construct(): void
{
parent::_construct();
$this->setTemplate('JaroslawZielinski_TorahVerse::widget/email/slider.phtml');
}

/**
* {@inheritDoc}
* @throws \Exception
*/
public function getConfig(): array
{
$config = parent::getConfig();
$items = $config['items'] ?? [];
$randomItemIndex = rand(0, count($items) - 1);
$config['items'] = [$items[$randomItemIndex]];
return $config;
}
}
47 changes: 47 additions & 0 deletions Block/Widget/Email/Static/Selected.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

namespace JaroslawZielinski\TorahVerse\Block\Widget\Email\Static;

/**
* @method setLanguage(string $language): self
* @method getEn(): string
* @method getPl(): string
*/
class Selected extends \JaroslawZielinski\TorahVerse\Block\Widget\Static\Selected
{
/**
* @inheritDoc
*/
protected function _construct(): void
{
parent::_construct();
$this->setTemplate('JaroslawZielinski_TorahVerse::widget/email/slider.phtml');
}

/**
* @inheritDoc
*/
public function getItems(array $groupsArray = []): array
{
$language = explode('_', $this->config->getStoreLocale());
$lang = $language[0];
$siglum = $this->getSiglum();
switch ($lang) {
default:
case 'en':
$translation = $this->getEn();
$this->setLanguage('en');
break;
case 'pl':
$translation = $this->getPl();
$this->setLanguage('pl');
break;
}
$siglumParts = explode('/', $siglum);
$siglumParts[0] = $translation;
$this->setSiglum(implode('/', $siglumParts));
return parent::getItems($groupsArray);
}
}
20 changes: 20 additions & 0 deletions Block/Widget/Slider/Custom.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,24 @@ public function getItems(array $groupsArray = []): array
$groupsArray = $this->config->getCustomSlider($this->getCode());
return parent::getItems($groupsArray);
}

/**
*/
public function getItemFlatHtml(array $config): string
{
$item = reset($config['items']);
if (!!$config['is_group_colours']) {
$html = $item['group_colours_template'];
} else {
$html = $item['template'];
}
$data = array_merge($item['data'], [
'textColour' => $config['text_colour'],
'content' => sprintf(
'"%s"',
!!$config['verses_ordered'] ? $item['data']['content'] : $item['data']['unordered']
)
]);
return Data::replaceMe($html, $data);
}
}
9 changes: 5 additions & 4 deletions Block/Widget/Static/Selected.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@
use Psr\Log\LoggerInterface;

/**
* @method string getSiglum()
* @method string getGroupName()
* @method string getColorValue()
* @method string getLanguage()
* @method getSiglum(): string
* @method setSiglum(string $siglum): self
* @method getGroupName(): string
* @method getColorValue(): string
* @method getLanguage(): string
*/
class Selected extends Custom
{
Expand Down
9 changes: 9 additions & 0 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,13 @@ public static function escapeQuotes(?string $input): ?string
}
return str_replace(['\''], ['`'], $input);
}

public static function replaceMe (string $html, array $data): string
{
$result = $html;
foreach ($data as $key => $value) {
$result = str_replace('{' . $key . '}', (string)$value, $result);
}
return $result;
}
}
8 changes: 8 additions & 0 deletions Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ class Config

public const CONFIG_PATH_TORAHINPUT_RESULTS_PER_PAGE = 'jaroslawzielinski_torah/torah_input/results_per_page';

public const PATH_STORE_LOCALE = 'general/locale/code';

/**
* @var ScopeConfigInterface
*/
Expand Down Expand Up @@ -538,4 +540,10 @@ public function getTorahInputResultsPerPage(): string
return (string)$this->scopeConfig
->getValue(self::CONFIG_PATH_TORAHINPUT_RESULTS_PER_PAGE, ScopeInterface::SCOPE_STORE);
}

public function getStoreLocale(): ?string
{
$storeLocale = $this->scopeConfig->getValue(self::PATH_STORE_LOCALE, ScopeInterface::SCOPE_STORE);
return empty($storeLocale) ? null : (string)$storeLocale;
}
}
40 changes: 40 additions & 0 deletions Model/Config/Source/Sliders/Frontend.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

namespace JaroslawZielinski\TorahVerse\Model\Config\Source\Sliders;

use Magento\Eav\Model\Entity\Attribute\Source\AbstractSource;
use Magento\Framework\Data\OptionSourceInterface;

class Frontend extends AbstractSource implements OptionSourceInterface
{
public const FRONTEND = 'frontend';

public const FRONTEND_OPTIONS = [
self::FRONTEND => [
'label' => 'Frontend',
'value' => self::FRONTEND
]
];

public function getOptions(): array
{
$options = [];
foreach (self::FRONTEND_OPTIONS as $value => $option) {
$options[] = ['label' => __($option['label']), 'value' => $value];
}
return $options;
}

/**
* @inheritDoc
*/
public function getAllOptions(): ?array
{
if (empty($this->_options)) {
$this->_options = $this->getOptions();
}
return $this->_options;
}
}
58 changes: 58 additions & 0 deletions etc/widget.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,62 @@
</parameter>
</parameters>
</widget>

<widget class="JaroslawZielinski\TorahVerse\Block\Widget\Email\Static\Random" id="flat_static_random">
<label>Torah Verse Flat Static Random</label>

<description>Flat Static Torah Verse Random</description>

<parameters>
<parameter name="area" xsi:type="select"
source_model="JaroslawZielinski\TorahVerse\Model\Config\Source\Sliders\Frontend" required="true"
sort_order="10">
<label translate="true">Area</label>
</parameter>

<parameter name="code" xsi:type="select"
source_model="JaroslawZielinski\TorahVerse\Model\Config\Source\Sliders\Codes" sort_order="20">
<label translate="true">Code</label>
</parameter>
</parameters>
</widget>

<widget class="JaroslawZielinski\TorahVerse\Block\Widget\Email\Static\Selected" id="flat_static_selected">
<label>Torah Verse Flat Static Selected</label>

<description>Flat Static Torah Verse Selected</description>

<parameters>
<parameter name="area" xsi:type="select"
source_model="JaroslawZielinski\TorahVerse\Model\Config\Source\Sliders\Frontend" required="true"
sort_order="10">
<label translate="true">Area</label>
</parameter>

<parameter name="siglum" xsi:type="text" sort_order="20">
<label translate="true">Siglum</label>
<value>bw/ro/10/9</value>
</parameter>

<parameter name="en" xsi:type="text" sort_order="30">
<label translate="true">English Translation</label>
<value>kjv</value>
</parameter>

<parameter name="pl" xsi:type="text" sort_order="40">
<label translate="true">Polish Translation</label>
<value>bw</value>
</parameter>

<parameter name="group_name" xsi:type="text" sort_order="50">
<label translate="true">Group Name</label>
<value>Test</value>
</parameter>

<parameter name="color_value" xsi:type="text" sort_order="60">
<label translate="true">Color Value</label>
<value>#5020df</value>
</parameter>
</parameters>
</widget>
</widgets>
22 changes: 22 additions & 0 deletions view/frontend/templates/widget/email/slider.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/** @var \JaroslawZielinski\TorahVerse\Block\Widget\Email\Static\Random|\JaroslawZielinski\TorahVerse\Block\Widget\Email\Static\Selected $block */
$config = $block->getConfig();
$customStyles = trim($block->getModuleCustomStyles() ?? '');
$backgroundHoverColour = $block->getBackgroundHoverColour() ?? 'none';
?>
<?php if ($block->isVisible()): ?>
<?php if (!empty($customStyles)): ?>
<style type="text/css">
/* <![CDATA[ */
.verse-slider.paused-slider {
background-color: <?= $backgroundHoverColour; ?>;
}
<?= $customStyles; ?>
.verse-slider .slider, .verse-slider .item { height: auto; }
/* ]]> */
</style>
<?php endif; ?>
<div class="verse-slider">
<?= $block->getItemFlatHtml($config); ?>
</div>
<?php endif; ?>

0 comments on commit f89496c

Please sign in to comment.