/** * @param string $response */ private function response($response) { $res = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; $res .= "<Response>\n"; $res .= "<Message>{$response}</Message>\n"; $res .= "</Response>"; $this->response = new SurveyResponse(); $this->response->setHeader("content-type: text/xml"); $this->response->setContent($res); }
protected static function load_response($survey, $id = null) { if (!$id) { $id = $_GET['id']; } $object = SurveyResponse::find_by_id($id); if ($object and $object->survey_id == $survey->id) { return $object; } else { throw new Error404(); } }
public static function load_from_row($row, $recurse_limit = 1, $current_level = 0) { // When PHP 5.3.0 is in, we can shift this over too and just redefine it // if needed (eg. loading child objects) $class = __CLASS__; $object = new $class(); $fields = self::fields_array(); $fields[] = array("created_at", "datetime"); $fields[] = array("updated_at", "datetime"); $fields[] = array("deleted", "bool"); foreach ($fields as $field) { $property = $field[0]; if (isset($field[2])) { $property = $field[2]; } if (isset($row[self::table . ".{$field[0]}"])) { if ($field[1] == "datetime") { $object->{$property} = strtotime($row[self::table . ".{$field[0]}"]); } else { $object->{$property} = $row[self::table . ".{$field[0]}"]; } } else { $object->{$property} = null; } } $object->is_new = false; // Load child objects here if ($current_level < $recurse_limit) { $current_level++; $object->survey = Survey::load_from_row($row, $recurse_limit, $current_level); $object->user = User::load_from_row($row, $recurse_limit, $current_level); $object->question = SurveyQuestion::load_from_row($row, $recurse_limit, $current_level); $object->response = SurveyResponse::load_from_row($row, $recurse_limit, $current_level); } return $object; }
public function completePreSurvey() { $input = Input::all(); //$inputSurvey=$input['survey']; $survey = Survey::find($input['surveyid']); $group = Group::find($input['groupid']); $user = Auth::user(); $response = new SurveyResponse(); $response->user_id = $user->id; $response->group_id = $input['groupid']; $response->survey_id = $input['surveyid']; $response->type = "pre"; $response->response = serialize(""); $response->save(); return ""; }
public function responses($reload = false) { if ($reload or !$this->responses_cache) { $id = mysql_real_escape_string($this->id); $this->responses_cache = SurveyResponse::find_all("surveys.id = '{$id}'"); } return $this->responses_cache; }
, <p> </p> <strong><?php printf(_('The %1$s Crew'), $GLOBALS['sys_name']); ?> </strong> <p> </p> <?php /* Delete this customer's responses in case they had back-arrowed */ $result = db_query("DELETE FROM survey_responses WHERE survey_id='" . addslashes($survey_id) . "' AND group_id='" . addslashes($group_id) . "' AND user_id='" . user_getid() . "'"); /* Select this survey from the database */ $s = new Survey($g, $survey_id); $quest_array =& $s->getQuestionArray(); $count = count($quest_array); $now = time(); /* Make a dummy SurveyResponses for creating */ $sr = new SurveyResponse($g); for ($i = 0; $i < $count; $i++) { /* Insert each form value into the responses table */ $val = "_" . $quest_array[$i]; $response = getStringFromRequest($val); $sr->create(user_getid(), $survey_id, $quest_array[$i], $response); if ($sr->isError()) { echo $sr->getErrorMessage(); } } $sh->footer(array());
/** * * @return type */ public function saveResponse() { if (!$_POST) { App::abort(404); } $input = Input::all(); $survey = Survey::find($input['surveyid']); $group = Group::find($input['groupid']); $user = User::find($input['userid']); if (is_null($survey) || is_null($group) || is_null($user)) { App::abort(404); } $response = new SurveyResponse(); $response->user_id = $input['userid']; $response->group_id = $input['groupid']; $response->survey_id = $input['surveyid']; $response->type = $input['type']; $response->response = serialize($input); $response->save(); return Redirect::to('play/group/' . $group->id)->with('postmessage', $survey->getPostMessage()); }
public function show($permalink = null) { if (isset($_GET['permalink'])) { $permalink = $_GET['permalink']; } $survey = Survey::find_by_permalink($permalink); if (!$survey or !$survey->active && Site::CurrentUser()->isAdmin() == 0) { Error404(); } if ($survey->event->id) { $event_id = mysql_real_escape_string($survey->event_id); $user_id = mysql_real_escape_string(Site::CurrentUser()->id); $result = EventSignup::find("events.id = '{$event_id}' AND users.id = '{$user_id}' AND event_signups.paid"); if (!$result) { Site::Flash("error", "You must have attended {$survey->event->name} to take this survey"); RedirectBack(); } } $user_id = mysql_real_escape_string(Site::CurrentUser()->id); $survey_id = mysql_real_escape_string($survey->id); $response = SurveyResponse::find("surveys.id = '{$survey_id}' AND users.id = '{$user_id}'"); if ($response) { Site::Flash("error", "You have already completed this survey"); Redirect("surveys"); } $response = new SurveyResponse(); $response->survey = $survey; $response->survey_id = $survey->id; $response->user = Site::CurrentUser(); $response->user_id = Site::CurrentUser()->id; $answers = array(); $choices = array(); $valid = true; $errors = array(); if ($this->post) { foreach ($survey->questions() as $question) { $answer = new SurveyAnswer(); $answer->survey_question_id = $question->id; if (in_array($question->type, array("sqtTextbox", "sqtTextArea"))) { // Free-text input if (isset($_POST['question'][$question->id])) { $answer->value = $_POST['question'][$question->id]; } elseif (!$question->required) { continue; } } else { if (isset($_POST['question'][$question->id])) { $chosen = array(); if ($question->type == "sqtCheckbox") { // Checkboxes $chosen = $_POST['question'][$question->id]; } else { // Radio/Select $chosen = array($_POST['question'][$question->id]); } foreach ($chosen as $id) { $option = SurveyQuestionOption::find_by_id($id); if (!$option or $option->question->id != $question->id) { if (!$question->required) { continue; } $valid = false; $answer->add_error("Answer for question {$question->position} is invalid"); $errors[] = $question->id; break; } $choice = new SurveyAnswerChoice(); $choice->survey_question_option_id = $option->id; $choices[$question->id][$option->id] = $choice; } } elseif ($question->required) { $valid = false; $answer->add_error("You must enter an answer for question {$question->position}"); $errors[] = $question->id; } else { continue; } } $result = $answer->validate(); if (!$result) { $valid = false; } $answers[$question->id] = $answer; } if ($valid) { // This is valid, let's save everything! if ($response->save()) { foreach ($answers as $answer) { $answer->survey_response_id = $response->id; $answer->save(); $answers[$answer->survey_question_id] = $answer; } foreach ($choices as $question_id => $answer_choices) { foreach ($answer_choices as $choice) { $choice->survey_answer_id = $answers[$question_id]->id; $choice->save(); } } $account = TwitterAccount::find_by_code('site'); if ($account) { $message = "{$response->user->nickname} has completed the {$survey->name} Survey"; $account->add_tweet($message); } Redirect("surveys/{$survey->permalink}/complete"); } $valid = false; } } $this->assign("answers", $answers); $this->assign("choices", $choices); $this->assign("valid", $valid); $this->assign("survey", $survey); $this->assign("response", $response); $this->assign("errors", $errors); $this->title = $survey->name; $this->render("survey/show.tpl"); }