Code Duplication    Length = 49-55 lines in 2 locations

module/Admin/src/Admin/Controller/ApplicationsController.php 1 location

@@ 162-216 (lines=55) @@
159
     * edit application entry
160
     * @return mixed|\Zend\Http\Response|\Zend\View\Model\ViewModel
161
     */
162
    public function editAction()
163
    {
164
        $tmplVars = $this->getTemplateVars( 
165
            array(
166
            'showForm'    => true,
167
            )
168
        );
169
        
170
        $id = (int) $this->params()->fromRoute('application_id', 0);
171
        if (!$id) {
172
            $this->flashMessenger()->addWarningMessage($this->translate("missing parameters"));
173
            return $this->redirect()->toRoute(
174
                'admin/applicationsedit', array(
175
                'action' => 'index'
176
                )
177
            );
178
        }
179
        try {
180
            $applications = $this->getApplicationsTable()->getApplication($id);
181
        } catch (\Exception $e) {
182
            $this->flashMessenger()->addWarningMessage($this->translate("invalid parameters"));
183
            return $this->redirect()->toRoute('admin/applicationsedit');
184
        }
185
186
        $form  = new ApplicationsForm();
187
        $form->bind($applications);
188
189
        $clients = $this->getClientsTable()->fetchAll()->toArray();
190
        $valueoptions = array();
191
        foreach ($clients as $client) {
192
            $valueoptions[$client["clients_id"]] = $client["name"];
193
        }
194
        $form->get('client_id')->setValueOptions($valueoptions);
195
        
196
        $request = $this->getRequest();
197
        if ($request->isPost()) {
198
            $form->setInputFilter($applications->getInputFilter());
199
            $form->setData($request->getPost());
200
201
            if ($form->isValid()) {
202
                $this->getApplicationsTable()->saveApplication($applications);
203
                $this->flashMessenger()->addSuccessMessage($this->translate("application has been saved"));
204
                if ( $this->isXHR() ) {
205
                    $tmplVars["showForm"] = false;
206
                } else {
207
                    return $this->redirect()->toRoute('admin/applicationsedit', array('action' => 'index'));
208
                }
209
            }
210
        } else {
211
            $form->bind($applications);
212
        }
213
        $tmplVars["application_id"] = $id;
214
        $tmplVars["form"] = $form;
215
        return new ViewModel($tmplVars);
216
    }
217
218
    /**
219
     * delete application entry

module/Admin/src/Admin/Controller/UsersController.php 1 location

@@ 159-207 (lines=49) @@
156
     * edit user entry
157
     * @return mixed|\Zend\Http\Response|\Zend\View\Model\ViewModel
158
     */
159
    public function editAction()
160
    {
161
        $tmplVars = $this->getTemplateVars(
162
            array(
163
                'showForm'    => true,
164
            )
165
        );
166
        $id = (int) $this->params()->fromRoute('user_id', 0);
167
        if (!$id) {
168
            $this->flashMessenger()->addWarningMessage($this->translate("missing parameters"));
169
            return $this->redirect()->toRoute('admin/default', array('controller' => 'users'));
170
        }
171
        try {
172
            $user = $this->getUserTable()->getUser($id);
173
        } catch (\Exception $e) {
174
            $this->flashMessenger()->addWarningMessage($this->translate("invalid parameters"));
175
            return $this->redirect()->toRoute('admin/default', array('controller' => 'users'));
176
        }
177
178
        $form    = new UserForm();
179
        $form->bind($user);
180
181
        $roles = $this->getAclroleTable()->fetchAll()->toArray();
182
        $valueoptions = array();
183
        foreach ($roles as $role) {
184
            $valueoptions[$role["roleslug"]] = $role["rolename"];
185
        }
186
        $form->get('aclrole')->setValueOptions($valueoptions);
187
188
        $request = $this->getRequest();
189
        if ($request->isPost()) {
190
            $form->setInputFilter($user->getInputFilter());
191
            $form->setData($request->getPost());
192
            if ($form->isValid()) {
193
                $this->getUserTable()->saveUser($user);
194
                $this->flashMessenger()->addSuccessMessage($this->translate("user has been saved"));
195
                if ( $this->isXHR() ) {
196
                    $tmplVars["showForm"] = false;
197
                } else {
198
                    return $this->redirect()->toRoute('admin/default', array('controller' => 'users'));
199
                }
200
            }
201
        } else {
202
            $form->bind($user);
203
        }
204
        $tmplVars["user_id"] = $id;
205
        $tmplVars["form"] = $form;
206
        return new ViewModel($tmplVars);
207
    }
208
209
    /**
210
     * delete user entry