Skip to content
This repository was archived by the owner on Aug 15, 2024. It is now read-only.

Commit dcb41ed

Browse files
authored
Merge pull request #132 from blopa/develop
develop
2 parents 866d94a + a87fa13 commit dcb41ed

File tree

21 files changed

+633
-67
lines changed

21 files changed

+633
-67
lines changed
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
<?php
2+
/**
3+
* Magento Chatbot Integration
4+
* Copyright (C) 2017
5+
*
6+
* This file is part of Werules/Chatbot.
7+
*
8+
* Werules/Chatbot is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
*/
21+
22+
namespace Werules\Chatbot\Block\Adminhtml\System\Config\Form\Field;
23+
24+
class DefaultReplies extends \Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray
25+
{
26+
/**
27+
* @var \Magento\Framework\Data\Form\Element\Factory
28+
*/
29+
protected $_elementFactory;
30+
protected $_itemRendererMatchCase;
31+
protected $_itemRendererMatchMode;
32+
protected $_itemRendererEnable;
33+
34+
/**
35+
* @param \Magento\Backend\Block\Template\Context $context
36+
* @param \Magento\Framework\Data\Form\Element\Factory $elementFactory
37+
* @param array $data
38+
*/
39+
public function __construct(
40+
\Magento\Backend\Block\Template\Context $context,
41+
\Magento\Framework\Data\Form\Element\Factory $elementFactory,
42+
array $data = array()
43+
)
44+
{
45+
$this->_elementFactory = $elementFactory;
46+
parent::__construct($context,$data);
47+
}
48+
protected function _construct()
49+
{
50+
$this->addColumn('enable_reply', array(
51+
'label' => __("Enable"),
52+
'renderer' => $this->_getRendererEnable()
53+
));
54+
// $this->addColumn('stop_processing', array(
55+
// 'label' => __("Stop Processing"),
56+
// 'renderer' => $this->_getRendererEnable()
57+
// ));
58+
$this->addColumn('match_mode', array(
59+
'label' => __("Match Mode"),
60+
'renderer' => $this->_getRendererMatchMode()
61+
));
62+
$this->addColumn('match_sintax', array(
63+
'label' => __("Match Text or Regex"),
64+
//'style' => 'width: 100%',
65+
'class' => 'validate-no-html-tags'
66+
));
67+
$this->addColumn('match_case', array(
68+
'label' => __("Match Case"),
69+
'renderer' => $this->_getRendererMatchCase()
70+
));
71+
$this->addColumn('reply_text', array(
72+
'label' => __("Reply Text"),
73+
//'style' => 'width: 100%',
74+
'class' => 'validate-no-html-tags'
75+
));
76+
77+
$this->_addAfter = false;
78+
$this->_addButtonLabel = __("Add");
79+
parent::_construct();
80+
}
81+
82+
protected function _getRendererYesNo()
83+
{
84+
return $this->getLayout()->createBlock(
85+
'Werules\Chatbot\Block\Adminhtml\System\Config\Options\YesNo',
86+
'',
87+
array('data' => array('is_render_to_js_template' => true))
88+
// array('is_render_to_js_template' => true)
89+
); // ->setExtraParams('style="width: 100%;"');
90+
}
91+
92+
protected function _getRendererEnable()
93+
{
94+
if (!$this->_itemRendererEnable)
95+
{
96+
$this->_itemRendererEnable = $this->_getRendererYesNo();
97+
}
98+
return $this->_itemRendererEnable;
99+
}
100+
101+
protected function _getRendererMatchCase()
102+
{
103+
if (!$this->_itemRendererMatchCase)
104+
{
105+
$this->_itemRendererMatchCase = $this->_getRendererYesNo();
106+
}
107+
return $this->_itemRendererMatchCase;
108+
}
109+
110+
protected function _getRendererMatchMode()
111+
{
112+
if (!$this->_itemRendererMatchMode)
113+
{
114+
$this->_itemRendererMatchMode = $this->getLayout()->createBlock(
115+
'Werules\Chatbot\Block\Adminhtml\System\Config\Form\Field\MatchModeSelect',
116+
'',
117+
array('data' => array('is_render_to_js_template' => true))
118+
// array('is_render_to_js_template' => true)
119+
); // ->setExtraParams('style="width: 100%;"');
120+
}
121+
return $this->_itemRendererMatchMode;
122+
}
123+
124+
protected function _prepareArrayRow(\Magento\Framework\DataObject $row)
125+
{
126+
$optionExtraAttr = array();
127+
$optionExtraAttr['option_' . $this->_getRendererEnable()->calcOptionHash($row->getData('enable_reply'))] = 'selected="selected"';
128+
$optionExtraAttr['option_' . $this->_getRendererMatchMode()->calcOptionHash($row->getData('match_mode'))] = 'selected="selected"';
129+
$optionExtraAttr['option_' . $this->_getRendererMatchCase()->calcOptionHash($row->getData('match_case'))] = 'selected="selected"';
130+
131+
$row->setData(
132+
'option_extra_attrs', $optionExtraAttr
133+
);
134+
}
135+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/**
3+
* Magento Chatbot Integration
4+
* Copyright (C) 2017
5+
*
6+
* This file is part of Werules/Chatbot.
7+
*
8+
* Werules/Chatbot is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
*/
21+
22+
namespace Werules\Chatbot\Block\Adminhtml\System\Config\Form\Field;
23+
24+
class MatchModeList implements \Magento\Framework\Option\ArrayInterface
25+
{
26+
/**
27+
* Provide available options as a value/label array
28+
*
29+
* @return array
30+
*/
31+
public function toOptionArray()
32+
{
33+
return array(
34+
array('value' => 0, 'label' => __("Equals to")),
35+
array('value' => 1, 'label' => __("Starts With")),
36+
array('value' => 2, 'label' => __("Ends With")),
37+
array('value' => 3, 'label' => __("Contains")),
38+
array('value' => 4, 'label' => __("Match RegEx"))
39+
);
40+
}
41+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/**
3+
* Magento Chatbot Integration
4+
* Copyright (C) 2017
5+
*
6+
* This file is part of Werules/Chatbot.
7+
*
8+
* Werules/Chatbot is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
*/
21+
22+
namespace Werules\Chatbot\Block\Adminhtml\System\Config\Form\Field;
23+
24+
class MatchModeSelect extends \Magento\Framework\View\Element\Html\Select
25+
{
26+
/**
27+
* @var \Werules\Chatbot\Block\Adminhtml\System\Config\Form\Field\MatchModeList
28+
*/
29+
protected $_matchModeList;
30+
31+
public function __construct(
32+
\Werules\Chatbot\Block\Adminhtml\System\Config\Form\Field\MatchModeList $MatchModeList,
33+
\Magento\Backend\Block\Template\Context $context, array $data = array())
34+
{
35+
parent::__construct($context, $data);
36+
$this->_matchModeList = $MatchModeList;
37+
}
38+
39+
public function _toHtml()
40+
{
41+
if (!$this->getOptions()) {
42+
foreach ($this->_matchModeList->toOptionArray() as $option) {
43+
$this->addOption($option['value'], $option['label']);
44+
}
45+
}
46+
return parent::_toHtml();
47+
}
48+
49+
public function getName()
50+
{
51+
return $this->getInputName();
52+
}
53+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
/**
3+
* Magento Chatbot Integration
4+
* Copyright (C) 2017
5+
*
6+
* This file is part of Werules/Chatbot.
7+
*
8+
* Werules/Chatbot is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
*/
21+
22+
namespace Werules\Chatbot\Block\Adminhtml\System\Config\Form\Field;
23+
24+
class WelcomeOptions extends \Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray
25+
{
26+
/**
27+
* @var \Magento\Framework\Data\Form\Element\Factory
28+
*/
29+
protected $_elementFactory;
30+
protected $_itemRendererEnable;
31+
32+
/**
33+
* @param \Magento\Backend\Block\Template\Context $context
34+
* @param \Magento\Framework\Data\Form\Element\Factory $elementFactory
35+
* @param array $data
36+
*/
37+
public function __construct(
38+
\Magento\Backend\Block\Template\Context $context,
39+
\Magento\Framework\Data\Form\Element\Factory $elementFactory,
40+
array $data = array()
41+
)
42+
{
43+
$this->_elementFactory = $elementFactory;
44+
parent::__construct($context,$data);
45+
}
46+
protected function _construct()
47+
{
48+
$this->addColumn('enable_option', array(
49+
'label' => __("Enable"),
50+
'renderer' => $this->_getRendererEnable()
51+
));
52+
$this->addColumn('option_text', array(
53+
'label' => __("Option Text"),
54+
//'style' => 'width: 100%',
55+
'class' => 'validate-no-html-tags'
56+
));
57+
58+
$this->_addAfter = false;
59+
$this->_addButtonLabel = __("Add");
60+
parent::_construct();
61+
}
62+
63+
protected function _getRendererYesNo()
64+
{
65+
return $this->getLayout()->createBlock(
66+
'Werules\Chatbot\Block\Adminhtml\System\Config\Options\YesNo',
67+
'',
68+
array('data' => array('is_render_to_js_template' => true))
69+
// array('is_render_to_js_template' => true)
70+
); // ->setExtraParams('style="width: 100%;"');
71+
}
72+
73+
protected function _getRendererEnable()
74+
{
75+
if (!$this->_itemRendererEnable)
76+
{
77+
$this->_itemRendererEnable = $this->_getRendererYesNo();
78+
}
79+
return $this->_itemRendererEnable;
80+
}
81+
82+
protected function _prepareArrayRow(\Magento\Framework\DataObject $row)
83+
{
84+
$optionExtraAttr = array();
85+
$optionExtraAttr['option_' . $this->_getRendererEnable()->calcOptionHash($row->getData('enable_option'))] = 'selected="selected"';
86+
87+
$row->setData(
88+
'option_extra_attrs', $optionExtraAttr
89+
);
90+
}
91+
}

0 commit comments

Comments
 (0)