Skip to content

Commit

Permalink
Merge pull request #71 from JaroslawZielinski/feature/torahverse-input
Browse files Browse the repository at this point in the history
TorahVerse Input
  • Loading branch information
JaroslawZielinski authored May 11, 2023
2 parents 87697c0 + b454487 commit f7840d9
Show file tree
Hide file tree
Showing 27 changed files with 440 additions and 509 deletions.
42 changes: 42 additions & 0 deletions Block/Search.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace JaroslawZielinski\TorahVerse\Block;

use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;
use JaroslawZielinski\TorahVerse\Model\Config\Source\Verses\Translation as TranslationOptions;

class Search extends Template
{
/**
* @var TranslationOptions
*/
private $translationOptions;
/**
* @inheritDoc
*/
public function __construct(
TranslationOptions $translationOptions,
Context $context,
array $data = []
) {
$this->translationOptions = $translationOptions;
parent::__construct($context, $data);
}

/**
* @inheritDoc
*/
protected function _construct()
{
$this->setTemplate('JaroslawZielinski_TorahVerse::search.phtml');
parent::_construct();
}

public function getTranslations(): array
{
return $this->translationOptions->toOptionArray();
}
}
77 changes: 77 additions & 0 deletions Block/Siglum/Info.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

declare(strict_types=1);

namespace JaroslawZielinski\TorahVerse\Block\Siglum;

use JaroslawZielinski\Torah\Translations\Resources;
use JaroslawZielinski\TorahVerse\Model\Config;
use Magento\Backend\Block\Template\Context;
use Magento\Directory\Helper\Data as DirectoryHelper;
use Magento\Framework\Json\Helper\Data as JsonHelper;
use Magento\Framework\View\Element\Template;

class Info extends Template
{
/**
* @var Config
*/
private $config;
/**
* @inheritDoc
*/
public function __construct(
Config $config,
Context $context,
array $data = [],
?JsonHelper $jsonHelper = null,
?DirectoryHelper $directoryHelper = null
) {
$this->config = $config;
parent::__construct($context, $data, $jsonHelper, $directoryHelper);
}

/**
* @inheritDoc
*/
protected function _construct()
{
$this->setTemplate('JaroslawZielinski_TorahVerse::siglum/info.phtml');
parent::_construct();
}

public function getBooksInfo(string $part = 'Tanakh'): array
{
$results = [];
$language = $this->config->getInternalizationLanguage();
array_filter(Resources::TORAH_BOOKS_EXTENDED[$part], function ($value, $key) use (&$results, $language) {
$results[$key] = $value[$language];
}, ARRAY_FILTER_USE_BOTH);
return $results;
}

private function pickBooks(array $rows, int $key, string $part): array
{
$books = $this->getBooksInfo($part);
$count = 0;
foreach ($books as $code => $book) {
$rows[$count][$key] = [$code => $book];
$count++;
}
return $rows;
}

public function getBooksRows(): array
{
$rows = [];
foreach ($this->getTorahParts() as $key => $part) {
$rows = $this->pickBooks($rows, $key, $part);
}
return $rows;
}

public function getTorahParts(): array
{
return array_keys(Resources::TORAH_BOOKS_EXTENDED);
}
}
36 changes: 36 additions & 0 deletions Controller/Siglum/Search.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace JaroslawZielinski\TorahVerse\Controller\Siglum;

use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
use Magento\Framework\View\Result\PageFactory;

class Search extends Action
{
/**
* @var PageFactory
*/
private $resultPageFactory;

/**
* @inheritDoc
*/
public function __construct(
PageFactory $resultPageFactory,
Context $context
) {
$this->resultPageFactory = $resultPageFactory;
parent::__construct($context);
}

/**
* @inheritDoc
*/
public function execute()
{
return $this->resultPageFactory->create();
}
}
16 changes: 15 additions & 1 deletion Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ class Config
public const CONFIG_PATH_CUSTOM_TEXT_COLOUR = 'jaroslawzielinski_torahverse/custom_sliders/text_colour';
public const CONFIG_PATH_CUSTOM_MODE = 'jaroslawzielinski_torahverse/custom_sliders/mode';
public const CONFIG_PATH_CUSTOM_SLIDERS = 'jaroslawzielinski_torahverse/custom_sliders/sliders';
public const CONFIG_PATH_INTERNALIZATION_LANGUAGE = 'jaroslawzielinski_torahverse/internalization/language';
public const CONFIG_PATH_INTERNALIZATION_LANGUAGE = 'jaroslawzielinski_torah/internalization/language';
public const CONFIG_PATH_TORAHINPUT_DIVISION = 'jaroslawzielinski_torah/torah_input/division';
public const CONFIG_PATH_TORAHINPUT_FRONTENDENABLED = 'jaroslawzielinski_torah/torah_input/frontend_enabled';

