'Male',
'Female' => 'Female',
'Specify' => 'Let me specify',
'Prefer not to say' => 'Prefer not to say'
));
$GenderSpecifyField = new TextField('GenderSpecify', 'Specify your gender');
$GenderSpecifyField->addExtraClass('hide');
$StatementOfInterestField = new TextField('StatementOfInterest', 'Statement of Interest');
$StatementOfInterestField->addExtraClass('autocompleteoff');
$affiliations = new FieldGroup(
new HeaderField('Affiliations'),
new LiteralField("add-affiliation", "Add New Affiliation"),
new LiteralField("affiliations-container", "
")
);
$fields = new FieldList(
$FirstNameField,
$LastNameField,
new LiteralField('break', '
'),
$PrimaryEmailField,
new LiteralField('instructions', 'This will also be your login name.
'),
new LiteralField('break', '
'),
$GenderField,
$GenderSpecifyField,
new LiteralField('instructions', 'It\'s perfectly acceptable if you choose not to tell us: we appreciate you becoming a member of OpenStack Foundation. The information will remain private and only used to monitor our effort to improve gender diversity in our community.
'),
new LiteralField('break', '
'),
$affiliations,
new HiddenField("Affiliations", "Affiliations", ""),
new LiteralField('instructions', 'For our purposes, an affiliation is defined as any company where you are an officer, director or employee, or any person or company that has paid you more than $60,000 USD as an independent contractor in the last 12 months. Please list all affiliations which meet this criteria.
'),
$StatementOfInterestField,
new LiteralField('instructions', 'Your statement of interest should be a few words describing your objectives or plans for OpenStack.
'),
new LiteralField('break', '
'),
new TextField('Address', _t('Addressable.ADDRESS', 'Street Address (Line1)')),
new TextField('Suburb', _t('Addressable.SUBURB', 'Street Address (Line2)')),
new TextField('City', _t('Addressable.CITY', 'City'))
);
$label = _t('Addressable.STATE', 'State');
if (is_array($this->allowedStates)) {
$fields->push(new DropdownField('State', $label, $this->allowedStates));
} elseif (!is_string($this->allowedStates)) {
$fields->push(new TextField('State', $label));
}
$AdressField = new TextField(
'Postcode', _t('Addressable.POSTCODE', 'Postcode')
);
$fields->push($AdressField);
$label = _t('Addressable.COUNTRY', 'Country');
if (is_array($this->allowedCountries)) {
$countryField = new DropdownField('Country', $label, $this->allowedCountries);
$countryField->addExtraClass('chzn-select');
$fields->push($countryField);
} elseif (!is_string($this->allowedCountries)) {
$countryField = new CountryDropdownField('Country', $label);
$countryField->addExtraClass('chzn-select');
$fields->push($countryField);
}
$fields->push(new LiteralField('break', '
'));
$fields->push(new ConfirmedPasswordField('Password',
'Password'
));
$actions = new FieldList(
new FormAction('doRegister', 'Submit My Application')
);
$validator = new Member_Validator(
'FirstName',
'Surname',
'Email',
'StatementOfInterest',
'Address',
'City',
'Country',
'Password'
);
return new HoneyPotForm($this, 'RegistrationForm', $fields, $actions, $validator);
}
//Submit the registration form
function doRegister($data, $form)
{
if (!isset($data["Affiliations"]) || empty($data["Affiliations"])) {
//Set error message
$form->AddErrorMessage('Affiliations', "Sorry, You must at least enter one valid Affiliation.", 'bad');
//Set form data from submitted values
Session::set("FormInfo.Form_RegistrationForm.data", $data);
//Return back to form
return $this->redirectBack();;
}
$new_affiliations = json_decode($data["Affiliations"]);
//Check for existing member email address
if ($member = Member::get()->filter('Email', Convert::raw2sql($data['Email']))->first()) {
//Set error message
$form->AddErrorMessage('Email', "Sorry, that email address already exists. Please choose another.", 'bad');
//Set form data from submitted values
Session::set("FormInfo.Form_RegistrationForm.data", $data);
//Return back to form
return $this->redirectBack();
}
//Otherwise create new member and log them in
$Member = new Member();
$form->saveInto($Member);
if (isset($data['Gender'])) {
$Gender = $data['Gender'];
if ($Gender != 'Male' && $Gender != 'Female' && $Gender != 'Prefer not to say') {
$Member->Gender = Convert::raw2sql($data['GenderSpecify']);
}
}
$Member->write();
// Assign the member to be part of the foundation group
$Member->addToGroupByCode('foundation-members');
// Set up member with legal agreement for becoming an OpenStack Foundation Member
$legalAgreement = new LegalAgreement();
$legalAgreement->MemberID = $Member->ID;
$legalAgreement->LegalDocumentPageID = 422;
$legalAgreement->write();
$Member->login();
//Find or create the 'user' group
if (!$userGroup = Group::get()->filter('Code', 'users')->first()) {
$userGroup = new Group();
$userGroup->Code = "users";
$userGroup->Title = "Users";
$userGroup->Write();
$Member->Groups()->add($userGroup);
}
//Add member to user group
$Member->Groups()->add($userGroup);
foreach ($new_affiliations as $key => $newAffiliation) {
$dbAffiliation = new Affiliation();
$org_name = Convert::raw2sql($newAffiliation->OrgName);
$org_name = trim($org_name);
AffiliationController::Save($dbAffiliation, $newAffiliation, $org_name, $Member);
}
PublisherSubscriberManager::getInstance()->publish('new_user_registered', array($Member->ID));
//Get profile page
if ($ProfilePage = EditProfilePage::get()->first()) {
//send Thank you email
$config = SiteConfig::current_site_config();
if ($config->RegistrationSendMail &&
!empty($config->RegistrationFromMessage) &&
!empty($config->RegistrationSubjectMessage) &&
!empty($config->RegistrationHTMLMessage) &&
!empty($config->RegistrationPlainTextMessage)
) {
$registration_email = new CustomEmail($config->RegistrationFromMessage,
$Member->Email,
$config->RegistrationSubjectMessage,
$config->RegistrationHTMLMessage,
$config->RegistrationPlainTextMessage);
$registration_email->send();
}
//Redirect to profile page with success message
return $this->redirect($ProfilePage->Link('?success=1'));
}
}
function LegalTerms()
{
return LegalDocumentPage::get()->byID(422);
}
// This method is used to autocomplete match org names as they are entered
// It's called via Ajax on the OrgName field
public function results()
{
if ($query = $this->getSearchQuery()) {
$query = Convert::raw2xml($query);
// Search Orgs against the query.
$Results = Org::get()->filter('Name:PartialMatch', $query);
// For AutoComplete
if (Director::is_ajax() && $Results) {
$Orgs = $Results->map('ID', 'Name');
$Suggestions = "";
foreach ($Orgs as $Org) {
$Suggestions = $Suggestions . $Org . '|' . '1' . "\n";
}
return $Suggestions;
}
}
}
function getSearchQuery()
{
if ($this->request)
return $this->request->getVar("q");
}
}