ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Elastic Search Base for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\ElasticSearch\Block\Adminhtml\Form\Field;
|
||||
|
||||
/**
|
||||
* @method array|null getFulltextAttributes()
|
||||
* @method Attribute setFulltextAttributes(array $attributes)
|
||||
*/
|
||||
class Attribute extends \Magento\Framework\View\Element\Text
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function _toHtml()
|
||||
{
|
||||
$this->setText('');
|
||||
foreach (array_keys($this->getFulltextAttributes()) as $attributeCode) {
|
||||
$this->addText('<%= option_extra_attrs.option_' . self::calcOptionHash($attributeCode) . ' %>');
|
||||
}
|
||||
|
||||
return parent::_toHtml();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $optionValue
|
||||
* @return string
|
||||
*/
|
||||
public function calcOptionHash($optionValue)
|
||||
{
|
||||
return sprintf('%u', crc32($this->getData('name') . $this->getData('id') . $optionValue));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
* @return $this
|
||||
*/
|
||||
public function setInputName($value)
|
||||
{
|
||||
return $this->setData('name', $value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Elastic Search Base for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\ElasticSearch\Block\Adminhtml\Form\Field;
|
||||
|
||||
class Combining extends \Magento\Framework\View\Element\Html\Select
|
||||
{
|
||||
/**
|
||||
* @var \Amasty\ElasticSearch\Model\Source\CombiningType
|
||||
*/
|
||||
private $source;
|
||||
|
||||
public function __construct(
|
||||
\Magento\Framework\View\Element\Context $context,
|
||||
\Amasty\ElasticSearch\Model\Source\CombiningType $source,
|
||||
array $data = []
|
||||
) {
|
||||
parent::__construct($context, $data);
|
||||
$this->source = $source;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @return $this
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
public function setInputName($value)
|
||||
{
|
||||
return $this->setName($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function _toHtml()
|
||||
{
|
||||
if (!$this->getOptions()) {
|
||||
$this->setOptions($this->source->toOptionArray());
|
||||
}
|
||||
|
||||
return parent::_toHtml();
|
||||
}
|
||||
}
|
||||
+168
@@ -0,0 +1,168 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Elastic Search Base for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\ElasticSearch\Block\Adminhtml\Form\Field;
|
||||
|
||||
use Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray;
|
||||
use Amasty\ElasticSearch\Model\Config\QuerySettings as BackendModel;
|
||||
|
||||
class QuerySettings extends AbstractFieldArray
|
||||
{
|
||||
public const STYLE = 'style="width:90px"';
|
||||
|
||||
/**
|
||||
* @var null|Attribute
|
||||
*/
|
||||
private $attributeRenderer;
|
||||
|
||||
/**
|
||||
* @var null|YesNo
|
||||
*/
|
||||
private $wildcardRenderer;
|
||||
|
||||
/**
|
||||
* @var null|YesNo
|
||||
*/
|
||||
private $spellCorrectionRenderer;
|
||||
|
||||
/**
|
||||
* @var null|Combining
|
||||
*/
|
||||
private $combiningRenderer;
|
||||
|
||||
/**
|
||||
* @var \Amasty\ElasticSearch\Model\Source\FulltextAttributes
|
||||
*/
|
||||
private $fulltextAttributesSource;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function _construct()
|
||||
{
|
||||
parent::_construct();
|
||||
$this->fulltextAttributesSource = $this->getData('fulltext_attributes');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Attribute|null
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
private function getAttributeRenderer()
|
||||
{
|
||||
if (!$this->attributeRenderer) {
|
||||
$this->attributeRenderer = $this->getLayout()->createBlock(
|
||||
Attribute::class,
|
||||
'',
|
||||
['data' => ['is_render_to_js_template' => true]]
|
||||
);
|
||||
$this->attributeRenderer
|
||||
->setFulltextAttributes($this->fulltextAttributesSource->toArray())
|
||||
->setExtraParams(self::STYLE);
|
||||
}
|
||||
|
||||
return $this->attributeRenderer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return YesNo|null
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
private function getWildcardRenderer()
|
||||
{
|
||||
if (!$this->wildcardRenderer) {
|
||||
$this->wildcardRenderer = $this->getLayout()->createBlock(
|
||||
YesNo::class,
|
||||
'',
|
||||
['data' => ['is_render_to_js_template' => true]]
|
||||
);
|
||||
$this->wildcardRenderer->setExtraParams(self::STYLE);
|
||||
}
|
||||
|
||||
return $this->wildcardRenderer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return YesNo|null
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
private function getSpellCorrectionRenderer()
|
||||
{
|
||||
if (!$this->spellCorrectionRenderer) {
|
||||
$this->spellCorrectionRenderer = $this->getLayout()->createBlock(
|
||||
YesNo::class,
|
||||
'',
|
||||
['data' => ['is_render_to_js_template' => true]]
|
||||
);
|
||||
$this->spellCorrectionRenderer->setExtraParams(self::STYLE);
|
||||
}
|
||||
|
||||
return $this->spellCorrectionRenderer;
|
||||
}
|
||||
/**
|
||||
* @return YesNo|null
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
private function getCombiningRenderer()
|
||||
{
|
||||
if (!$this->combiningRenderer) {
|
||||
$this->combiningRenderer = $this->getLayout()->createBlock(
|
||||
Combining::class,
|
||||
'',
|
||||
['data' => ['is_render_to_js_template' => true]]
|
||||
);
|
||||
$this->combiningRenderer->setExtraParams(self::STYLE);
|
||||
}
|
||||
|
||||
return $this->combiningRenderer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function _prepareToRender()
|
||||
{
|
||||
$this->setTemplate('system/config/array.phtml');
|
||||
$this->addColumn(
|
||||
BackendModel::ATTRIBUTE,
|
||||
['label' => __('Attribute'), 'renderer' => $this->getAttributeRenderer()]
|
||||
);
|
||||
$this->addColumn(
|
||||
BackendModel::WILDCARD,
|
||||
['label' => __('Wildcard'), 'renderer' => $this->getWildcardRenderer()]
|
||||
);
|
||||
$this->addColumn(
|
||||
BackendModel::SPELLING,
|
||||
['label' => __('Spell Correction'), 'renderer' => $this->getSpellCorrectionRenderer()]
|
||||
);
|
||||
$this->addColumn(
|
||||
BackendModel::COMBINING,
|
||||
['label' => __('Match Mode'), 'renderer' => $this->getCombiningRenderer()]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function _prepareArrayRow(\Magento\Framework\DataObject $row)
|
||||
{
|
||||
$optionId = $this->getAttributeRenderer()->calcOptionHash($row->getData(BackendModel::ATTRIBUTE));
|
||||
$value = $this->fulltextAttributesSource->toArray()[$row->getData(BackendModel::ATTRIBUTE)];
|
||||
$optionExtraAttr['option_'. $optionId] = $value;
|
||||
|
||||
$optionId = $this->getWildcardRenderer()->calcOptionHash($row->getData(BackendModel::WILDCARD));
|
||||
$optionExtraAttr['option_'. $optionId] = ' checked ';
|
||||
|
||||
$optionId = $this->getSpellCorrectionRenderer()->calcOptionHash($row->getData(BackendModel::SPELLING));
|
||||
$optionExtraAttr['option_'. $optionId] = ' checked ';
|
||||
|
||||
$optionId = $this->getCombiningRenderer()->calcOptionHash($row->getData(BackendModel::COMBINING));
|
||||
$optionExtraAttr['option_'. $optionId] = 'selected="selected"';
|
||||
|
||||
$row->setData('option_extra_attrs', $optionExtraAttr);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package Elastic Search Base for Magento 2
|
||||
*/
|
||||
|
||||
namespace Amasty\ElasticSearch\Block\Adminhtml\Form\Field;
|
||||
|
||||
use Magento\Framework\View\Element\Context;
|
||||
use Magento\Framework\View\Element\Html\Select;
|
||||
|
||||
class YesNo extends Select
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Config\Model\Config\Source\Yesno
|
||||
*/
|
||||
private $source;
|
||||
|
||||
public function __construct(
|
||||
Context $context,
|
||||
\Magento\Config\Model\Config\Source\Yesno $source,
|
||||
array $data = []
|
||||
) {
|
||||
parent::__construct($context, $data);
|
||||
$this->source = $source;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @return $this
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
public function setInputName($value)
|
||||
{
|
||||
return $this->setName($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function _toHtml()
|
||||
{
|
||||
if (!$this->getOptions()) {
|
||||
$this->setOptions($this->source->toOptionArray());
|
||||
}
|
||||
|
||||
if (!$this->_beforeToHtml()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$html = '<div name="' . $this->getName() . '" class="admin__actions-switch ' . $this->getClass() . '">';
|
||||
$selectedHtml = ' <%= option_extra_attrs.option_' . self::calcOptionHash('1') . ' %>';
|
||||
$html .= ' <input id="' . $this->getName() . '" type="checkbox" class="admin__actions-switch-checkbox input-'
|
||||
. $this->getColumnName() . '" ' . $selectedHtml . '" name="' . $this->getName() . '"/>' .
|
||||
'<label class="admin__actions-switch-label ' . $this->getColumnName() . '" for="' . $this->getName()
|
||||
. '" style="width: 70px;">' .
|
||||
'<span class="admin__actions-switch-text" data-text-on="'. __('Yes'). '" data-text-off="' . __('No')
|
||||
. '"></span></label>';
|
||||
$html .= '</div>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user