function addAction($data, $form)
 {
     //Check for a logged in member
     if ($CurrentMember = Member::currentUser()) {
         // Find a site member (in any group) based on the MemberID field
         $id = Convert::raw2sql($data['MemberID']);
         $member = DataObject::get_by_id("Member", $id);
         if ($data['SpeakerID'] && is_numeric($data['SpeakerID'])) {
             $speaker = PresentationSpeaker::get()->byID(intval($data['SpeakerID']));
         } elseif ($member) {
             $speaker = PresentationSpeaker::get()->filter('MemberID', $member->ID)->first();
         }
         if (!$speaker) {
             $speaker = new PresentationSpeaker();
         }
         //Find or create the 'speaker' group
         if (!($userGroup = DataObject::get_one('Group', "Code = 'speakers'"))) {
             $userGroup = new Group();
             $userGroup->Code = "speakers";
             $userGroup->Title = "Speakers";
             $userGroup->Write();
             $member->Groups()->add($userGroup);
         }
         //Add member to the group
         $member->Groups()->add($userGroup);
         if ($data['Country'] != '' && $data['Country'] != $member->Country) {
             $member->Country = convert::raw2sql($data['Country']);
         }
         if ($data['ReplaceName'] == 1) {
             $member->FirstName = $data['FirstName'];
         }
         if ($data['ReplaceSurname'] == 1) {
             $member->Surname = $data['LastName'];
         }
         if ($data['ReplaceBio'] == 1) {
             $member->Bio = $data['Bio'];
         }
         $member->write();
         $form->saveInto($speaker);
         $speaker->MemberID = $member->ID;
         $speaker->AdminID = Member::currentUser()->ID;
         // Attach Photo
         if ($member->PhotoID && $speaker->PhotoID == 0) {
             $speaker->PhotoID = $member->PhotoID;
         }
         $speaker->AskedAboutBureau = TRUE;
         // Languages
         foreach ($speaker->Languages() as $currentlang) {
             $currentlang->delete();
         }
         foreach ($data['Language'] as $lang) {
             if (trim($lang) != '') {
                 $spoken_lang = SpeakerLanguage::create(array('Language' => $lang));
                 $speaker->Languages()->add($spoken_lang);
             }
         }
         // Expertise
         $speaker->AreasOfExpertise()->removeAll();
         foreach ($data['Expertise'] as $exp) {
             if (trim($exp) != '') {
                 $expertise = SpeakerExpertise::create(array('Expertise' => $exp));
                 $speaker->AreasOfExpertise()->add($expertise);
             }
         }
         // Presentation Link
         $speaker->OtherPresentationLinks()->removeAll();
         foreach ($data['PresentationLink'] as $key => $link) {
             if (trim($link) != '') {
                 $presentation_title = trim($data['PresentationTitle'][$key]);
                 $presentation_link = SpeakerPresentationLink::create(array('LinkUrl' => $link, 'Title' => $presentation_title));
                 $speaker->OtherPresentationLinks()->add($presentation_link);
             }
         }
         // Travel Preferences
         $speaker->TravelPreferences()->removeAll();
         foreach ($data['CountriesToTravel'] as $travel_country) {
             $travel_pref = SpeakerTravelPreference::create(array('Country' => $travel_country));
             $speaker->TravelPreferences()->add($travel_pref);
         }
         $speaker->write();
         $form->sessionMessage('Your profile has been updated', 'good');
         Session::clear("FormInfo.{$form->FormName()}.data", $data);
         return $this->controller()->redirectBack();
     } else {
         return Security::PermissionFailure($this->controller, 'You must be <a href="/join">registered</a> and logged in to edit your profile:');
     }
 }
Esempio n. 2
0
 public function saveInto(DataObjectInterface $dataObject, $fieldList = null)
 {
     parent::saveInto($dataObject, $fieldList);
     if (!$dataObject instanceof PresentationSpeaker) {
         return;
     }
     $speaker = $dataObject;
     $speaker->AreasOfExpertise()->removeAll();
     for ($i = 1; $i <= 5; $i++) {
         $field = $this->fields->fieldByName("Expertise[{$i}]");
         if (is_null($field)) {
             continue;
         }
         $val = $field->Value();
         if (empty($val)) {
             continue;
         }
         $speaker->AreasOfExpertise()->add(SpeakerExpertise::create(array('Expertise' => trim($val))));
     }
     $speaker->Languages()->removeAll();
     for ($i = 1; $i <= 5; $i++) {
         $field = $this->fields->fieldByName("Language[{$i}]");
         if (is_null($field)) {
             continue;
         }
         $val = $field->Value();
         if (empty($val)) {
             continue;
         }
         $speaker->Languages()->add(SpeakerLanguage::create(array('Language' => trim($val))));
     }
     $speaker->OtherPresentationLinks()->removeAll();
     for ($i = 1; $i <= 5; $i++) {
         $link = $this->fields->fieldByName("PresentationLink[{$i}]");
         $title = $this->fields->fieldByName("PresentationTitle[{$i}]");
         if (is_null($link)) {
             continue;
         }
         $link_val = $link->Value();
         $title_val = is_null($title) ? '' : $title->Value();
         if (empty($link_val)) {
             continue;
         }
         $speaker->OtherPresentationLinks()->add(SpeakerPresentationLink::create(array('LinkUrl' => trim($link_val), 'Title' => trim($title_val))));
     }
     $countries_2_travel = $this->fields->fieldByName('CountriesToTravel');
     if (!is_null($countries_2_travel)) {
         $speaker->TravelPreferences()->removeAll();
         $country_array = $countries_2_travel->Value();
         foreach ($country_array as $country_name) {
             $speaker->TravelPreferences()->add(SpeakerTravelPreference::create(array('Country' => $country_name)));
         }
     }
 }
