public function indexAction() { $userForm = new Application_Form_User(); if ($this->getRequest()->isPost()) { if ($userForm->isValid($_POST)) { $user = new Application_Model_User(); $this->userRepository->populate($user, $userForm->getValues()); $this->userRepository->create($user); $this->userRepository->flush(); $userForm->reset(); } } $this->view->users = $this->userRepository->findAll(); $this->view->userForm = $userForm; }
public function myProfileAction() { $usersNs = new Zend_Session_Namespace("members"); $model = new Security_Model_User(); $user = $model->find($usersNs->userId); if (false === $user) { $this->_flashMessenger->addMessage(array('error' => 'Invalid request!')); $this->_helper->_redirector->gotoUrl($this->view->seoUrl('/admin/dashboard')); } $form = new Application_Form_User(); $elements = $form->getElements(); foreach ($elements as $element) { if ($element->getId() != "profilePicture" && $element->getId() != "submit") { $form->removeElement($element->getId()); } } $this->view->form = $form; $request = $this->getRequest(); if ($request->isPost()) { $options = $request->getPost(); if ($form->isValid($options)) { $user->uploadProfilePicture($usersNs->userId, $options); $this->_flashMessenger->addMessage(array('success' => 'Profile picture has been uploaded successfully!')); $this->_helper->_redirector->gotoUrl($this->view->seoUrl('/user/my-profile')); } else { $this->_flashMessenger->addMessage(array('error' => 'Unable to upload the profile picture!')); $form->reset(); } } $this->view->user = $user; }
public function editEmployeeAction() { $id = $this->_getParam('id'); $this->view->user_id = $id; $model1 = new Application_Model_User(); $model = $model1->find($id); if (false === $model) { $this->_flashMessenger->addMessage(array('error' => 'Invalid request! Please try again.')); $this->_helper->_redirector->gotoUrl($this->view->seoUrl('/hr/employees')); } $options['firstName'] = $model->getFirstName(); $options['middleName'] = $model->getMiddleName(); $options['lastName'] = $model->getLastName(); $options['email'] = $model->getEmail(); $options['dob'] = $model->getDob(); $options['doj'] = $model->getDoj(); $options['pan'] = $model->getPan(); $options['employeeCode'] = $model->getEmployeeCode(); $options['contactNo'] = $model->getContactNo(); $options['extensionNo'] = $model->getExtensionNo(); $options['skype'] = $model->getSkype(); $options['sex'] = $model->getSex(); $options['mobile'] = $model->getMobile(); $options['fatherName'] = $model->getFatherName(); $options['marriageAnniversary'] = $model->getMarriageAnniversary(); $options['designationId'] = $model->getDesignationId(); $options['departmentId'] = $model->getDepartmentId(); $options['userLevelId'] = $model->getUserLevelId(); $options['correspondenceAddress'] = $model->getCorrespondenceAddress(); $this->view->username = $model->getUsername(); $request = $this->getRequest(); $form = new Application_Form_User(); //remove fields do not need to display in Edit //$form->removeElement('employeeCode'); //$form->getElement('employeeCode')->setAttrib("readonly", "true"); $form->removeElement('username'); $form->removeElement('password'); $form->removeElement('confirmPassword'); $form->populate($options); $options = $request->getPost(); if ($request->isPost()) { /*---- email validation ----*/ if ($options['email'] != $model->getEmail()) { $form->getElement('email')->addValidators(array(array('Db_NoRecordExists', false, array('table' => 'user', 'field' => 'email', 'messages' => 'Email already exists, Please choose another email address.')))); } if ($options['employeeCode'] == $model->getEmployeeCode()) { $form->getElement('employeeCode')->removeValidator("Db_NoRecordExists"); } /*-------------------------*/ if ($form->isValid($options)) { $model->setOptions($options); $model->save(); /*--------- Upload image START -------------------------*/ $model->uploadProfilePicture($id, $options); /*--------- Upload image END -------------------------*/ $this->_flashMessenger->addMessage(array('success' => 'Employee information has been updated successfully!')); $this->_helper->_redirector->gotoUrl($this->view->seoUrl('/hr/edit-employee/id/' . $id)); } else { $this->_flashMessenger->addMessage(array('error' => 'Unable to save the data. Please provide valid inputs and try again.')); $form->reset(); $form->populate($options); } } $this->view->profile_image = $model->getProfileImage(); $this->view->form = $form; }