Completed
Push — master ( b50753...137f43 )
by Florian
03:57
created

PersonStatusMapping::renderCellTemplate()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 17
Code Lines 13

Duplication

Lines 17
Ratio 100 %

Importance

Changes 0
Metric Value
dl 17
loc 17
c 0
b 0
f 0
rs 8.8571
cc 5
eloc 13
nc 3
nop 1
1
<?php
2
3
/**
4
 * PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU Lesser General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * PAYONE Magento 2 Connector is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU Lesser General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Lesser General Public License
15
 * along with PAYONE Magento 2 Connector. If not, see <http://www.gnu.org/licenses/>.
16
 *
17
 * PHP version 5
18
 *
19
 * @category  Payone
20
 * @package   Payone_Magento2_Plugin
21
 * @author    FATCHIP GmbH <[email protected]>
22
 * @copyright 2003 - 2016 Payone GmbH
23
 * @license   <http://www.gnu.org/licenses/> GNU Lesser General Public License
24
 * @link      http://www.payone.de
25
 */
26
27
namespace Payone\Core\Block\Adminhtml\Config\Form\Field;
28
29
/**
30
 * Block class for person-status-mapping grid-element
31
 */
32
class PersonStatusMapping extends \Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray
33
{
34
    /**
35
     * Element factory
36
     *
37
     * @var \Magento\Framework\Data\Form\Element\Factory
38
     */
39
    protected $elementFactory;
40
41
    /**
42
     * Person status source class
43
     *
44
     * @var \Payone\Core\Model\Source\PersonStatus
45
     */
46
    protected $personStatus;
47
48
    /**
49
     * Credit score source class
50
     *
51
     * @var \Payone\Core\Model\Source\CreditScore
52
     */
53
    protected $creditScore;
54
55
    /**
56
     * Constructor
57
     *
58
     * @param \Magento\Backend\Block\Template\Context      $context
59
     * @param \Magento\Framework\Data\Form\Element\Factory $elementFactory
60
     * @param \Payone\Core\Model\Source\PersonStatus       $personStatus
61
     * @param \Payone\Core\Model\Source\CreditScore        $creditScore
62
     * @param array                                        $data
63
     */
64
    public function __construct(
65
        \Magento\Backend\Block\Template\Context $context,
66
        \Magento\Framework\Data\Form\Element\Factory $elementFactory,
67
        \Payone\Core\Model\Source\PersonStatus $personStatus,
68
        \Payone\Core\Model\Source\CreditScore $creditScore,
69
        array $data = []
70
    ) {
71
        parent::__construct($context, $data);
72
        $this->elementFactory = $elementFactory;
73
        $this->personStatus = $personStatus;
74
        $this->creditScore = $creditScore;
75
    }
76
77
    /**
78
     * Initialise form fields
79
     *
80
     * @return void
81
     */
82
    protected function _construct()
83
    {
84
        $this->addColumn('personstatus', ['label' => __('Personstatus')]);
85
        $this->addColumn('score', ['label' => __('Score')]);
86
        $this->addAfter = false;
87
        $this->addButtonLabel = __('Add Personstatus Mapping');
88
        parent::_construct();
89
    }
90
91
    /**
92
     * Render array cell for prototypeJS template
93
     *
94
     * @param  string $columnName
95
     * @return string
96
     */
97 View Code Duplication
    public function renderCellTemplate($columnName)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
98
    {
99
        if ($columnName == 'personstatus' && isset($this->_columns[$columnName])) {
100
            $aOptions = $this->personStatus->toOptionArray();
101
        } elseif ($columnName == 'score' && isset($this->_columns[$columnName])) {
102
            $aOptions = $this->creditScore->toOptionArray();
103
        } else {
104
            return parent::renderCellTemplate($columnName);
105
        }
106
107
        $oElement = $this->elementFactory->create('select');
108
        $oElement->setForm($this->getForm());
109
        $oElement->setName($this->_getCellInputElementName($columnName));
110
        $oElement->setHtmlId($this->_getCellInputElementId('<%- _id %>', $columnName));
111
        $oElement->setValues($aOptions);
112
        return str_replace("\n", '', $oElement->getElementHtml());
113
    }
114
}
115