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 testWhenMissingDobParamsThenGetAgeReturnNull() { $profile = new Application_Model_Profile(['data' => ['dob' => '']]); $this->assertNull($profile->getAge()); $profileOther = new Application_Model_Profile(['data' => []]); $this->assertNull($profileOther->getAge()); }
public function delete(Application_Model_Profile $model) { if ($model->getId() !== null) { $where = $this->getDbTable()->getAdapter()->quoteInto("id = ?", $model->getId()); $this->getDbTable()->delete($where); } }
public function save(Application_Model_Profile $profile, $exists) { $data = array('user_id' => $profile->getUserId(), 'first_name' => $profile->getFirstName(), 'last_name' => $profile->getLastName(), 'birthdate' => $profile->getBirthdate(), 'gender' => $profile->getGender()); if ($exists) { unset($data['user_id']); $this->getDbTable()->update($data, array('user_id = ?' => $profile->getUserId())); } else { return $this->getDbTable()->insert($data); } }
/** * Restore backupped profiles * This is not a trigger of plugin API. It's called by Backupper plugin */ function restoreItems($items) { $models = Application_Model_ProfilesMapper::i()->fetchAll(); // cleaning up all shares foreach ($models as $model) { Application_Model_ProfilesMapper::i()->delete($model); } foreach (@$items['profiles'] as $modelInfo) { $model = new Application_Model_Profile(); $model->setArg(@$modelInfo['arg'])->setCondProviders(@$modelInfo['cond_providers'] !== '' ? @$modelInfo['cond_providers'] : null)->setCondFormats(@$modelInfo['cond_formats'] !== '' ? @$modelInfo['cond_formats'] : null)->setCondDevices(@$modelInfo['cond_devices'] !== '' ? @$modelInfo['cond_devices'] : null)->setLabel(@$modelInfo['label'])->setWeight(@$modelInfo['weight']); // i don't set id, or db adapter will try to update old data that i cleaned Application_Model_ProfilesMapper::i()->save($model); } return X_Env::_('p_profiles_backupper_restoreditems') . ": " . count($items['profiles']); }