Ejemplo n.º 1
0
 public function edituserAction()
 {
     $id = $this->params('id');
     $get_user = $this->getUsersService()->getUser($id);
     foreach ($get_user as $usr) {
         $data = $usr;
     }
     //var_dump($data['country']);
     //exit;
     $form = new UsersForm($this->getServiceLocator()->get('Admin\\Model\\UsersModel'));
     // set the form fields with the values in the users table
     // based on the user id fetched
     $form->get('username')->setValue($data['username']);
     $form->get('password')->setValue($data['password']);
     $form->get('first_name')->setValue($data['first_name']);
     $form->get('last_name')->setValue($data['last_name']);
     $form->get('gender')->setValue($data['gender']);
     $form->get('address')->setValue($data['address']);
     $form->get('city')->setValue($data['city']);
     $form->get('state')->setValue($data['state']);
     $form->get('zipcode')->setValue($data['zipcode']);
     $form->get('country')->setValue($data['country']);
     $form->get('add_user_submit')->setValue('Edit User');
     $request = $this->getRequest();
     // check to see if the request was a POST form request
     if ($request->isPost()) {
         // good to go
         // filter the form values now
         $users = new Users();
         $form->setInputFilter($users->getInputFilter());
         // set the form data to hold all the values supplied by the form
         // via $request->getPost()
         $form->setData($request->getPost());
         // now we will see if the form is valid
         // we check if it is valid by the email form class we created
         if ($form->isValid()) {
             // it is valid
             // pass the form to data to the filter class via exchangeArray()
             $users->exchangeArray($form->getData());
             if ($this->getUsersService()->editUser($users, $id) === true) {
                 // the user was inserted into the database successfully
                 // redirect to users view
                 return $this->redirect()->toUrl('/admin/users');
             } else {
                 // error occured..
                 // the error is logged automatically
                 // redirect to add users view
                 return $this->redirect()->toUrl('/admin/edit-user/' . $id);
             }
         }
     }
     return new ViewModel(array('form' => $form, 'id' => $id));
 }
Ejemplo n.º 2
0
 public function editAction()
 {
     $id = (int) $this->params()->fromRoute('id', 0);
     if (!$id) {
         return $this->redirect()->toRoute('admin/users', array('action' => 'add'));
     }
     $user = $this->getUsersTable()->getUser($id);
     if ($user == false) {
         $this->flashMessenger()->addErrorMessage('User not found..!!');
         return $this->redirect()->toRoute('admin/users');
     }
     $vm = new ViewModel();
     $tableGateway = $this->getServiceLocator()->get('Admin\\Model\\UsertypeTable');
     $user_form = new UsersForm($tableGateway, $this->getServiceLocator()->get('Admin\\Model\\StatesTable'), $this->getServiceLocator()->get('Admin\\Model\\CountriesTable'), $this->getServiceLocator()->get('Admin\\Model\\StatusTable'), $this->getServiceLocator()->get('Admin\\Model\\ServiceLanguagesTable'), $this->getUsersTable()->getConsumerServiceLanguage($id, true), $user->country_id);
     //$form  = new UsersForm();
     $user_form->bind($user);
     $user_form->get('submit')->setAttribute('value', 'Edit');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $user->getInputFilter()->get('pass')->setRequired(false);
         if ($request->getPost('pass') == '') {
             $user->getInputFilter()->get('c_pass')->setRequired(false);
         }
         $user->getInputFilter()->get('user_name')->getValidatorChain()->attach(new \Zend\Validator\Db\NoRecordExists(array('table' => 'users', 'field' => 'user_name', 'adapter' => $this->getServiceLocator()->get('Zend\\Db\\Adapter\\Adapter'), 'exclude' => array('field' => 'id', 'value' => $id))));
         $user->getInputFilter()->get('email')->getValidatorChain()->attach(new \Zend\Validator\Db\NoRecordExists(array('table' => 'users', 'field' => 'email', 'adapter' => $this->getServiceLocator()->get('Zend\\Db\\Adapter\\Adapter'), 'exclude' => array('field' => 'id', 'value' => $id))));
         //echo '<pre>'; print_r($user->getInputFilter()->get('email')); exit;
         $user_form->setInputFilter($user->getInputFilter());
         $user_form->setData($request->getPost());
         if ($user_form->isValid()) {
             //echo '<pre>'; print_r($this->errors); exit;
             $this->getUsersTable()->saveUser($user_form->getData(), '', $request->getPost('service_language_id'));
             $this->flashMessenger()->addSuccessMessage('User updated successfully..!!');
             // Redirect to list of pages
             return $this->redirect()->toRoute('admin/users');
         } else {
             $this->errors = $user_form->getMessages();
         }
     }
     return array('id' => $id, 'errors' => $this->errors, 'user_form' => $user_form);
 }