function index() { $posts = $this->request->postVars(); $filename = $posts['filename']; $surveyID = intval($posts['surveyID']); if (!$filename || !Member::currentUser() || !$surveyID || !($Survey = Survey::get()->filter('ID', $surveyID)->first())) { return false; } $folder = Folder::find_or_make('jsonFormFiles'); $fullFileName = Director::baseFolder() . '/' . $folder->getRelativePath() . $filename . '.json'; $jsonString = '{"name":"' . $Survey->Name . '","startDate": "' . $Survey->StartDate . '", "endDate": "' . $Survey->EndDate . '","sections": ['; foreach ($Survey->Sections() as $Section) { $jsonString .= '{"Title": "' . $Section->Title . '","Descripton": "' . $Section->Description . '","sectionQuestions": ['; foreach ($Section->SurveyQuestions() as $SQ) { $jsonString .= '{"number": "' . $SQ->Number . '","title": "' . $SQ->Title . '","description":"' . $SQ->Description . '","helpText": "' . $SQ->HelpText . '","questions": ['; foreach ($SQ->Questions() as $Question) { $jsonString .= $Question->renderJson(); } $jsonString = rtrim($jsonString, ","); $jsonString .= ']},'; } $jsonString = rtrim($jsonString, ","); $jsonString .= ']},'; } $jsonString = rtrim($jsonString, ","); $jsonString .= ']}'; file_put_contents($fullFileName, $jsonString); $Survey->LastJsonGenerated = SS_Datetime::now()->getValue(); $Survey->write(); }
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!.'); }
/** * @return bool */ public function hasSurveys() { return Survey::get()->filter(array('CreatedByID' => $this->getIdentifier()))->count() > 0; }
public function DeploymentDetails(SS_HTTPRequest $request) { $params = $request->allParams(); $deployment_id = intval(Convert::raw2sql($params["ID"])); //get survey version $deployment = Survey::get()->byID($deployment_id); if ($deployment->ClassName === 'EntitySurvey') { $deployment = EntitySurvey::get()->byID($deployment_id); } if (!$deployment) { return $this->owner->httpError(404, 'Sorry that Deployment could not be found!.'); } $back_url = $request->getVar('BackUrl'); if (empty($back_url)) { $back_url = $this->owner->Link("ViewDeploymentDetails"); } $data = ["Name" => 'Deployment', "Survey" => $deployment, "BackUrl" => $back_url]; return $this->owner->Customise($data)->renderWith(array('SangriaPage_SurveyBuilderSurveyDetails', 'SangriaPage', 'SangriaPage')); }