Code Duplication    Length = 38-40 lines in 2 locations

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

@@ 119-156 (lines=38) @@
116
     * add application entry
117
     * @return mixed|\Zend\Http\Response|\Zend\View\Model\ViewModel
118
     */
119
    public function addAction()
120
    {
121
        $tmplVars = $this->getTemplateVars( 
122
            array(
123
            'showForm'    => true,
124
            )
125
        );
126
        
127
        $form = new ApplicationsForm();
128
        
129
        $clients = $this->getClientsTable()->fetchAll()->toArray();
130
        $valueoptions = array();
131
        foreach ($clients as $client) {
132
            $valueoptions[$client["clients_id"]] = $client["name"];
133
        }
134
        $form->get('client_id')->setValueOptions($valueoptions);
135
        
136
        $request = $this->getRequest();
137
        $applications = new Applications();
138
        if ($request->isPost()) {
139
            $form->setInputFilter($applications->getInputFilter());
140
            $form->setData($request->getPost());
141
142
            if ($form->isValid()) {
143
                $applications->exchangeArray($form->getData());
144
                $this->getApplicationsTable()->saveApplication($applications);
145
                $this->flashMessenger()->addSuccessMessage($this->translate('application has been saved'));
146
                if ( $this->isXHR() ) {
147
                    $tmplVars["showForm"] = false;
148
                } else {
149
                    return $this->redirect()->toRoute('admin/applicationsedit', array('action' => 'index'));
150
                }
151
            }
152
            $tmplVars["applications"] = $applications;
153
        }
154
        $tmplVars["form"] = $form;
155
        return new ViewModel($tmplVars);
156
    }
157
158
    /**
159
     * edit application entry

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

@@ 114-153 (lines=40) @@
111
     * add user entry
112
     * @return mixed|\Zend\Http\Response|\Zend\View\Model\ViewModel
113
     */
114
    public function addAction()
115
    {
116
        $tmplVars = $this->getTemplateVars(
117
            array(
118
                'showForm'    => true,
119
            )
120
        );
121
        $form = new UserForm();
122
123
        $roles = $this->getAclroleTable()->fetchAll()->toArray();
124
        $valueoptions = array();
125
        foreach ($roles as $role) {
126
            $valueoptions[$role["roleslug"]] = $role["rolename"];
127
        }
128
        /** @var \Zend\Form\Element\Select $aclroleSelect */
129
        $aclroleSelect = $form->get('aclrole');
130
        $aclroleSelect->setValueOptions($valueoptions);
131
132
        $request = $this->getRequest();
133
        $user = new User();
134
        if ($request->isPost()) {
135
            $form->setInputFilter($user->getInputFilter());
136
            $form->setData($request->getPost());
137
138
            if ($form->isValid()) {
139
                $user->exchangeArray($form->getData());
140
                $this->getUserTable()->saveUser($user);
141
                $this->flashMessenger()->addSuccessMessage($this->translate("user has been saved"));
142
                if ( $this->isXHR() ) {
143
                    $tmplVars["showForm"] = false;
144
                } else {
145
                    return $this->redirect()->toRoute('admin/default', array('controller' => 'users'));
146
                }
147
148
            }
149
            $tmplVars["user"] = $user;
150
        }
151
        $tmplVars["form"] = $form;
152
        return new ViewModel($tmplVars);
153
    }
154
155
    /**
156
     * edit user entry