protected function getUserProfile()
 {
     $contributorData = $this->contributorData;
     // look for the id in the cached map
     $contributorId = $contributorData['id'];
     if (array_key_exists($contributorId, $this->contributorIdProfileMap)) {
         return $this->contributorIdProfileMap[$contributorId];
     }
     $db = get_db();
     // lookup User by the email address, then get the profile
     // from user id, profile type
     $email = $contributorData['email'];
     $user = $db->getTable('User')->findByEmail($email);
     $profile = $db->getTable('UserProfilesProfile')->findByUserIdAndTypeId($user->id, $this->userProfilesType->id);
     if ($profile) {
         $this->contributorIdProfileMap[$contributorId] = $profile;
         return $profile;
     }
     //finally, create a new profile if all else failed
     $profile = new UserProfilesProfile();
     $profile->owner_id = $user->id;
     $profile->type_id = $this->userProfilesType->id;
     $profile->setRelationData(array('subject_id' => $user->id));
     $profile->public = 0;
     $profile->save(true);
     $this->contributorIdProfileMap[$contributorId] = $profile;
     return $profile;
 }
 public function _setupProfile()
 {
     $profile = new UserProfilesProfile();
     $profile->setRelationData(array('subject_id' => 1, 'user_id' => 1));
     $values = array(array('Text Field' => 'Text Field Value'), array('Int Field' => 'Int Field Value'));
     $profile->values = $values;
     $profile->type_id = 1;
     $this->assertFalse($profile->isSubject());
     $profile->save();
 }
 public function perform()
 {
     $db = get_db();
     $elementSet = new ElementSet();
     $elementSet->record_type = "UserProfilesType";
     $elementSet->name = "Contributor Elements";
     $elementSet->description = "";
     $elementSet->save();
     $importData = $this->_importContributorFields($elementSet);
     $type_id = $importData['type_id'];
     $contribFieldElementMap = $importData['contribFieldElementMap'];
     $userContributorMap = unserialize(file_get_contents(CONTRIBUTION_PLUGIN_DIR . '/upgrade_files/user_contributor_map.txt'));
     foreach ($userContributorMap as $userId => $contributorIds) {
         $contribIds = implode(',', $contributorIds);
         $sql = "SELECT * FROM {$db->ContributionContributorValue} WHERE `contributor_id` IN ({$contribIds})";
         $res = $db->query($sql);
         $contributorValues = $res->fetchAll();
         $profile = new UserProfilesProfile();
         $profile->owner_id = $userId;
         $profile->public = true;
         $profile->element_set_id = $elementSet->id;
         $profile->type_id = $type_id;
         $profile->setRelationData(array('subject_id' => $userId));
         $profile->save();
         $elTextArray = array();
         foreach ($contributorValues as $value) {
             //dig up element_id
             $fieldId = $value['field_id'];
             $elementId = $contribFieldElementMap[$fieldId];
             $elementText = new ElementText();
             $elementText->element_id = $elementId;
             $elementText->text = $value['value'];
             $elementText->html = 0;
             $elementText->record_type = 'UserProfilesProfile';
             $elementText->record_id = $profile->id;
             $elementText->save();
             release_object($elementText);
         }
         release_object($profile);
     }
     set_option('user_profiles_contributors_imported', true);
 }
예제 #4
0
 public function editAction()
 {
     $this->view->addHelperPath(USER_PROFILES_DIR . '/helpers', 'UserProfiles_View_Helper_');
     $allTypes = $this->_helper->db->getTable('UserProfilesType')->findAll();
     $typeId = $this->getParam('type');
     //if no typeId
     if (!$typeId) {
         $typeId = $allTypes['0']->id;
     }
     $profileType = $this->_helper->db->getTable('UserProfilesType')->find($typeId);
     $userId = $this->_getParam('id');
     if ($userId) {
         $user = $this->_helper->db->getTable('User')->find($userId);
     } else {
         $user = current_user();
         $userId = $user->id;
     }
     $this->view->user = $user;
     $userProfile = $this->_helper->db->getTable()->findByUserIdAndTypeId($userId, $typeId);
     if (!$userProfile) {
         $userProfile = new UserProfilesProfile();
         $userProfile->setOwner($user);
         $userProfile->type_id = $typeId;
         $userProfile->setRelationData(array('subject_id' => $userId));
     }
     if (!is_allowed($userProfile, 'edit')) {
         throw new Omeka_Controller_Exception_403();
     }
     if ($this->_getParam('submit')) {
         $userProfile->setPostData($_POST);
         if ($userProfile->save(false)) {
             fire_plugin_hook('user_profiles_save', array('post' => $_POST, 'profile' => $userProfile, 'type' => $profileType));
             $this->redirect("user-profiles/profiles/user/id/{$userId}/type/{$typeId}");
         } else {
             $this->_helper->flashMessenger($userProfile->getErrors());
         }
     }
     $this->view->userprofilesprofile = $userProfile;
     $this->view->userprofilestype = $profileType;
     $this->view->profile_types = apply_filters('user_profiles_type', $allTypes);
 }
 protected function _processUserProfile($post, $user)
 {
     $profileTypeId = get_option('contribution_user_profile_type');
     if ($profileTypeId && plugin_is_active('UserProfiles')) {
         $profile = $this->_helper->db->getTable('UserProfilesProfile')->findByUserIdAndTypeId($user->id, $profileTypeId);
         if (!$profile) {
             $profile = new UserProfilesProfile();
             $profile->setOwner($user);
             $profile->type_id = $profileTypeId;
             $profile->public = 0;
             $profile->setRelationData(array('subject_id' => $user->id, 'user_id' => $user->id));
         }
         $profile->setPostData($post);
         $this->_profile = $profile;
         if (!$profile->save(false)) {
             return false;
         }
     }
     return true;
 }