|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magefan ([email protected]). All rights reserved. |
| 4 | + * Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement). |
| 5 | + */ |
| 6 | + |
| 7 | +declare(strict_types=1); |
| 8 | + |
| 9 | +namespace Magefan\Community\Block\Adminhtml; |
| 10 | + |
| 11 | +use Magento\Backend\Block\Template; |
| 12 | +use Magento\Framework\App\ResourceConnection; |
| 13 | +use Magefan\Community\Model\SectionFactory; |
| 14 | + |
| 15 | +class Linv extends Template |
| 16 | +{ |
| 17 | + /** |
| 18 | + * @var ResourceConnection |
| 19 | + */ |
| 20 | + private $resource; |
| 21 | + |
| 22 | + /** |
| 23 | + * @var SectionFactory |
| 24 | + */ |
| 25 | + private $sectionFactory; |
| 26 | + |
| 27 | + /** |
| 28 | + * @param SectionFactory $sectionFactory |
| 29 | + * @param Template\Context $context |
| 30 | + * @param ResourceConnection $resource |
| 31 | + * @param array $data |
| 32 | + */ |
| 33 | + public function __construct( |
| 34 | + SectionFactory $sectionFactory, |
| 35 | + Template\Context $context, |
| 36 | + ResourceConnection $resource, |
| 37 | + array $data = [] |
| 38 | + ) { |
| 39 | + parent::__construct($context, $data); |
| 40 | + $this->sectionFactory = $sectionFactory; |
| 41 | + $this->resource = $resource; |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * @return array |
| 46 | + */ |
| 47 | + public function getItems() |
| 48 | + { |
| 49 | + $connection = $this->resource->getConnection(); |
| 50 | + $table = $this->resource->getTableName('core_config_data'); |
| 51 | + $path = '/g'.'en'.'er'.'al'.'/l'.'in'.'v'; |
| 52 | + $select = $connection->select() |
| 53 | + ->from([$table]) |
| 54 | + ->where( 'path LIKE ?', '%' . $path ) |
| 55 | + ->where('value = ?',1); |
| 56 | + $items = $connection->fetchAll($select); |
| 57 | + $result = []; |
| 58 | + |
| 59 | + foreach ($items as $config) { |
| 60 | + $configPath = explode('/', $config['path']); |
| 61 | + $moduleName = $configPath[0]; |
| 62 | + $section = $this->sectionFactory->create([ |
| 63 | + 'name' => $moduleName |
| 64 | + ]); |
| 65 | + $module = $section->getModule(true); |
| 66 | + if ($module) { |
| 67 | + $result[] = $module; |
| 68 | + } |
| 69 | + |
| 70 | + } |
| 71 | + return $result; |
| 72 | + } |
| 73 | +} |
0 commit comments