CMS  Version 3.9
survey_question.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 
41 
43 {
44  var $fields = array ( "survey_question_id" => Number,
45  "question_type_id" => Number,
46  "question" => HTML,
47  "question_name" => String,
48  "options" => Text,
49  "required" => Number,
50  "char_limit" => Number,
51  "num_rows" => Number,
52  "context_help" => Text
53  );
54 
55  var $relations = array (
56  "Answer" => Answer,
57  "Survey" => Survey,
58  "SurveyQuestionXref" => SurveyQuestionXref,
59  "QuestionType" => QuestionType
60  );
61 
62  // Answer to one object's survey question
63  function Answer($response_id)
64  {
65  $answer = Query::create(SurveyAnswer, "WHERE response_id=:response_id AND survey_question_id=:survey_question_id")
66  ->bind(":response_id", $response_id, ":survey_question_id", $this->survey_question_id)
67  ->executeSingle();
68 
69  return $answer;
70  }
71 
72  function Survey()
73  {
74  return $this->crossReference(Survey, SurveyQuestionXref);
75  }
76 
77  function QuestionType()
78  {
79  return $this->getRelated(QuestionType);
80  }
81 
83  {
84  if($this->survey_question_id)
85  return querySingle(SurveyQuestionXref, "WHERE survey_question_id = {$this->survey_question_id} AND survey_id = $survey_id");
86  }
87 
88  function isEditable()
89  {
90  if(!$this->survey_question_id)
91  return true;
92 
93  $count = queryValue(SurveyAnswer, "COUNT(1)", "WHERE survey_question_id={$this->survey_question_id}");
94 
95  return ($count > 0) ? false : true;
96  }
97 
98 
99  /*
100  * If the question is editable and is linked only to this survey or
101  * survey template, then allow delete. This function is called
102  * from survey_question_form to determine if a user can delete his/her
103  * own question.
104  */
105  function allowDelete()
106  {
107  if(!$this->survey_question_id)
108  return true;
109 
110  if(!$this->isEditable())
111  return false;
112 
113  $count = queryValue(SurveyQuestionXref, "COUNT(1)", "WHERE survey_question_id={$this->survey_question_id}");
114 
115  return ($count > 1) ? false : true;
116  }
117 
118  function SurveyQuestion()
119  {
120  $this->table = "survey_question";
121  $this->primary_key = "survey_question_id";
122 
123  $this->DataItem(func_get_args());
124  }
125 }
126 
127 ?>
return false
Defines the relations and functions required of a Question class that uses Questionnaire form and res...
Definition: question.inc:51
static using()
Import the datamodels, views and manifest for the specified component(s).
Definition: core.inc:116
Answer($response_id)
isEditable()
Returns true if the question can be edited and false if it cannot.
SurveyQuestionXref($survey_id)
$survey_id
$response_id