public static function Save(Affiliation $dbAffiliation, $newAffiliation, $org_name, Member $CurrentMember) { $org_name = Convert::raw2sql($org_name); // attempt to retrieve Org by the submitted name $org = Org::get()->filter('Name', $org_name)->First(); if (!$org) { // no org matched, create a new org of that name and associate it $org = new Org(); $org->Name = $org_name; $org->write(); } $config = HTMLPurifier_Config::createDefault(); // Remove any CSS or inline styles $config->set('CSS.AllowedProperties', array()); $purifier = new HTMLPurifier($config); $dbAffiliation->OrganizationID = $org->ID; $dbAffiliation->JobTitle = $newAffiliation->JobTitle; $dbAffiliation->MemberID = $CurrentMember->ID; $dbAffiliation->StartDate = $newAffiliation->StartDate; $dbAffiliation->EndDate = !empty($newAffiliation->EndDate) ? $newAffiliation->EndDate : null; $dbAffiliation->Current = $newAffiliation->Current == 1 ? true : false; if (empty($newAffiliation->EndDate)) { $dbAffiliation->Current = true; } $dbAffiliation->write(); }
public static function Save(Affiliation $dbAffiliation, $newAffiliation, $org_name, Member $CurrentMember) { $org_name = Convert::raw2sql($org_name); // attempt to retrieve Org by the submitted name $org = Org::get()->filter('Name', $org_name)->First(); if (!$org) { // no org matched, create a new org of that name and associate it $org = new Org(); $org->Name = $org_name; $org->write(); //register new request $new_request = new OrganizationRegistrationRequest(); $new_request->MemberID = $CurrentMember->ID; $new_request->OrganizationID = $org->ID; $new_request->write(); } $config = HTMLPurifier_Config::createDefault(); // Remove any CSS or inline styles $config->set('CSS.AllowedProperties', array()); $purifier = new HTMLPurifier($config); if (!empty($newAffiliation->EndDate) && $newAffiliation->Current == 1) { $today = new DateTime($newAffiliation->ClientToday); $end_date = new DateTime($newAffiliation->EndDate); if ($end_date < $today) { throw new Exception('Current Affiliation: End Date must me greater than today!.'); } } $dbAffiliation->OrganizationID = $org->ID; $dbAffiliation->MemberID = $CurrentMember->ID; $dbAffiliation->StartDate = $newAffiliation->StartDate; $dbAffiliation->EndDate = !empty($newAffiliation->EndDate) ? $newAffiliation->EndDate : null; $dbAffiliation->Current = $newAffiliation->Current == 1 ? true : false; if (empty($newAffiliation->EndDate)) { $dbAffiliation->Current = true; } //$dbAffiliation->JobTitle = $purifier->purify($newAffiliation->JobTitle); //$dbAffiliation->Role = $purifier->purify($newAffiliation->Role); $dbAffiliation->write(); }
public function __construct(ISingleValueTemplateQuestion $question, $value = null) { $children = new FieldList(); $this->question = $question; $current_user = Member::currentUser(); $current_affiliations = $current_user->getCurrentAffiliations(); if (!$current_affiliations) { $children->add($txt = new TextField($question->name(), $question->label())); $txt->addExtraClass('input-organization-name'); } else { if (intval($current_affiliations->count()) > 1) { $source = array(); foreach ($current_affiliations as $a) { $org = $a->Organization(); $source[$org->ID] = $org->Name; } $source['0'] = "-- New One --"; $children->add($ddl = new DropdownField($question->name() . 'ID', $question->label(), $source)); $ddl->setEmptyString('-- Select Your Organization --'); $ddl->addExtraClass('select-organization-name'); if (!is_null($value)) { $org = Org::get()->filter('Name', $value)->first(); if ($org) { $ddl->setValue($org->ID); } } $children->add($txt = new TextField($question->name(), '')); $txt->addExtraClass('input-organization-name'); } else { $children->add($txt = new TextField($question->name(), $question->label(), $current_user->getOrgName())); $txt->addExtraClass('input-organization-name'); } } parent::__construct($children); $control_css_class = strtolower($this->question->name() . '-composite'); $this->addExtraClass($control_css_class); Requirements::javascript('survey_builder/js/survey.organization.field.js'); Requirements::customScript("\n jQuery(document).ready(function(\$) {\n \$('.'+'{$control_css_class}').survey_organization_field();\n });"); }
* Copyright 2015 OpenStack Foundation * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. **/ PublisherSubscriberManager::getInstance()->subscribe('survey_organization_selected', function ($member, $organization_name) { //create the affiliation as current $organization_name = Convert::raw2sql(trim($organization_name)); if (!empty($organization_name)) { $org = Org::get()->filter(array('Name' => $organization_name))->first(); if (!$org) { $org = new Org(); $org->Name = $organization_name; $org->IsStandardizedOrg = false; $org->write(); //register new request $new_request = new OrganizationRegistrationRequest(); $new_request->MemberID = $member->getIdentifier(); $new_request->OrganizationID = $org->ID; $new_request->write(); } // If a new org name was provided for the member, find / create the new org and update the member record if (!$member->hasCurrentAffiliation($organization_name)) { $newAffiliation = new StdClass(); $newAffiliation->StartDate = date('Y-m-d');
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; } } }
/** * @param $request * @return SS_HTTPResponse */ public function searchOrg($request) { if (!Director::is_ajax()) { return $this->forbiddenError(); } $term = $request->getVar('term'); $term = Convert::raw2sql($term); $organizations = Org::get()->filter('Name:PartialMatch', $term)->limit(10); if ($organizations) { $suggestions = array(); foreach ($organizations as $org) { array_push($suggestions, array('id' => $org->ID, 'label' => $org->Name, 'value' => $org->Name)); } $response = new SS_HTTPResponse(); $response->setStatusCode(200); $response->addHeader('Content-Type', 'application/json'); $response->setBody(json_encode($suggestions)); return $response; } }
public function NextStep($data, $form) { // Save our work $survey = $this->GetCurrentSurvey(); $form->saveInto($survey); //Update Member if need be if (isset($data['Organization'])) { $org_data = Convert::raw2sql(trim($data['Organization'])); if (!empty($org_data)) { $org = Org::get()->filter(array('Name' => $org_data))->first(); if (!$org) { $org = new Org(); $org->Name = $org_data; $org->IsStandardizedOrg = false; $org->write(); //register new request $new_request = new OrganizationRegistrationRequest(); $new_request->MemberID = Member::currentUserID(); $new_request->OrganizationID = $org->ID; $new_request->write(); } $this->updateMember($org_data); $survey->OrgID = $org->ID; $survey->UpdateDate = SS_Datetime::now()->Rfc2822(); $survey->write(); } } $newIndex = array_search($this->CurrentStep(), DeploymentSurvey::$steps) + 1; if ($form instanceof DeploymentSurveyAboutYouForm) { //check if user info has changed $current_user = Member::currentUser(); $current_user->FirstName = $data['FirstName']; $current_user->Surname = $data['Surname']; $current_user->write(); } if ($form instanceof DeploymentSurveyYourThoughtsForm) { if (strpos($survey->OpenStackActivity, 'Write applications that run on OpenStack') !== false || strpos($survey->OpenStackActivity, 'Manage people who write applications that run on OpenStack') !== false || strpos($survey->OpenStackInvolvement, 'Cloud Consumer') !== false) { //normal flow - Send them to user-survey/AppDevSurvey as normal $newIndex = array_search('AppDevSurvey', DeploymentSurvey::$steps); } else { // Send them to user-survey/Deployments $newIndex = array_search('Deployments', DeploymentSurvey::$steps); } } if ($newIndex > count(DeploymentSurvey::$steps)) { $newIndex = count(DeploymentSurvey::$steps); } $CurrentStep = DeploymentSurvey::$steps[$newIndex]; Session::set('CurrentStep', $CurrentStep); $survey->CurrentStep = $CurrentStep; $DesiredHighestStepIndex = array_search($survey->CurrentStep, DeploymentSurvey::$steps); // The index of this step in the list $HighestStepAllowedIndex = array_search($survey->HighestStepAllowed, DeploymentSurvey::$steps); // The index of the highest allowed step in the list if ($DesiredHighestStepIndex > $HighestStepAllowedIndex) { $survey->HighestStepAllowed = $CurrentStep; } $survey->UpdateDate = SS_Datetime::now()->Rfc2822(); $survey->write(); $this->redirect($this->Link() . $CurrentStep); }
/** * @param string $name * @return IOrganization */ public function getByName($name) { return Org::get()->filter('Name', $name)->First(); }
public function suggestOrganization(SS_HTTPRequest $request) { if (!Director::is_ajax()) { return $this->forbiddenError(); } if (!Member::currentUser()) { return $this->forbiddenError(); } $term = Convert::raw2sql($request->getVar('term')); $orgs = Org::get()->filter('Name:PartialMatch', $term)->sort('Name')->limit(100); $items = array(); foreach ($orgs as $org) { $items[] = array('id' => $org->ID, 'label' => $org->Name, 'value' => $org->Name); } return $this->ok($items); }
public function suggestOrganization(SS_HTTPRequest $request) { if (!Director::is_ajax()) { return $this->httpError(403); } if (!Member::currentUser()) { return $this->httpError(403); } $term = Convert::raw2sql($request->getVar('term')); $orgs = Org::get()->filter('Name:PartialMatch', $term)->sort('Name')->limit(100); $items = array(); foreach ($orgs as $org) { $items[] = array('id' => $org->ID, 'label' => $org->Name, 'value' => $org->Name); } $response = new SS_HTTPResponse(); $response->addHeader('Content-Type', 'application/json'); $response->setBody(json_encode($items)); return $response; }