コード例 #1
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);
 }
コード例 #2
0
 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;
 }