Esempio n. 1
0
 public function addAction()
 {
     // Handle edit vocabulary form.
     $profileType = new UserProfilesType();
     $this->_profileType = $profileType;
     $this->view->profileType = $profileType;
     if ($this->_getParam('submit')) {
         $profileType->label = $this->_getParam('name');
         $profileType->description = $this->_getParam('description');
         $profileType->public = $this->_getParam('public');
         $profileType->required = $this->_getParam('required');
         $elementSet = new ElementSet();
         $elementSet->name = $profileType->label . " Elements";
         $elementSet->description = "Elements for " . $profileType->label;
         $elementSet->record_type = 'UserProfilesType';
         $elementSet->save();
         $this->_elementSet = $elementSet;
         $profileType->element_set_id = $elementSet->id;
         $elementInfos = $this->_getElementInfos();
         $profileType->setElementInfos($elementInfos);
         $multiInfos = $this->_getMultiElementInfos();
         $profileType->setMultiElementInfos($multiInfos);
         if ($profileType->save(false)) {
             $this->_helper->flashMessenger(__('The profile type was successfully added.'), 'success');
             $this->redirect('user-profiles');
         } else {
             $elementSet->delete();
             $errors = $profileType->getErrors();
             $this->_helper->flashMessenger($errors, 'error');
         }
     }
 }
 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);
 }