public function indexAction() { $form = new Application_Form_Profile(); $form->setMethod('POST'); $form->setDefaultsFromEntity($this->user); $request = $this->getRequest(); if ($request->isPost() && $form->isValid($request->getPost())) { $values = $form->getValues(); try { if (!empty($values['image'])) { $imageInfo = array_pop($form->image->getFileInfo()); $values['image'] = $this->_helper->service('image')->save($imageInfo); } $this->service->save($values, $this->user); $this->_helper->redirector('index'); } catch (\InvalidArgumentException $e) { switch ($e->getMessage()) { case 'username_conflict': $form->username->addError($this->view->translate("User with given username exists.")); break; default: $form->image->addError($e->getMessage()); break; } } } $this->view->user_first_name = $this->user->getFirstName(); $this->view->user_last_name = $this->user->getLastName(); $this->view->user_email = $this->user->getEmail(); $this->view->form = $form; $this->view->user = new MetaUser($this->user); $this->view->first_time = $this->_getParam('first', false); }
public function indexAction() { // display the profile form and populate if profile exists $request = $this->getRequest(); $form = new Application_Form_Profile(); $auth = Zend_Auth::getInstance(); $identity = $auth->getIdentity(); $profileMapper = new Application_Model_ProfileMapper(); $profile = new Application_Model_Profile(); $exists = $profileMapper->exists($identity->id); if ($request->isPost()) { if ($form->isValid($request->getPost())) { $profile->setOptions($form->getValues()); $profile->setUserId($identity->id); $profileMapper->save($profile, $exists); // display success message $this->view->msg = "<p class='msg'>Profile saved</p>"; } } else { $profileMapper->find($identity->id, $profile); $data = array('first_name' => $profile->getFirstName(), 'last_name' => $profile->getLastName(), 'birthdate' => date_format(new DateTime($profile->getBirthdate()), 'Y-m-d'), 'gender' => $profile->getGender()); $form->populate($data); } $this->view->form = $form; }
public function testBindFromProfileWillPopulateDataFromProfileEntity() { $profileRaw = ['id' => 1, 'fullname' => "Trinh Thanh Tam", 'dob' => '2018-06-18', 'email' => '*****@*****.**']; $profile = new Application_Model_Profile(['data' => $profileRaw]); $this->form->bindFromProfile($profile); $this->assertEquals($profileRaw, $this->form->getValues()); }
private function _initForm() { if ($this->form === null) { $this->form = new Application_Form_Profile(); $this->form->setAction($this->_helper->url('save', 'profiles')); // i need to create an array of audio and video codecs and device types } return $this->form; }
/** * Edit existed profile * * Handler GET, POST request * @link GET /profile/edit/:id display form profile populated * @link POST /profile/edit persit profile * */ public function editAction() { $profileRepoFactory = new Application_Factory_ProfileRepository(); $profileModelFactory = new Application_Factory_ProfileModel(); $profileForm = new Application_Form_Profile(['id' => 'edit-profile']); $profileForm->submit->setLabel("Save"); $profileRepo = $profileRepoFactory->createService(); $this->view->profileForm = $profileForm; //GET request handler $visitEditProfilePage = !$this->getRequest()->isPost(); if ($visitEditProfilePage) { $profileId = (int) $this->getParam('id', 0); $profileEntity = $profileRepo->findById($profileId); $profileForm->bindFromProfile($profileEntity); return; //render edit profile form } //POST request handler $postInvalidProfile = !$profileForm->isValid($this->getRequest()->getPost()); if ($postInvalidProfile) { return; //represent profile form with error messages } //Persit filtered profile to persistent $profileRepo->save($profileModelFactory->createService($profileForm->getValues())); $this->_helper->redirector('index', 'profile', 'default'); }
/** * Edit profile */ public function editAction() { $Profiles = new Application_Model_Profiles(); $this->buildMenu(); $profile_form = new Application_Form_Profile(); $this->view->profile_form = $profile_form; $request = $this->getRequest(); if ($request->isPost() && $profile_form->isValid($_POST)) { Application_Plugin_Common::redirectOnDemoAccount(); $profile = $Profiles->getProfileRow(); // do not foreach this! $profile->screen_name = $profile_form->getValue('screen_name'); $profile->profile_privacy = $profile_form->getValue('profile_privacy'); $profile->save(); $ProfilesMeta = new Application_Model_ProfilesMeta(); $elements = $profile_form->getElements(); $system_elements = array('identifier', 'formsubmit', 'profile_privacy', 'screen_name', 'csrf', 'name', 'email', 'id'); // foreach meta elements foreach ($elements as $element) { $element_id = $element->getId(); $element_value = $element->getValue(); // skip system & readonly fields if (in_array($element_id, $system_elements)) { continue; } // custom date element? if ($element->helper == 'formDate') { if ($element_value) { $dateval = date("Y-m-d H:i:s", strtotime($element_value['day'] . '-' . $element_value['month'] . '-' . $element_value['year'])); $ProfilesMeta->metaUpdate($element_id, $dateval, $profile->id); } else { $ProfilesMeta->deleteProfilesMetaKey($profile->id, $element_id); } continue; } $ProfilesMeta->metaUpdate($element_id, $element_value, $profile->id); } Application_Plugin_Alerts::success($this->view->translate('Profile updated')); // refresh user session Zend_Auth::getInstance()->getStorage()->write($Profiles->getProfileRowObject()); // flush url $this->redirect('editprofile/edit'); } }
public function editAction() { $authorization = Zend_Auth::getInstance(); $identity = $authorization->getIdentity(); if ($identity) { $form = new Application_Form_Profile(); $model = new Application_Model_Users(); $id = $this->getRequest()->getParam('id'); $user_data = $model->getUserById($id); $form->populate($user_data); // $form->getElement('password')->setValue($user_data[0]['password']); // $form->getElement('re_password')->setValue($user_data[0]['password']); if ($identity->user_type == "admin") { if ($this->getRequest()->isPost()) { $form->getElement('id')->setValue($id); if ($form->isValid($this->getRequest()->getParams())) { $model = new Application_Model_Users(); $form->removeElement("re_password"); $model->editUser($form->getValues(), $id); //$this->view->identity->id $this->redirect("/users/list"); } } } else { $form->removeElement("user_type"); $form->removeElement("active"); if ($this->getRequest()->isPost()) { $form->getElement('id')->setValue($id); if ($form->isValid($this->getRequest()->getParams())) { $model = new Application_Model_Users(); $form->removeElement("re_password"); $model->editUser($form->getValues(), $id); //$this->view->identity->id $this->redirect("categories/list"); } } } $this->view->form = $form; //$this->render("add"); } else { $this->redirect("/users/login"); } }
public function profileAction() { $this->_helper->layout->setLayout('iframe'); $form = new Admin_Form_Profile(); $user = $this->getUser(); $formProfile = new Application_Form_Profile(); $formProfile->setDefaultsFromEntity($user); $form->addSubform($formProfile->getSubform('attributes'), 'attributes'); $request = $this->getRequest(); if ($request->isPost() && $form->isValid($request->getPost())) { $values = $form->getValues(); try { if (!empty($values['image'])) { $imageInfo = array_pop($form->image->getFileInfo()); $values['image'] = $this->_helper->service('image')->save($imageInfo); $this->view->image = $this->_helper->service('image')->getSrc($values['image'], $this->_getParam('width', 80), $this->_getParam('height', 80)); } else { unset($values['image']); } $this->_helper->service('user')->save($values, $user); $this->view->close = true; } catch (\InvalidArgumentException $e) { $form->image->addError($e->getMessage()); } } $this->view->form = $form; }
public function myProfileAction() { /*--- find user data and populate the edit form ----*/ $userNs = new Zend_Session_Namespace('members'); $userId = $userNs->userId; //$user = unserialize($userNs->userObj); //$userId = $user->getId(); $userM = new Application_Model_User(); $user = $userM->find($userId); $params['firstName'] = $user->getFirstName(); $params['lastName'] = $user->getLastName(); $params['email'] = $user->getEmail(); $params['countryPassport'] = $user->getCountryPassport(); $params['preferredLanguage'] = $user->getPreferredLanguage(); $params['otherLanguages'] = $user->getOtherLanguages(); $params['cityId'] = $user->getCityId(); $params['cityName'] = $user->getCityName(); $arrDob = explode("-", $user->getDob()); if (count($arrDob) > 0) { $params['year'] = $arrDob[0]; $params['month'] = $arrDob[1]; $params['day'] = $arrDob[2]; } $params['sex'] = $user->getSex(); $params['firstTimeTraveller'] = $user->getFirstTimeTraveller(); $params['mobileCountryCode'] = $user->getMobileCountryCode(); $params['mobile'] = $user->getMobile(); $params['dreamDestination'] = $user->getDreamDestination(); $params['wayToTravel'] = $user->getWayToTravel(); $params['travelGear'] = $user->getTravelGear(); $params['yearGoal'] = $user->getYearGoal(); $params['leaveHomeWithout'] = $user->getLeaveHomeWithout(); $params['interests'] = $user->getInterests(); $params['evenTakenGapYear'] = $user->getEvenTakenGapYear(); $params['nextTravelToDoList'] = $user->getNextTravelToDoList(); $params['favouriteTravelExperience'] = $user->getFavouriteTravelExperience(); $this->view->username = $user->getUsername(); /*-------------------------------------------------------*/ $form = new Application_Form_Profile(); $form->populate($params); $elements = $form->getElements(); $form->clearDecorators(); foreach ($elements as $element) { $element->removeDecorator('label'); } if ($this->getRequest()->isPost()) { $params = $this->getRequest()->getPost(); /*---- email validation ----*/ if ($params['email'] != $user->getEmail()) { $form->getElement('email')->addValidators(array(array('Db_NoRecordExists', false, array('table' => 'user', 'field' => 'email', 'messages' => 'Email already exists, Please choose another email address')))); } /*-------------------------*/ /*--- validations for change password -------*/ if (trim($params['currentPassword']) != "") { $params['currentPassword'] = md5($params['currentPassword']); $form->getElement('currentPassword')->addValidators(array(array('Db_RecordExists', false, array('table' => 'user', 'field' => 'password', 'messages' => 'Incorrect current password')))); $form->getElement('password')->setRequired(true); } if (trim($params['password']) != "" && $params['currentPassword'] == "") { $form->getElement('currentPassword')->setRequired(true); $form->getElement('currentPassword')->addValidators(array(array('NotEmpty', false, array('messages' => array('isEmpty' => 'You must enter the current password'))))); } /*--- validations for change password -------*/ if ($form->isValid($params)) { $upload = new Zend_File_Transfer_Adapter_Http(); //---main image if ($upload->isValid('image')) { //unlink existing images if ($user->getImage() != "" && file_exists("media/picture/profile/" . $user->getImage())) { unlink("media/picture/profile/" . $user->getImage()); //main uploaded image unlink("media/picture/profile/thumb_" . $user->getImage()); //thumb image } $upload->setDestination("images/uploads/"); try { $upload->receive('image'); } catch (Zend_File_Transfer_Exception $e) { $msg = $e->getMessage(); } $upload->setOptions(array('useByteString' => false)); $id = $userId; $file_name = $upload->getFileName('image'); $cardImageTypeArr = explode(".", $file_name); $ext = strtolower($cardImageTypeArr[count($cardImageTypeArr) - 1]); $target_file_name = "profile_" . $id . ".{$ext}"; $targetPath = 'media/picture/profile/' . $target_file_name; $filterFileRename = new Zend_Filter_File_Rename(array('target' => $targetPath, 'overwrite' => true)); $filterFileRename->filter($file_name); $params['image'] = $target_file_name; /*--- Generate Thumbnail ---*/ $thumb = Base_Image_PhpThumbFactory::create($targetPath); $thumb->resize(200, 200); $thumb->save($targetPath = 'media/picture/profile/thumb_' . $target_file_name); } //----------- $params['dob'] = $params['year'] . "-" . $params['month'] . "-" . $params['day']; $pass = $user->getPassword(); if (trim($params['password']) != "") { $params['password'] = md5($params['password']); } else { $params['password'] = $pass; } $user->setOptions($params); $user->save(); $this->view->msg = "Profile updated successfully!"; $userNs->userObj = serialize($user); } //$this->_helper->_redirector->gotoUrl($this->view->seoUrl("/gapper/my-profile")); //$this->_redirect($this->view->seoUrl("/gapper/my-profile")); } $this->view->thumbImage = $user->getThumbnail(); $this->view->image_name = $user->getImage(); $this->view->gender = $user->getSex(); $this->view->form = $form; }