Code Duplication    Length = 34-35 lines in 2 locations

application/modules/comments/comments_widgets.php 2 locations

@@ 85-119 (lines=35) @@
82
     * @param string $action
83
     * @param array $widget_data
84
     */
85
    public function recent_comments_configure($action = 'show_settings', array $widget_data = []) {
86
        if ($this->dx_auth->is_admin() == FALSE) {
87
            exit; // Only admin access
88
        }
89
        switch ($action) {
90
            case 'show_settings':
91
                assetManager::create()->setData('widget', $widget_data)->renderAdmin('recent_comments_form');
92
                break;
93
94
            case 'update_settings':
95
                $this->form_validation->set_rules('comments_count', lang('Number of comments', 'comments'), 'trim|required|is_natural_no_zero|min_length[1]');
96
                $this->form_validation->set_rules('symbols_count', lang('Number of characters', 'comments'), 'required|trim|is_natural');
97
98
                if ($this->form_validation->run($this) == FALSE) {
99
                    showMessage(validation_errors());
100
                } else {
101
                    $data = [
102
                             'comments_count' => $this->input->post('comments_count'),
103
                             'symbols_count'  => $this->input->post('symbols_count'),
104
                            ];
105
106
                    $this->load->module('admin/widgets_manager')->update_config($widget_data['id'], $data);
107
                    showMessage(lang('Settings have been saved', 'comments'));
108
                    if ($this->input->post('action') == 'tomain') {
109
                        pjax('/admin/widgets_manager/index');
110
                    }
111
                }
112
                break;
113
114
            case 'install_defaults':
115
                $this->load->module('admin/widgets_manager')->update_config($widget_data['id'], $this->defaults);
116
                break;
117
        }
118
    }
119
120
    /**
121
     * Get and display recent product comments
122
     * @param array $widget
@@ 171-204 (lines=34) @@
168
     * @param string $action
169
     * @param array $widget_data
170
     */
171
    public function recent_product_comments_configure($action = 'show_settings', array $widget_data = []) {
172
        if ($this->dx_auth->is_admin() == FALSE) {
173
            exit; // Only admin access
174
        }
175
        switch ($action) {
176
            case 'show_settings':
177
                assetManager::create()->setData('widget', $widget_data)->renderAdmin('recent_product_comments_form');
178
                break;
179
180
            case 'update_settings':
181
                $this->form_validation->set_rules('comments_count', lang('Number of responses'), 'trim|required|is_natural_no_zero|min_length[1]');
182
                $this->form_validation->set_rules('symbols_count', lang('Number of characters'), 'required|trim|is_natural');
183
184
                if ($this->form_validation->run($this) == FALSE) {
185
                    showMessage(validation_errors());
186
                } else {
187
                    $data = [
188
                             'comments_count' => $this->input->post('comments_count'),
189
                             'symbols_count'  => $this->input->post('symbols_count'),
190
                            ];
191
192
                    $this->load->module('admin/widgets_manager')->update_config($widget_data['id'], $data);
193
                    showMessage(lang('Settings have been saved', 'comments'));
194
                    if ($this->input->post('action') == 'tomain') {
195
                        pjax('/admin/widgets_manager/index');
196
                    }
197
                }
198
                break;
199
200
            case 'install_defaults':
201
                $this->load->module('admin/widgets_manager')->update_config($widget_data['id'], $this->defaults);
202
                break;
203
        }
204
    }
205
206
}