Exemplo n.º 1
0
 public function addAction()
 {
     $form = new ConsumersForm($this->getServiceLocator()->get('Admin\\Model\\UsertypeTable'), $this->getServiceLocator()->get('Admin\\Model\\StatesTable'), $this->getServiceLocator()->get('Admin\\Model\\CountriesTable'), $this->getServiceLocator()->get('Admin\\Model\\StatusTable'), $this->getServiceLocator()->get('Admin\\Model\\ServiceLanguagesTable'));
     $form->get('submit')->setValue('Add');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $consumers = new Users();
         $consumers->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'))));
         $consumers->getInputFilter()->get('email')->getValidatorChain()->attach(new \Zend\Validator\Db\NoRecordExists(array('table' => 'users', 'field' => 'email', 'adapter' => $this->getServiceLocator()->get('Zend\\Db\\Adapter\\Adapter'))));
         $form->setInputFilter($consumers->getInputFilter());
         $request->getPost()->user_type_id = '4';
         // set user type to consumer
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $consumers->exchangeArray($form->getData());
             $this->getconsumersTable()->saveUser($consumers, '', $request->getPost('service_language_id'));
             $this->flashMessenger()->addSuccessMessage('Consumer added successfully..!!');
             // Redirect to list of pages
             return $this->redirect()->toRoute('admin/consumers');
         }
     }
     return array('form' => $form);
 }
Exemplo n.º 2
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));
 }