CMS  Version 3.9
survey_response.inc
Go to the documentation of this file.
1 <?php
7 /**************************************************************
8 
9 Copyright (c) 2007,2008 Sonjara, Inc
10 
11 Permission is hereby granted, free of charge, to any person
12 obtaining a copy of this software and associated documentation
13 files (the "Software"), to deal in the Software without
14 restriction, including without limitation the rights to use,
15 copy, modify, merge, publish, distribute, sublicense, and/or sell
16 copies of the Software, and to permit persons to whom the
17 Software is furnished to do so, subject to the following
18 conditions:
19 
20 The above copyright notice and this permission notice shall be
21 included in all copies or substantial portions of the Software.
22 
23 Except as contained in this notice, the name(s) of the above
24 copyright holders shall not be used in advertising or otherwise
25 to promote the sale, use or other dealings in this Software
26 without prior written authorization.
27 
28 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
30 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
32 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
33 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
34 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
35 OTHER DEALINGS IN THE SOFTWARE.
36 
37 *****************************************************************/
38 
39 Fakoli::using("questionnaire");
40 
42 {
43  var $fields = array (
44  "response_id" => Number,
45  "survey_id" => Number,
46  "token" => String,
47  "email" => String,
48  "last_modified" => Date,
49  "status" => String,
50  "include_in_results" => Boolean,
51  );
52 
53  var $fieldAliases = array(
54  "include_in_results" => "Include in Reslts",
55  );
56 
57  var $relations = array (
58  "Questions" => Questions,
59  "Answers" => SurveyAnswer,
60  "Survey" => Survey,
61  );
62 
63  var $statusTypes = array(
64  "not_started" => "Not Started",
65  "in_progress" => "In Progress",
66  "submitted" => "Submitted",
67  );
68 
69  function Questions()
70  {
71  $survey = $this->Survey();
72 
73  if($survey)
74  $questions = $survey->Questions();
75 
76  return $questions;
77  }
78 
79  function Survey()
80  {
81  return $this->getRelated(Survey);
82  }
83 
84  function Answers($constraint = "")
85  {
86  $answers = array();
87  $questions = $this->Questions();
88  foreach($questions as $question)
89  {
90  $answer = querySingle(SurveyAnswer, "WHERE response_id = {$this->response_id} AND survey_question_id = $question->survey_question_id");
91  if($answer)
92  array_push($answers, $answer);
93  }
94 
95  return $answers;
96  }
97 
98  function Questionnaire()
99  {
100  return $this->Survey()->Questionnaire();
101  }
102 
103  function isSubmitted()
104  {
105  return ($this->status != "submitted") ? false : true;
106  }
107 
108  function isEditable()
109  {
110  return ($this->status != "submitted") ? true : false;
111  }
112 
113 
114  function setStatus($status)
115  {
116  $this->last_modified = date('Y-m-d');
117  $this->filter = new InclusionFilter("status", "last_modified");
118  $this->status = $status;
119  $rtn = $this->save();
120  }
121 
123  {
124  $responses = Query::create(SurveyResponse, "WHERE survey_id=:survey_id AND token=:token")
125  ->bind(":survey_id", $survey_id, ":token", $token)
126  ->execute();
127 
128  return (count($responses) > 0) ? $responses[0] : null;
129  }
130 
131 
132  function setDefaults()
133  {
134  $this->status = "not_started";
135  $this->include_in_results = true;
136  }
137 
138  /*
139  * merge_code
140  *
141  * Allow a user to get to a survey landing page with just the survey_id
142  * and they can enter the token from there.
143  *
144  * Called by merge code and response tester block
145  */
146  function getEditUrl()
147  {
148  $mgr = new SurveyResponseManager($this);
149  return $mgr->getEditUrl($this->Survey());
150  }
151 
157  function getIntroUrl()
158  {
159  $mgr = new SurveyResponseManager($this);
160  return $mgr->getIntroUrl($this->Survey());
161  }
162 
163  function isTester()
164  {
165  return ($this->include_in_results) ? false : true;
166  }
167 
169  {
170  $this->include_in_results = false;
171  $this->filter = new InclusionFilter("include_in_results");
172  $this->save();
173  }
174 
175 
179  function reset()
180  {
181  if(!$this->response_id) return;
182  if(!$this->isTester()) return;
183 
184  $this->setStatus("not_started");
185  $answer = new SurveyAnswer();
186  $answer->delete("WHERE response_id={$this->response_id}");
187  }
188 
189 
190  function SurveyResponse()
191  {
192  $this->table = "survey_response";
193  $this->primary_key = "response_id";
194  $this->answer_class = SurveyAnswer;
195 
196  $this->DataItem(func_get_args());
197  }
198 }
199 
200 
201 ?>
$constraint
$table filter
return false
$progress status
static using()
Import the datamodels, views and manifest for the specified component(s).
Definition: core.inc:116
reset()
reinitialize token for a test user.
Answers($constraint="")
setStatus($status)
Set the response status and save.
static findResponseByToken($survey_id, $token)
excludeResponse($include_in_results=false)
$survey_id
if(! $survey_id) $survey
$question
$answers
$table column("Redirect From", "<a href='redirect_form?redirect_id={redirect_id}'>{redirect_from}</a>", true, "width: 30%") -> column("Redirect To", "<a href='{redirect_to}' target='_blank'>{redirect_to}</a>", true, "width: 30%") ->column("Last Modified", "{last_modified}", true, "width: 20%; text-align: center") ->column("Override", "{ override true
Definition: redirects.inc:9
$response include_in_results
$include_in_results