public function saveAction() { $profile = $this->_getProfile(); $form = new Users_Form_PersonalInfo(null, $profile); $formData = $this->_request->getPost(); $form->populate($formData); if (!$form->isValid($formData)) { $appSession = Zend_Registry::get('appSession'); $appSession->personalInfoForm = $form; $this->_forward('edit'); return; } $fieldsValues = new Model_FieldsValues(); if ($this->_getParam('profile')) { $fieldsValues->deleteForProfile($profile); } else { $profile->user_id = $this->user->id; $profile->name = $form->getValue('profileName'); $profile->save(); } foreach ($form->getValues() as $fieldName => $fieldValue) { if ($fieldName == 'profileName' || !$fieldValue) { continue; } $fieldsValue = $fieldsValues->createRow(); $fieldsValue->user_id = $this->user->id; $fieldsValue->profile_id = $profile->id; list(, $fieldId) = explode('_', $fieldName); $fieldsValue->field_id = $fieldId; $fieldsValue->value = $fieldValue; $fieldsValue->save(); } $this->_helper->FlashMessenger->addMessage($this->view->translate('Profile has been saved')); $this->_redirect('/users/personalinfo'); }
/** * I need to fill the new profile_id field in the fields_values table, before being able to * add a foreign key to it */ public function proceed() { $fieldsValues = new Model_FieldsValues(); $users = new Users_Model_Users(); foreach ($users->getUsers() as $user) { $profileId = $user->createDefaultProfile($this->_view); foreach ($fieldsValues->getForUser($user) as $fieldValue) { $fieldValue->profile_id = $profileId; $fieldValue->save(); } } $this->_db->query('ALTER TABLE `fields_values` ADD FOREIGN KEY ( `profile_id` ) REFERENCES `profiles` (`id`) ON DELETE CASCADE'); }
public function generatePersonalInfo(array $ldapData, $profileId) { if (!$this->id) { throw new Exception('Can\'t call User::generatePersonalInfo() on an empty User object'); } $ldapConfig = Zend_Registry::get('config')->ldap; if (!isset($ldapConfig->fields)) { return; } $fieldValues = new Model_FieldsValues(); $fields = new Model_Fields(); foreach ($ldapConfig->fields->toArray() as $openIdField => $ldapField) { if (!($fieldRow = $fields->getByOpenIdIdentifier($openIdField))) { continue; } if (!isset($ldapData[$ldapField])) { if (strpos($ldapField, '+') == false) { continue; } $subfields = explode('+', $ldapField); array_walk($subfields, 'trim'); $value = array(); foreach ($subfields as $subfield) { if (!isset($ldapData[$subfield])) { continue; } $value[] = $ldapData[$subfield][0]; } $value = implode(' ', $value); } else { $value = $ldapData[$ldapField][0]; } $fieldsValue = $fieldValues->createRow(); $fieldsValue->user_id = $this->id; $fieldsValue->profile_id = $profileId; $fieldsValue->field_id = $fieldRow->id; $fieldsValue->value = $value; $fieldsValue->save(); } }