CMS  Version 3.9
abstract_questionnaire_manager.inc
Go to the documentation of this file.
1 <?php
7 Fakoli::using("questionnaire");
8 
9 
72 {
74  {
75  }
76 
85  function getQuestions()
86  {
87  $sort_field = $this->getSortField();
88  $questions = $this->item->Questions("ORDER BY $sort_field");
90  }
91 
103  function getSortableItems()
104  {
105  if($this->getXrefClass())
106  {
107  $relation = pluralize($this->getSortableClass());
108  }
109  else
110  {
111  $relation = "Questions";
112  }
113  $sort_field = $this->getSortField();
114 
115  return $this->item->$relation("ORDER BY $sort_field");
116  }
117 
118  function getSortableClass()
119  {
120  return ($this->getXrefClass()) ? $this->getXrefClass() : $this->getQuestionClass();
121  }
122 
123  function getSortableObj()
124  {
125  $class = $this->getSortableClass();
126  return new $class();
127  }
128 
129  function getSortField()
130  {
131  $obj = $this->getSortableObj();
132  return ($obj->hasField("sort_order")) ? "sort_order" : "question_number";
133  }
134 
138  function getQuestionKey()
139  {
140  $qClass = $this->getQuestionClass();
141  $question = new $qClass();
142  return $question->getPrimaryKey();
143  }
144 
151  {
152  return QuestionnaireHelper::getQuestionNumber($this->item, $this->getQuestions(), $question);
153  }
154 
155  function getAnswerKey()
156  {
157  $class = $this->getAnswerClass();
158  $obj = new $class();
159  return $obj->getPrimaryKey();
160  }
161 
162  function getPrimaryKey()
163  {
164  return $this->item->getPrimaryKey();
165  }
166 
167 } // end AbstractQuestionnaireManager
168 
169 
170 
184 {
186  {
187 
188  }
189 
190  static function getQuestionNumber($item, $questions, $question)
191  {
192  if(count($questions) > 0)
193  {
194  $idx = 1;
195  foreach($questions as $q)
196  {
197  $renderer = QuestionField::create($item, $q);
198 
199  if (!$renderer->skipNumbering)
200  {
201  $idx++;
202  }
203 
204  if ($question->question_id == $q->question_id) return $idx;
205  }
206  }
207  return "";
208  }
209 
217  static function setQuestionNumbers($item, $questions)
218  {
219  if(count($questions) == 0) return $question;
220 
221  $idx = 1;
222  foreach($questions as $question)
223  {
225 
226  if (!$renderer->skipNumbering)
227  {
228  $question->question_number = $idx;
229  $idx++;
230  }
231  }
232  return $questions;
233  }
234 
235 
243  {
244  if(!$question->question_name)
245  $question->question_name = substr($question->question, 0, 79);
246 
247  $pk = $question->getPrimaryKey();
248  return $question->format("<input type='text' name=\"question_{$question->$pk}\"
249  value=\"{question_name}\" size=\"40\"/>");
250  }
251 
252 } // end QuestionnaireHelper
253 ?>
Questionnaire/Survey Implementation instructions.
getQuestionNumber($question)
Called by QuestionRenderers from QuestionnaireForm Given an instance of a question,...
getQuestionKey()
Returns the primar key name of the question obj.
getSortableItems()
Retrieves the table that has the question sort order field either Question or a QuestionXref.
getQuestions()
Retrieves questions through the questionnaire or survey DataItem object.
static using()
Import the datamodels, views and manifest for the specified component(s).
Definition: core.inc:116
static create($parent, $question)
Provides static function support for Questionnaire Manager methods that are shared among types Questi...
static setQuestionNumbers($item, $questions)
Given an array of question objects, set the question_number field or pseudo field so that Question Re...
static getQuestionNumber($item, $questions, $question)
static formatQuestionNameInputField($question)
On the question names dialog, format the input field for editing the question names.
$question
$renderer