CMS  Version 3.9
question.inc
Go to the documentation of this file.
1 <?php
7 /**************************************************************
8 
9  Copyright (c) 2010 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 
50 abstract class AbstractQuestion extends DataItem
51 {
52  var $editable = true; // pseudo field
53 
54  var $fieldAliases = array(
55  "char_limit" => "Character Limit for Answer",
56  "num_rows" => "Number of Rows for Answer",
57  "options" => "Options for Answer",
58  "required" => "Answer Required",
59  );
60 
65  abstract function isEditable();
66 
67  abstract function QuestionType();
68 
73  function setDefaultValues()
74  {
75  $this->num_rows = 3;
76  $this->required = 0;
77 
78  $qTypes = Query::create(QuestionType, "ORDER BY sort_order")
79  ->execute();
80 
81  if(count($qTypes) > 0)
82  {
83  $this->question_type_id = $qTypes[0]->question_type_id;
84  }
85  }
86 
87  function isFreeText()
88  {
89  return ($this->question_type_id == 4) ? true : false;
90  }
91 
92  function isShortText()
93  {
94  return ($this->question_type_id == 3) ? true : false;
95  }
96 
97  function isCheckList()
98  {
99  return ($this->question_type_id == 5) ? true : false;
100  }
101 
102  function isRatings()
103  {
104  return ($this->question_type_id == 2) ? true : false;
105  }
106 
107  function isMultiChoice()
108  {
109  return ($this->question_type_id == 1) ? true : false;
110  }
111 
112  function isDropDown()
113  {
114  return ($this->question_type_id == 6) ? true : false;
115  }
116 
117  function isHeading()
118  {
119  return ($this->question_type_id == 7) ? true : false;
120  }
121 
123  {
124  if(!$this->editable)
125  {
126  return "<p><b><i>Note:&nbsp;</i>This question has been answered. You may edit the question but be careful not to change its meaning.</b></p>\n";
127  }
128  }
129 
130  function AbstractQuestion()
131  {
132  }
133 
134 }
135 
137 {
138  var $fields = array ( "question_id" => Number,
139  "questionnaire_id" => Number,
140  "question_number" => Number,
141  "question_type_id" => Number,
142  "question" => HTML,
143  "question_name" => String,
144  "options" => Text,
145  "required" => Number,
146  "char_limit" => Number,
147  "num_rows" => Number,
148  "context_help" => Text
149  );
150 
151  var $relations = array (
152  "Questionnaire" => Questionnaire,
153  "QuestionType" => QuestionType,
154  "Answers" => QuestionnaireAnswer,
155  );
156 
157 
158  function Questionnaire()
159  {
160  return $this->getRelated(Questionnaire);
161  }
162 
163  function QuestionType()
164  {
165  return $this->getRelated(QuestionType);
166  }
167 
168  function Answers($constraint = "")
169  {
170  return $this->getRelatedList(QuestionnaireAnswer, "question_id", $constraint);
171  }
172 
173  function isEditable()
174  {
175  if(!$this->question_id)
176  {
177  return true;
178  }
179 
180  $count = Query::create(QuestionnaireAnswer, "WHERE question_id=:question_id")
181  ->bind(":question_id", $this->question_id)
182  ->executeValue("COUNT(1)");
183 
184  return ($count > 0) ? false : true;
185  }
186 
190  function allowDelete()
191  {
192  if(!$this->question_id)
193  {
194  return false;
195  }
196 
197  $count = count($this->Answers());
198  return ($count > 0) ? false : true;
199  }
200 
201  function Question()
202  {
203  $this->table = "question";
204  $this->primary_key = "question_id";
205 
206  $this->DataItem(func_get_args());
207  }
208 }
209 
210 ?>
$constraint
return false
Defines the relations and functions required of a Question class that uses Questionnaire form and res...
Definition: question.inc:51
setDefaultValues()
Sets the default values for a question object:
Definition: question.inc:73
isEditable()
Returns true if the question can be edited and false if it cannot.
Question()
Definition: question.inc:201
isEditable()
Returns true if the question can be edited and false if it cannot.
Definition: question.inc:173
Answers($constraint="")
Definition: question.inc:168
allowDelete()
Do not allow delete if there are answers linked to the question.
Definition: question.inc:190
QuestionType()
Definition: question.inc:163
Questionnaire()
Definition: question.inc:158
$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