function run() { $batch_size = 15; if (isset($_GET['batch_size'])) { $batch_size = intval(trim(Convert::raw2sql($_GET['batch_size']))); } $surveys = DeploymentSurvey::getNotDigestSent($batch_size); $deployments = Deployment::getNotDigestSent($batch_size); if ($surveys) { foreach ($surveys as $survey) { $survey->SendDigest = 1; $survey->write(); } } if ($deployments) { foreach ($deployments as $dep) { $dep->SendDigest = 1; $dep->write(); } } if ((!is_null($surveys) && count($surveys)) > 0 || !is_null($deployments) && count($deployments)) { global $email_new_deployment; $email = EmailFactory::getInstance()->buildEmail($email_new_deployment, $email_new_deployment, $subject = 'New Deployments and Surveys'); $email->setTemplate('NewDeploymentsSurveysEmail'); $email->populateTemplate(array('SurveysUrl' => Director::absoluteURL('admin/deployments/DeploymentSurvey/EditForm/field/DeploymentSurvey/item'), 'DeploymentsUrl' => Director::absoluteURL('admin/deployments/Deployment/EditForm/field/Deployment/item'), 'SangriaDeploymentsUrl' => Director::absoluteURL('sangria/ViewDeploymentDetails'), 'Surveys' => $surveys, 'Deployments' => $deployments)); $email->send(); } }
function SurveyDetails() { $params = $this->owner->request->allParams(); $deployment_id = intval(Convert::raw2sql($params["ID"])); $range = Session::get("global_survey_range"); //get survey version if (!empty($range) && $range === SurveyType::FALL_2015) { $survey = Survey::get()->byID($deployment_id); if ($survey->ClassName === 'EntitySurvey') { $survey = EntitySurvey::get()->byID($deployment_id); } } else { $survey = DeploymentSurvey::get()->byID($deployment_id); } if ($survey) { $back_url = $this->owner->request->getVar('BackUrl'); if ($survey instanceof Survey) { $details_template = 'SangriaPage_SurveyBuilderSurveyDetails'; $data = array("Survey" => $survey, "BackUrl" => $back_url); } else { $details_template = $survey->getSurveyType() == SurveyType::OLD ? "SangriaPage_SurveyDetailsOld" : "SangriaPage_SurveyDetails"; $data = array("Survey" => $survey, "BackUrl" => $back_url); } if (empty($back_url)) { $back_url = "#"; } return $this->owner->Customise($data)->renderWith(array($details_template, 'SangriaPage', 'SangriaPage')); } return $this->owner->httpError(404, 'Sorry that Survey could not be found!.'); }
function MembersWithPublicDeployments() { $MembersWithPublicDeployments = new ArrayList(); $DeploymentSurveys = DeploymentSurvey::get(); foreach ($DeploymentSurveys as $CurrentSurvey) { $PublicDeployments = Deployment::get()->filter(array('DeploymentSurveyID' => $CurrentSurvey->ID, 'IsPublic' => 1)); if ($PublicDeployments) { $Member = Member::get()->byID($CurrentSurvey->MemberID); $MembersWithPublicDeployments->push($Member); echo $Member->FirstName . " has public deployments on DeploymentSurvey ID " . $CurrentSurvey->ID . '<br/>'; } } return $MembersWithPublicDeployments; }
public function copyFrom(DeploymentSurvey $oldSurvey) { // copy properties foreach (DeploymentSurvey::$db as $field => $type) { if (in_array($field, DeploymentSurveyMigrationOptions::$blank_fields)) { continue; } $new_value = ''; if (array_key_exists($field, DeploymentSurveyMigrationOptions::$migration_fields)) { $new_value = $oldSurvey->getField($field); if (empty($new_value)) { continue; } $table = DeploymentSurveyMigrationOptions::$migration_fields[$field]; foreach ($table as $old => $new) { $new_value = str_replace($old, $new, $new_value); } } else { $new_value = $oldSurvey->getField($field); } $this->setField($field, $new_value); } $this->setField('OrgID', $oldSurvey->getField('OrgID')); $this->setField('MemberID', $oldSurvey->getField('MemberID')); foreach ($oldSurvey->Deployments() as $oldDeployment) { $newDeployment = new Deployment(); $newDeployment->copyFrom($oldDeployment); $newDeployment->write(); $this->Deployments()->add($newDeployment); } foreach ($oldSurvey->AppDevSurveys() as $oldAppDev) { $newAppDev = new AppDevSurvey(); $newAppDev->copyFrom($oldAppDev); $newAppDev->write(); $this->AppDevSurveys()->add($newAppDev); } }
function SurveyDetails() { $params = $this->owner->request->allParams(); $survey_id = intval(Convert::raw2sql($params["ID"])); $survey = DeploymentSurvey::get()->byID($survey_id); if ($survey) { $back_url = $this->owner->request->getVar('BackUrl'); if (empty($back_url)) { $back_url = '#'; } $details_template = $survey->getSurveyType() == SurveyType::OLD ? "SangriaPage_SurveyDetailsOld" : "SangriaPage_SurveyDetails"; return $this->owner->Customise(array("Survey" => $survey, "BackUrl" => $back_url))->renderWith(array($details_template, 'SangriaPage', 'SangriaPage')); } return $this->owner->httpError(404, 'Sorry that survey could not be found!.'); }
function up() { echo "Starting Proc ...<BR>"; $migration = Migration::get()->filter('Name', $this->title)->first(); if (!$migration) { $migration = new Migration(); $migration->Name = $this->title; $migration->Description = $this->description; $migration->Write(); //run migration $surveys = DeploymentSurvey::get(); foreach ($surveys as $survey) { $survey->SendDigest = 1; $survey->write(); } } else { echo "Migration Already Ran! <BR>"; } echo "Migration Done <BR>"; }
/** * @param ISurvey $survey * @param ISurveyBuilder $survey_builder * @param ISurveyManager $manager */ public function autoPopulate(ISurvey $survey, ISurveyBuilder $survey_builder, ISurveyManager $manager) { $template = $survey->template(); $owner = $survey->createdBy(); $mappings = $template->getAutopopulationMappings(); // get former survey ... $old_survey = DeploymentSurvey::get()->filter('MemberID', $owner->getIdentifier())->sort('Created', 'DESC')->first(); if (is_null($old_survey)) { return; } foreach ($mappings as $mapping) { if (!$mapping instanceof IOldSurveyMigrationMapping) { continue; } $origin_table_name = $mapping->getOriginTableName(); $origin_field_name = $mapping->getOriginFieldName(); $question = $mapping->getTargetQuestion(); if (is_null($question)) { continue; } $step_template = $question->step(); if (is_null($step_template)) { continue; } $step = $survey->getStep($step_template->title()); if (is_null($step)) { continue; } if (!$step instanceof ISurveyRegularStep) { continue; } if ($origin_table_name === 'DeploymentSurvey') { $old_data = $old_survey->{$origin_field_name}; // old data is only a label, we need to find out the value $data = $old_data; if ($question instanceof IMultiValueQuestionTemplate) { $data = ''; if ($question instanceof IDropDownQuestionTemplate && $question->isCountrySelector()) { $data = $old_data; } else { $old_data = explode(',', $old_data); foreach ($old_data as $od) { $v = $question->getValueByValue($od); if (is_null($v)) { continue; } if (!empty($data)) { $data .= ','; } $data .= $v->getIdentifier(); } } } if (empty($data)) { continue; } $step->addAnswer($survey_builder->buildAnswer($question, $data)); } if ($origin_table_name === 'AppDevSurvey') { $app_dev_survey = $old_survey->AppDevSurveys()->first(); if (!$app_dev_survey) { continue; } $old_data = $app_dev_survey->{$origin_field_name}; $data = $old_data; if ($question instanceof IMultiValueQuestionTemplate) { $data = ''; $old_data = explode(',', $old_data); foreach ($old_data as $od) { $v = $question->getValueByValue($od); if (is_null($v)) { continue; } if (!empty($data)) { $data .= ','; } $data .= $v->getIdentifier(); } } if (empty($data)) { continue; } $step->addAnswer($survey_builder->buildAnswer($question, $data)); } } //check if we need to auto-populate entities foreach ($template->getEntities() as $entity_survey) { if ($entity_survey->belongsToDynamicStep() && $entity_survey->shouldPrepopulateWithFormerData()) { $mappings = $entity_survey->getAutopopulationMappings(); $dyn_step = $survey->getStep($entity_survey->getDynamicStepTemplate()->title()); if (is_null($dyn_step)) { continue; } foreach ($old_survey->Deployments() as $old_deployment) { $entity_survey = $manager->buildEntitySurvey($dyn_step, $owner->getIdentifier()); foreach ($mappings as $mapping) { if (!$mapping instanceof IOldSurveyMigrationMapping) { continue; } $origin_table_name = $mapping->getOriginTableName(); $origin_field_name = $mapping->getOriginFieldName(); $question = $mapping->getTargetQuestion(); $step_template = $question->step(); $step = $entity_survey->getStep($step_template->title()); if (!$step instanceof ISurveyRegularStep) { continue; } if ($origin_table_name === 'Deployment') { $old_data = $old_deployment->{$origin_field_name}; $data = $old_data; if ($question instanceof IMultiValueQuestionTemplate) { $data = ''; $old_data = explode(',', $old_data); foreach ($old_data as $od) { $v = $question->getValueByValue($od); if (is_null($v)) { continue; } if (!empty($data)) { $data .= ','; } $data .= $v->getIdentifier(); } } if (empty($data)) { continue; } $step->addAnswer($survey_builder->buildAnswer($question, $data)); } } } } } }
/** * @return bool */ public function hasDeploymentSurveys() { return DeploymentSurvey::get()->filter(array('MemberID' => $this->getIdentifier()))->count() > 0; }
function GetCurrentSurvey() { // Look for an existing survey if ($CurrentUserID = Member::currentUserID()) { // look for a deployment survey for this user $DeploymentSurvey = DeploymentSurvey::get()->filter(array('MemberID' => $CurrentUserID, 'Created:GreaterThanOrEqual' => SURVEY_START_DATE))->first(); if (!$DeploymentSurvey) { // Create a new deployment survey $DeploymentSurvey = new DeploymentSurvey(); $DeploymentSurvey->MemberID = $CurrentUserID; //check if we have an older survey and pre-populate $oldSurvey = DeploymentSurvey::get()->filter(array('MemberID' => $CurrentUserID))->first(); if ($oldSurvey) { $DeploymentSurvey->copyFrom($oldSurvey); } $DeploymentSurvey->CurrentStep = 'AboutYou'; $DeploymentSurvey->HighestStepAllowed = 'AboutYou'; $DeploymentSurvey->UpdateDate = SS_Datetime::now()->Rfc2822(); //old business drivers does not match with current answers $DeploymentSurvey->BusinessDrivers = ''; $DeploymentSurvey->Write(); } return $DeploymentSurvey; } }