/**
* @var ScopeConfigInterface
Expand Down Expand Up @@ -416,4 +418,16 @@ public function getInternalizationLanguage(): string
return (string)$this->scopeConfig
->getValue(self::CONFIG_PATH_INTERNALIZATION_LANGUAGE, ScopeInterface::SCOPE_STORE);
}

public function getTorahInputDivision(): string
{
return (string)$this->scopeConfig
->getValue(self::CONFIG_PATH_TORAHINPUT_DIVISION, ScopeInterface::SCOPE_STORE);
}

public function isTorahInputFrontendEnabled(): bool
{
return $this->scopeConfig
->isSetFlag(self::CONFIG_PATH_TORAHINPUT_FRONTENDENABLED, ScopeInterface::SCOPE_STORE);
}
}
38 changes: 38 additions & 0 deletions Model/Config/Source/Verses/Division.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

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

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

class Division extends AbstractSource implements OptionSourceInterface
{
public const MODE = [
'two-division' => 'Old Testamen/New Testament',
'three-division' => 'Tanakh/Nevi\'im ketuvim/Brithadasha'
];

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

/**
* @inheritDoc
*/
public function getAllOptions(): ?array
{
if (empty($this->_options)) {
$this->_options = $this->getOptions();
}
return $this->_options;
}
}
2 changes: 1 addition & 1 deletion Model/ResourceModel/AbstractUninstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
abstract class AbstractUninstall extends AbstractDb
{
protected const UNINSTALL_DATA = [
'core_config_data' => 'DELETE FROM %s WHERE path LIKE "&jaroslawzielinski_torahverse&";',
'core_config_data' => 'DELETE FROM %s WHERE path LIKE "&jaroslawzielinski_torah&";',
'layout_update' => 'DELETE FROM %s WHERE xml LIKE "&TorahVerse&";',
'patch_list' => 'DELETE FROM %s WHERE patch_name LIKE "&TorahVerse&";',
'torahverse_quotes' => 'DROP table %s;',
Expand Down
4 changes: 4 additions & 0 deletions Plugin/Backend/Model/Menu/BuilderPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public function afterGetResult(Builder $subject, Menu $result): Menu
{
if (!$this->config->isModuleMenuEnabled()) {
$result->remove('JaroslawZielinski_TorahVerse::menu');
} else {
if (!$this->config->isTorahInputFrontendEnabled()) {
$result->remove('JaroslawZielinski_TorahVerse::versesearch');
}
}
return $result;
}
Expand Down
30 changes: 30 additions & 0 deletions Plugin/Backend/Model/Menu/ItemPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace JaroslawZielinski\TorahVerse\Plugin\Backend\Model\Menu;

use Magento\Backend\Model\Menu\Item;
use Magento\Framework\UrlInterface;

class ItemPlugin
{
/**
* @var UrlInterface
*/
private $frontUrlModel;

public function __construct(UrlInterface $frontUrlModel)
{
$this->frontUrlModel = $frontUrlModel;
}

public function afterGetUrl(Item $subject, $result)
{
$info = $subject->toArray();
if ('JaroslawZielinski_TorahVerse::versesearch' === $info['resource']) {
return $this->frontUrlModel->getUrl($info['action']);
}
return $result;
}
}
25 changes: 17 additions & 8 deletions etc/acl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,21 @@
<resources>
<resource id="Magento_Backend::admin">
<resource id="JaroslawZielinski_TorahVerse::menu" title="TorahVerse Menu">
<resource id="JaroslawZielinski_TorahVerse::torahverse" title="JaroslawZielinski TorahVerse">
<resource id="JaroslawZielinski_TorahVerse::groups" title="JaroslawZielinski TorahVerse Groups"/>
<resource id="JaroslawZielinski_TorahVerse::verses" title="JaroslawZielinski TorahVerse Verses"/>
<resource id="JaroslawZielinski_TorahVerse::quotes" title="JaroslawZielinski TorahVerse Quotes"/>
<resource id="JaroslawZielinski_TorahVerse::config"
title="JaroslawZielinski TorahVerse Configuration Menu" translate="title" />
<resource id="JaroslawZielinski_TorahVerse::grids" title="TorahVerse Grids">
<resource id="JaroslawZielinski_TorahVerse::groups" title="TorahVerse Groups"/>
<resource id="JaroslawZielinski_TorahVerse::verses" title="TorahVerse Verses"/>
<resource id="JaroslawZielinski_TorahVerse::quotes" title="TorahVerse Quotes"/>
</resource>

<resource id="JaroslawZielinski_TorahVerse::settings" title="TorahVerse Settings"
translate="title">
<resource id="JaroslawZielinski_TorahVerse::configuration"
title="TorahVerse Configuration" translate="title" />
</resource>

<resource id="JaroslawZielinski_TorahVerse::search" title="TorahVerse Search"
translate="title">
<resource id="JaroslawZielinski_TorahVerse::versesearch" title="TorahVerse Verse Search" />
</resource>
</resource>

Expand All @@ -22,8 +31,8 @@
<resource id="Magento_Backend::stores">
<resource id="Magento_Backend::stores_settings">
<resource id="Magento_Config::config">
<resource id="JaroslawZielinski_TorahVerse::configuration"
title="JaroslawZielinski TorahVerse Configuration" translate="title" />
<resource id="JaroslawZielinski_Torah::configuration"
title="Torah Configuration" translate="title" />
</resource>
</resource>
</resource>
Expand Down
12 changes: 12 additions & 0 deletions etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,16 @@
</argument>
</arguments>
</type>

<type name="JaroslawZielinski\TorahVerse\Plugin\Backend\Model\Menu\ItemPlugin">
<arguments>
<!-- force Frontend Url -->
<argument name="frontUrlModel" xsi:type="object" shared="false">Magento\Framework\Url</argument>
</arguments>
</type>

<type name="Magento\Backend\Model\Menu\Item">
<plugin name="add-frontend-verse-search-in-admin-menu"
type="JaroslawZielinski\TorahVerse\Plugin\Backend\Model\Menu\ItemPlugin" sortOrder="20" disabled="false" />
</type>
</config>
21 changes: 15 additions & 6 deletions etc/adminhtml/menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,41 @@
<add id="JaroslawZielinski_TorahVerse::menu" resource="JaroslawZielinski_TorahVerse::menu" title="Torah Verse"
module="JaroslawZielinski_TorahVerse" sortOrder="10"/>

<add id="JaroslawZielinski_TorahVerse::torahverse" resource="JaroslawZielinski_TorahVerse::torahverse"
<add id="JaroslawZielinski_TorahVerse::grids" resource="JaroslawZielinski_TorahVerse::grids"
title="Grids" translate="title" module="JaroslawZielinski_TorahVerse"
parent="JaroslawZielinski_TorahVerse::menu" sortOrder="10"/>

<add id="JaroslawZielinski_TorahVerse::groups" resource="JaroslawZielinski_TorahVerse::groups"
title="Groups" action="torahverse/groups/index"
module="JaroslawZielinski_TorahVerse" sortOrder="30" parent="JaroslawZielinski_TorahVerse::torahverse"
module="JaroslawZielinski_TorahVerse" sortOrder="30" parent="JaroslawZielinski_TorahVerse::grids"
dependsOnModule="JaroslawZielinski_TorahVerse"/>

<add id="JaroslawZielinski_TorahVerse::verses" resource="JaroslawZielinski_TorahVerse::verses"
title="Groups/Verses" action="torahverse/verses/index"
module="JaroslawZielinski_TorahVerse" sortOrder="40" parent="JaroslawZielinski_TorahVerse::torahverse"
module="JaroslawZielinski_TorahVerse" sortOrder="40" parent="JaroslawZielinski_TorahVerse::grids"
dependsOnModule="JaroslawZielinski_TorahVerse"/>

<add id="JaroslawZielinski_TorahVerse::quotes" resource="JaroslawZielinski_TorahVerse::quotes"
title="Groups/Quotes" action="torahverse/quotes/index"
module="JaroslawZielinski_TorahVerse" sortOrder="50" parent="JaroslawZielinski_TorahVerse::torahverse"
module="JaroslawZielinski_TorahVerse" sortOrder="50" parent="JaroslawZielinski_TorahVerse::grids"
dependsOnModule="JaroslawZielinski_TorahVerse"/>

<add id="JaroslawZielinski_TorahVerse::config" resource="JaroslawZielinski_TorahVerse::config"
<add id="JaroslawZielinski_TorahVerse::settings" resource="JaroslawZielinski_TorahVerse::settings"
title="Settings" translate="title" module="JaroslawZielinski_TorahVerse"
parent="JaroslawZielinski_TorahVerse::menu" sortOrder="20"/>

<add id="JaroslawZielinski_TorahVerse::configuration" resource="JaroslawZielinski_TorahVerse::configuration"
title="Configuration" action="adminhtml/system_config/edit/section/jaroslawzielinski_torahverse"
module="JaroslawZielinski_TorahVerse" sortOrder="50" parent="JaroslawZielinski_TorahVerse::config"
module="JaroslawZielinski_TorahVerse" sortOrder="50" parent="JaroslawZielinski_TorahVerse::settings"
dependsOnModule="JaroslawZielinski_TorahVerse"/>

<add id="JaroslawZielinski_TorahVerse::search" resource="JaroslawZielinski_TorahVerse::search"
title="Search" translate="title" module="JaroslawZielinski_TorahVerse"
parent="JaroslawZielinski_TorahVerse::menu" sortOrder="30"/>

<add id="JaroslawZielinski_TorahVerse::versesearch" resource="JaroslawZielinski_TorahVerse::versesearch"
title="Verse Search" action="torahverse/siglum/search"
module="JaroslawZielinski_TorahVerse" sortOrder="10" parent="JaroslawZielinski_TorahVerse::search"
target="_blank" dependsOnModule="JaroslawZielinski_TorahVerse"/>
</menu>
</config>
Loading

0 comments on commit f7840d9

Please sign in to comment.