CMS  Version 3.9
questionnaire_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 abstract class AbstractQuestionnaireResponse extends DataItem
40 {
42  {
43 
44  }
45 
46  abstract function Questions();
47 
52  abstract function Answers();
53 
54  abstract function isSubmitted();
55 
56  abstract function isEditable();
57 
58  abstract function setDefaults();
59 
63  abstract function setStatus($status);
64 
65 
66 }
67 
69 {
70  var $fields = array (
71  "response_id" => Number,
72  "questionnaire_id" => Number,
73  "user_id" => Number,
74  "date_submitted" => DateTime,
75  "status" => String,
76  );
77 
78  var $relations = array (
79  "Questions" => Questions,
80  "Answers" => QuestionnaireAnswer,
81  "Questionnaire" => Questionnaire,
82  );
83 
84  var $statusTypes = array(
85  "not_started" => "Not Started",
86  "in_progress" => "In Progress",
87  "submitted" => "Submitted",
88  );
89 
90 
91  function Questions()
92  {
93  $questionnaire = $this->Questionnaire();
94 
95  if($questionnaire)
96  $questions = $questionnaire->Questions();
97 
98  return $questions;
99  }
100 
101  function Questionnaire()
102  {
103  return $this->getRelated(Questionnaire);
104  }
105 
106  function Answers($constraint = "")
107  {
108  if(!$this->response_id)
109  {
110  return null;
111  }
112  return $this->getRelatedList(QuestionnaireAnswer, "response_id", $constraint);
113  }
114 
115  function isSubmitted()
116  {
117  return ($this->status != "submitted") ? false : true;
118  }
119 
120  function setDefaults()
121  {
122  $this->status = "not_started";
123  }
124 
125  function isEditable()
126  {
127  return ($this->status != "submitted") ? true : false;
128  }
129 
130  function setStatus($status)
131  {
132  $this->date_submitted = date('Y-m-d');
133  $this->status = $status;
134  $this->filter = new InclusionFilter("status", "date_submitted");
135  $this->save();
136  }
137 
139  {
140  $this->table = "questionnaire_response";
141  $this->primary_key = "response_id";
142 
143  $this->DataItem(func_get_args());
144 
145  $this->default_format = "{Respondent.first_name} {Respondent.last_name}";
146  }
147 }
148 
149 
150 
151 /*
152  * Dummy dataitem class to enable use of dataview on
153  * option results
154  */
155 class OptionAnswer extends DataItem
156 {
157  var $fields = array(
158  "question_id" => Number,
159  "option_number" => Number, // position in list
160  "option" => String,
161  "count" => Number
162  );
163 
164  function OptionAnswer($question_id, $option_number, $option, $count)
165  {
166  $this->table = "option_answer";
167  $this->primary_key = "question_id";
168  $this->question_id = $question_id;
169  $this->option_number = $option_number;
170  $this->option = $option;
171  $this->count = $count;
172  }
173 }
174 
175 
180 class SpreadsheetResponse extends DataItem
181 {
182  var $fields = array(
183  "name" => String,
184  //question/answer fields built at run time
185  );
186 
188  {
189  $this->table = "spreadsheet_response";
190 
191  // pk value does not need to match questionnaire item
192  $this->primary_key = "questionnaire_id";
193 
194  $this->DataItem(func_get_args());
195  }
196 }?>
$constraint
$table filter
return false
$progress status
Answers()
If key field is not null, retrieve the answers linked to this respondent.
setStatus($status)
Set the response status and save.
OptionAnswer($question_id, $option_number, $option, $count)
setStatus($status)
Set the response status and save.
Dummy datamodel for building SpreadsheetView.
if(! $questionnaire_id) $questionnaire
$question_id
$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