forked from aitoc/magento-2-core
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Evgeni Obukhovsky
committed
Dec 12, 2019
1 parent
d0e5bee
commit d3522b1
Showing
50 changed files
with
2,963 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
<?php | ||
|
||
namespace Aitoc\Core\Block; | ||
|
||
use Magento\Framework\Data\Form\Element\AbstractElement; | ||
|
||
class InstalledExtensions extends \Magento\Config\Block\System\Config\Form\Fieldset | ||
{ | ||
const AITOC_UPDATE_EXTENSION_VERSION_LINK = 'https://www.aitoc.com/customer/account/login/'; | ||
const AITOC_PRODUCT_LINK_DEFAULT = 'https://www.aitoc.com/magento-2-extensions.html'; | ||
const AITOC_SUPPROT_LINK = 'https://www.aitoc.com/get-support.html'; | ||
|
||
/** | ||
* @var \Magento\Framework\Module\ModuleListInterface | ||
*/ | ||
protected $_moduleList; | ||
|
||
/** | ||
* @var \Magento\Framework\View\LayoutFactory | ||
*/ | ||
protected $_layoutFactory; | ||
|
||
/** | ||
* @var \Aitoc\Core\Helper\Extensions | ||
*/ | ||
private $extensionsHelper; | ||
|
||
public function __construct( | ||
\Magento\Backend\Block\Context $context, | ||
\Magento\Backend\Model\Auth\Session $authSession, | ||
\Magento\Framework\View\Helper\Js $jsHelper, | ||
\Magento\Framework\Module\ModuleListInterface $moduleList, | ||
\Magento\Framework\View\LayoutFactory $layoutFactory, | ||
\Aitoc\Core\Helper\Extensions $extensionsHelper, | ||
array $data = [] | ||
) { | ||
parent::__construct($context, $authSession, $jsHelper, $data); | ||
|
||
$this->_moduleList = $moduleList; | ||
$this->_layoutFactory = $layoutFactory; | ||
$this->extensionsHelper = $extensionsHelper; | ||
$this->_scopeConfig = $context->getScopeConfig(); | ||
} | ||
|
||
/** | ||
* Render fieldset html | ||
* | ||
* @param AbstractElement $element | ||
* @return string | ||
*/ | ||
public function render(AbstractElement $element) | ||
{ | ||
$html = $this->_getHeaderHtml($element); | ||
|
||
$modules = $this->extensionsHelper->getAitocExtensions(true); | ||
|
||
if ($modules) { | ||
foreach ($modules as $ext) { | ||
$html .= $this->getRenderExtensionLine($ext); | ||
} | ||
} | ||
|
||
$html .= $this->_getFooterHtml($element); | ||
|
||
return $html; | ||
} | ||
|
||
/** | ||
* Return footer html for fieldset | ||
* Add extra tooltip comments to elements | ||
* | ||
* @param AbstractElement $element | ||
* @return string | ||
*/ | ||
protected function _getFooterHtml($element) | ||
{ | ||
$html = '</tbody></table>'; | ||
|
||
$html .= $this->addCommentToHtml(); | ||
|
||
foreach ($element->getElements() as $field) { | ||
if ($field->getTooltip()) { | ||
$html .= sprintf( | ||
'<div id="row_%s_comment" class="system-tooltip-box" style="display:none;">%s</div>', | ||
$field->getId(), | ||
$field->getTooltip() | ||
); | ||
} | ||
} | ||
$html .= '</fieldset>' . $this->_getExtraJs($element); | ||
|
||
if ($element->getIsNested()) { | ||
$html .= '</td></tr>'; | ||
} else { | ||
$html .= '</div>'; | ||
} | ||
return $html; | ||
} | ||
|
||
/** | ||
* @param $fieldset | ||
* @param $moduleCode | ||
* @return string | ||
*/ | ||
private function getRenderExtensionLine($extName) | ||
{ | ||
$extensionsEnabled = $this->extensionsHelper->isModuleEnabled($extName); | ||
$resultHtml = ''; | ||
$extInfo = $this->extensionsHelper->getExtInfo($extName); | ||
$packageData = []; | ||
$versionOld = false; | ||
$productUrl = self::AITOC_UPDATE_EXTENSION_VERSION_LINK; | ||
|
||
if (!is_array($extInfo) || | ||
!array_key_exists('version', $extInfo) || | ||
!array_key_exists('description', $extInfo) || | ||
!array_key_exists('name', $extInfo) | ||
) { | ||
return ''; | ||
} | ||
|
||
$allExtensionsData = $this->extensionsHelper->getAllExtensions(); | ||
if (isset($allExtensionsData[$extInfo['name']])) { | ||
$packageData = $allExtensionsData[$extInfo['name']]; | ||
|
||
if ($packageData && isset($packageData['version'])) { | ||
$versionOld = $this->extensionsHelper | ||
->compareExtensionComposerVersions($packageData['version'], $extInfo['version']); | ||
|
||
if (isset($packageData['product_url']) && $packageData['product_url']) { | ||
$productUrl = $packageData['product_url']; | ||
} | ||
} | ||
} | ||
|
||
$resultHtml .= '<tr id="aitoc_core_' . strtolower($extName) . '"><td class="label"><label for="aitoc_core_' . | ||
strtolower($extName) . '"><span><a href="' . $productUrl . '" target="_blank">' | ||
. str_replace('extension', '', str_replace('by Aitoc', '', $extInfo['description'])) | ||
. '</a> (' . ($extensionsEnabled ? __('Enabled') : __('Disabled')) . ')</span></label></td>'; | ||
$resultHtml .= '<td class="value">' | ||
. $extInfo['version'] . ' ' | ||
. '<b>' . | ||
($versionOld ? | ||
__("(New version %1 is available in your account: ", $packageData['version']) | ||
. '<a class="aitoc-button-get-new-version" href="' | ||
. self::AITOC_UPDATE_EXTENSION_VERSION_LINK . | ||
'" target="_blank">' . __('Get Update') . '</a> )' : '' ) | ||
. '</b></td>'; | ||
|
||
return $resultHtml . '</tr>'; | ||
} | ||
|
||
/** | ||
* @param $html | ||
* @return string | ||
*/ | ||
private function addCommentToHtml() | ||
{ | ||
$html = '<div class="comment aitoc-support">'; | ||
$html .= 'Have any issues with <b>Aitoc extensions</b>?' . | ||
' Please <a href="' . self::AITOC_SUPPROT_LINK | ||
. '" class="aitoc-get-support-button" target="_blank">Contact Support</a>'; | ||
|
||
return $html . '</div>'; | ||
} | ||
|
||
/** | ||
* @return \Magento\Framework\View\Element\BlockInterface | ||
*/ | ||
protected function _getFieldRenderer() | ||
{ | ||
if (empty($this->_fieldRenderer)) { | ||
$layout = $this->_layoutFactory->create(); | ||
|
||
$this->_fieldRenderer = $layout->createBlock( | ||
\Magento\Config\Block\System\Config\Form\Field::class | ||
); | ||
} | ||
|
||
return $this->_fieldRenderer; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace Aitoc\Core\Block; | ||
|
||
/** | ||
* Class Shopfeed | ||
* @package Aitoc\Core\Block | ||
*/ | ||
class Shopfeed extends \Magento\Config\Block\System\Config\Form\Fieldset | ||
{ | ||
/** | ||
* Render text | ||
* | ||
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element | ||
* @return string | ||
* @throws \Magento\Framework\Exception\LocalizedException | ||
*/ | ||
public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element) | ||
{ | ||
$html = $this->_getHeaderHtml($element); | ||
$html .= $this->_getFooterHtml($element); | ||
|
||
return $html; | ||
} | ||
|
||
/** | ||
* Return element html | ||
* | ||
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element | ||
* @return string | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element) | ||
{ | ||
return $this->_toHtml(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace Aitoc\Core\Block\System\Config\Form\Field; | ||
|
||
use Magento\Framework\Data\Form\Element\AbstractElement; | ||
use Magento\Framework\Stdlib\DateTime\DateTimeFormatterInterface; | ||
|
||
/** | ||
* Backend system config datetime field renderer | ||
*/ | ||
class Notification extends \Magento\Config\Block\System\Config\Form\Field | ||
{ | ||
/** | ||
* @var DateTimeFormatterInterface | ||
*/ | ||
protected $dateTimeFormatter; | ||
|
||
/** | ||
* @param \Magento\Backend\Block\Template\Context $context | ||
* @param DateTimeFormatterInterface $dateTimeFormatter | ||
* @param array $data | ||
*/ | ||
public function __construct( | ||
\Magento\Backend\Block\Template\Context $context, | ||
DateTimeFormatterInterface $dateTimeFormatter, | ||
array $data = [] | ||
) { | ||
parent::__construct($context, $data); | ||
$this->dateTimeFormatter = $dateTimeFormatter; | ||
} | ||
|
||
/** | ||
* @param AbstractElement $element | ||
* @return string | ||
*/ | ||
protected function _getElementHtml(AbstractElement $element) | ||
{ | ||
$element->setValue($this->_cache->load(\Aitoc\Core\Model\Feed::AITOC_CACHE_NAME)); | ||
$format = $this->_localeDate->getDateTimeFormat( | ||
\IntlDateFormatter::MEDIUM | ||
); | ||
return $this->dateTimeFormatter->formatObject($this->_localeDate->date(intval($element->getValue())), $format); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<?php | ||
|
||
namespace Aitoc\Core\Components\Model\ResourceModel; | ||
|
||
use Magento\Framework\Api\ExtensibleDataInterface; | ||
use Magento\Framework\Api\Search\AggregationInterface; | ||
use Magento\Framework\Api\Search\DocumentInterface; | ||
use Magento\Framework\Api\SearchCriteriaInterface; | ||
|
||
trait GridCollectionTrait | ||
{ | ||
/** | ||
* @var AggregationInterface | ||
*/ | ||
private $aggregations; | ||
|
||
/** | ||
* Retrieve all ids for collection | ||
* Backward compatibility with EAV collection | ||
* | ||
* @param int $limit | ||
* @param int $offset | ||
* @return array | ||
*/ | ||
public function getAllIds($limit = null, $offset = null) | ||
{ | ||
return $this->getConnection()->fetchCol($this->_getAllIdsSelect($limit, $offset), $this->_bindParams); | ||
} | ||
|
||
/** | ||
* @return AggregationInterface | ||
*/ | ||
public function getAggregations() | ||
{ | ||
return $this->aggregations; | ||
} | ||
|
||
/** | ||
* @param AggregationInterface $aggregations | ||
* @return $this | ||
*/ | ||
public function setAggregations($aggregations) | ||
{ | ||
$this->aggregations = $aggregations; | ||
} | ||
|
||
/** | ||
* Get search criteria. | ||
* | ||
* @return SearchCriteriaInterface|null | ||
*/ | ||
public function getSearchCriteria() | ||
{ | ||
return null; | ||
} | ||
|
||
/** | ||
* Set search criteria. | ||
* | ||
* @param SearchCriteriaInterface $searchCriteria | ||
* @return $this | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function setSearchCriteria(SearchCriteriaInterface $searchCriteria = null) | ||
{ | ||
return $this; | ||
} | ||
|
||
/** | ||
* Get total count. | ||
* | ||
* @return int | ||
*/ | ||
public function getTotalCount() | ||
{ | ||
return $this->getSize(); | ||
} | ||
|
||
/** | ||
* Set total count. | ||
* | ||
* @param int $totalCount | ||
* @return $this | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function setTotalCount($totalCount) | ||
{ | ||
return $this; | ||
} | ||
|
||
/** | ||
* Set items list. | ||
* | ||
* @param ExtensibleDataInterface[] $items | ||
* @return $this | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function setItems(array $items = null) | ||
{ | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return DocumentInterface[] | ||
*/ | ||
public function getItems() | ||
{ | ||
return $this; | ||
} | ||
} |
Oops, something went wrong.