CMS  Version 3.9
abstract_questionnaire_results_manager.inc
Go to the documentation of this file.
1 <?php
7 Fakoli::using("questionnaire");
8 Fakoli::usingFile("/cms/components/questionnaire/abstract_questionnaire_manager.inc");
9 
22 abstract class AbstractQuestionnaireResultsManager extends AbstractQuestionnaireManager
23 {
24  var $item;
25 
26  function AbstractQuestionnaireResultsManager($item)
27  {
28  $this->item = $item;
29  }
30 
34  abstract function getComponentName();
35 
39  abstract function getQuestionClass();
40 
47  abstract function getXrefClass();
48 
54  abstract function Responses();
55 
56 
67  abstract function getResponseManager($response);
68 
69  abstract function getResponseClass();
70 
76  abstract function getRespondentColumnHeading();
77 
82  function getRespondentColumnFormat()
83  {
84  return "{name}";
85  }
86 
91  function addRespondentAdditionalColumns($table)
92  {
93  return $table;
94  }
95 
100  abstract function getRecipientCount();
101 
107  function getAnswers()
108  {
109  return $this->item->Answers();
110  }
111 
112  function getQuestionNamesHandler()
113  {
114  return "question_names_dialog";
115  }
116 
117  function getResponseViewDialog()
118  {
119  return "response_view";
120  }
121 
129  function formatResponseLink($response)
130  {
131  $pk = $response->getPrimaryKey();
132 
133  $mgr = $this->getResponseManager($response);
134  $respondent = $mgr->getRespondent();
135 
136  if($response->isSubmitted())
137  return $response->format("<a href='#' onclick=\"questionnaireMgr.showResponse('{$pk}', {{$pk}}); return false\">$respondent</a>");
138  else
139  return $respondent;
140  }
141 
145  function getResponseViewTitle()
146  {
147  return $this->item->prettifyClassName() . " Response";
148  }
149 
150 
156  function getQuestionNumber($question)
157  {
158  return QuestionnaireHelper::getQuestionNumber($this->item, $this->getQuestions(), $question);
159  }
160 
164  function getResponseCount()
165  {
166  return count($this->Responses());
167  }
168 
173  function getProgressBar()
174  {
175  $percentage = 0;
176  $total = $this->getRecipientCount();
177  if($total > 0)
178  {
179  $responseCount = $this->getResponseCount();
180  $percentage = round($responseCount / $total * 100, 0);
181  }
182  if(!$responseCount) $responseCount = 0;
183 
184  $html .= $percentage . "%";
185  $html .= " <span style='font-size: 8pt'>($responseCount&nbsp;of&nbsp;$total)</span>";
186  $html .= "<div class='progress_bar'>\n";
187  $html .= "<div class='progress' style='width: $percentage%'>\n";
188  $html .= "</div></div>\n";
189  return $html;
190  }
191 
192  function drawEditQuestionNamesButton()
193  {
194  $pk = $this->item->getPrimaryKey();
195  echo $this->item->format("<p><a class='button' href='#' onclick=\"questionnaireMgr.showQuestionNamesDialog({{$pk}});
196  return false;\">Edit Column Headings</a></p>\n");
197  }
198 
202  function buildQuestionNamesForm()
203  {
204  $item = $this->item;
205  $component = $this->getComponentName();
206  $handler = $this->getQuestionNamesHandler();
207  $pk = $item->getPrimaryKey();
208 
209  $item->filter = new InclusionFilter();
210  $form = new AutoForm($item, "POST", "/action/{$component}/{$handler}?$pk={$item->$pk}", "QuestionNames_form");
211  $form->ajaxSubmit("function(result) {new questionnaireMgr.questionNamesFormResult(result);}", "function() {document.id('{$form->id}_error').set('text','Failed to communicate with server'); }");
212 
213  $questions = $this->getQuestions();
214  $table = new DataListView($questions, "QuestionnaireQuestions");
215  $table->column("Question", "{question}")
216  ->column("Question Name", array(QuestionnaireHelper, formatQuestionNameInputField), false)
217  ;
218 
219  $table->emptyMessage = "There are no questions defined.";
220  $table->sortable = false;
221  $table->cssStyle = "width: 100%";
222 
223  $questionSelect = new DataListFieldRenderer($form, $table, "questionnaire_questions");
224  $questionSelect->hideLabel = true;
225  $form->submitLabel = "Save Question Names";
226  $questionSelect->onPostProcess = array($this, saveQuestionNames);
227 
228  if(count($questions) == 0)
229  {
230  $form->readOnlyForm = true;
231  }
232  return $form;
233  }
234 
235 
240  function saveQuestionNames()
241  {
242  global $_POST;
243  $qClass = $this->getQuestionClass();
244 
245  foreach($_POST as $name => $value)
246  {
247  if (!strncmp($name, "question_", 9))
248  {
249  $id = substr($name, 9);
250  checkNumeric($id);
251  $question = new $qClass($id);
252  $question->question_name = $value;
253  $question->filter = new InclusionFilter("question_name");
254  $question->save();
255  }
256  }
257  return true;
258  }
259 
267  function formatIncludeInResultsLink($response)
268  {
269  $img = $response->include_in_results ? "on.png" : "off.png";
270  $alt = $response->include_in_results ? "include_in_results" : "exclude_from_results";
271  $fn = $response->include_in_results ? "excludeResponse" : "includeResponse";
272 
273  return $response->format("<a href='#' onclick=\"questionnaireMgr.$fn({response_id}); return false;\"><img src='/fakoli/images/$img' alt='$alt' style='display: inline-block; vertical-align: middle; border: none;'/></a>");
274  }
275 
288  function writeScript()
289  {
290  $itemPk = $this->item->getPrimaryKey();
291  $item_id = $this->item->$itemPk;
292  $component_name = $this->getComponentName();
293  $question_names_dialog = "question_names_dialog";
294  $response_view_dialog = $this->getResponseViewDialog();
295  $response_view_title = $this->getResponseViewTitle();
296 
297  $response_class = $this->getResponseClass();
298  $mgr = $this->getResponseManager(new $response_class());
299  $exclude_handler = $mgr->getExcludeHandler();
300  $responsePk = $mgr->item->getPrimaryKey();
301 
302  ob_start();
303  ?>
304 <script type="text/javascript" src="/components/questionnaire/js/questionnaire_results.js"></script>
305 <script type="text/javascript">
306 var questionnaireMgr;
307 
308 window.addEvent('domready', function()
309 {
310  questionnaireMgr = new QuestionnaireResultsManager('<?php echo $itemPk ?>',
311  <?php echo $item_id ?>, '<?php echo $component_name ?>',
312  '<?php echo $question_names_dialog ?>',
313  '<?php echo $response_view_dialog ?>',
314  '<?php echo $response_view_title ?>',
315  '<?php echo $exclude_handler ?>',
316  '<?php echo $responsePk ?>'
317  );
318 });
319 
320 </script>
321 <?
322  $script .= ob_get_contents();
323  ob_end_clean();
324 
325  return $script;
326  }
327 
328 } // end AbstractQuestionnaireResultsManager
329 ?>
$form
$_POST["owner_id"]
Definition: blog_form.inc:54
$handler
Definition: event_form.inc:62
$component
Definition: help.inc:38
$name
Definition: upload.inc:54
Questionnaire/Survey Implementation instructions.
getQuestionNumber($question)
Called by QuestionRenderers from QuestionnaireForm Given an instance of a question,...
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 usingFile()
Uses the specified framework file(s) from the framework directory.
Definition: core.inc:369
Provides static function support for Questionnaire Manager methods that are shared among types Questi...
static getQuestionNumber($item, $questions, $question)
$question
if(! $user) if(! $response_id) $response