Esempio n. 3
0
 public function saveInto(DataObjectInterface $dataObject, $fieldList = null)
 {
     parent::saveInto($dataObject, $fieldList);
     if (!$dataObject instanceof PresentationSpeaker) {
         return;
     }
     $speaker = $dataObject;
     $expertise_csv = $this->fields->fieldByName("Expertise")->Value();
     $expertise_array = explode(',', $expertise_csv);
     $exp_ids = array();
     if ($expertise_array) {
         foreach ($expertise_array as $expertise) {
             if (empty($expertise)) {
                 continue;
             }
             $expertise = Convert::raw2sql(trim($expertise));
             if (!($anexp = $speaker->AreasOfExpertise()->find('Expertise', $expertise))) {
                 $anexp = SpeakerExpertise::create(array('Expertise' => $expertise));
             }
             $anexp->write();
             $exp_ids[] = $anexp->ID;
         }
     }
     $speaker->AreasOfExpertise()->setByIdList($exp_ids);
     $language_csv = $this->fields->fieldByName("Language")->Value();
     $language_array = explode(',', $language_csv);
     $lang_ids = array();
     if ($language_array) {
         foreach ($language_array as $language) {
             if (empty($language)) {
                 continue;
             }
             $language = Convert::raw2sql(trim($language));
             if (!($alang = $speaker->Languages()->find('Language', $language))) {
                 $alang = SpeakerLanguage::create(array('Language' => $language));
             }
             $alang->write();
             $lang_ids[] = $alang->ID;
         }
     }
     $speaker->Languages()->setByIdList($lang_ids);
     $link_ids = array();
     for ($i = 1; $i <= 5; $i++) {
         $link = $this->fields->fieldByName("PresentationLink[{$i}]");
         $title = $this->fields->fieldByName("PresentationTitle[{$i}]");
         if (is_null($link)) {
             continue;
         }
         $link_val = Convert::raw2sql(trim($link->Value()));
         if (empty($link_val)) {
             continue;
         }
         $title_val = is_null($title) ? '' : Convert::raw2sql(trim($title->Value()));
         if (!($alink = $speaker->OtherPresentationLinks()->find('LinkUrl', $link_val))) {
             $alink = SpeakerPresentationLink::create(array('LinkUrl' => $link_val, 'Title' => $title_val));
         } else {
             $alink->Title = $title_val;
         }
         $alink->write();
         $link_ids[] = $alink->ID;
     }
     $speaker->OtherPresentationLinks()->setByIdList($link_ids);
     $roles = $this->fields->fieldByName("OrganizationalRole")->Value();
     if ($roles && in_array(0, $roles)) {
         // 0 is the id for Other
         $other_role = $this->fields->fieldByName("OtherOrganizationalRole")->Value();
         $other_role = Convert::raw2sql(trim($other_role));
         $new_role = SpeakerOrganizationalRole::get()->where("Role = '{$other_role}' ")->first();
         if (!$new_role) {
             $new_role = new SpeakerOrganizationalRole(array('Role' => $other_role, 'IsDefault' => 0));
             $new_role->write();
         }
         array_pop($roles);
         $roles[] = $new_role->ID;
     }
     $speaker->OrganizationalRoles()->setByIdList($roles);
     $countries_2_travel = $this->fields->fieldByName('CountriesToTravel');
     $country_ids = array();
     if (!is_null($countries_2_travel)) {
         $country_array = $countries_2_travel->Value();
         if ($country_array) {
             foreach ($country_array as $country_name) {
                 $country_name = Convert::raw2sql(trim($country_name));
                 if (!($acountry = $speaker->TravelPreferences()->find('Country', $country_name))) {
                     $acountry = SpeakerTravelPreference::create(array('Country' => $country_name));
                 }
                 $acountry->write();
                 $country_ids[] = $acountry->ID;
             }
         }
     }
     $speaker->TravelPreferences()->setByIdList($country_ids);
 }