CMS  Version 3.9
QuestionnaireDataView Class Reference

Public Member Functions

 QuestionnaireDataView ($mgr)
 
 getAggregateData ($question, $answers)
 
 getSingleSelectQuestionResultData ($question, $answers)
 
 getRatingsQuestionResultData ($question, $answers)
 
 getOptionText ($options)
 
 getMean ($counts)
 
 getMedian ($optionAnswers)
 
 getCheckListQuestionResultData ($question, $answers)
 
 writeScript ()
 
 buildOptionDataView ()
 
 getGroupTitle ($question)
 
 buildTextDataView ()
 
 drawView ()
 
 getHeading ()
 

Static Public Member Functions

static getCheckListAnswerCounts ($answers)
 
static formatQuestion ($question)
 
static formatAnswer ($answer)
 

Public Attributes

 $obj
 
 $survey
 
 $questions
 
 $answers
 
 $emptyMessage = "There are no results."
 
 $optionDataView
 
 $textDataView
 
 $optionAnswers
 
 $textAnswers
 
 $responseCount
 

Detailed Description

Definition at line 37 of file questionnaire_data_view.inc.

Member Function Documentation

◆ buildOptionDataView()

QuestionnaireDataView::buildOptionDataView ( )

Definition at line 330 of file questionnaire_data_view.inc.

331  {
332  $dataView = new GroupedDataListView($this->optionAnswers, "OptionDataList");
333  $dataView->column("Option", "{option}", false, "width: 90%")
334  ->column("Count", "{count}", false, "width: 10%");
335  $dataView->groupBy($this->questions, array($this, getGroupTitle));
336  $dataView->mode = 'tree';
337  $dataView->emptyMessage = "There are no aggregated data results.";
338  $dataView->excelFile = "option_surveyData.xls";
339  $this->optionDataView = $dataView;
340  }

◆ buildTextDataView()

QuestionnaireDataView::buildTextDataView ( )

Definition at line 350 of file questionnaire_data_view.inc.

351  {
352  $table = new GroupedDataListView($this->textAnswers, "AnswerTextList");
353  $table->column("Answer Text", array(QuestionnaireDataView, formatAnswer));
354  $table->groupBy($this->questions, array(QuestionnaireDataView, formatQuestion));
355  $table->mode = 'tree';
356  $table->emptyMessage = "There are no text results.";
357  $table->excelFile = "text_surveyData.xls";
358 
359  $this->textDataView = $table;
360  }

◆ drawView()

QuestionnaireDataView::drawView ( )

Definition at line 374 of file questionnaire_data_view.inc.

375  {
376  echo $this->getHeading();
377  $this->optionDataView->drawView();
378  echo "<h4>Free Text Responses</h4>";
379  $this->textDataView->drawView();
380  }

◆ formatAnswer()

static QuestionnaireDataView::formatAnswer (   $answer)
static

Definition at line 368 of file questionnaire_data_view.inc.

369  {
370  return ($answer->value) ? $answer->value : "Not Answered";
371  }

◆ formatQuestion()

static QuestionnaireDataView::formatQuestion (   $question)
static

Definition at line 363 of file questionnaire_data_view.inc.

364  {
365  return $question->question_number . ". " . $question->question;
366  }
$question

◆ getAggregateData()

QuestionnaireDataView::getAggregateData (   $question,
  $answers 
)

Definition at line 79 of file questionnaire_data_view.inc.

80  {
81  $qPk = $this->mgr->getQuestionKey();
82 
83  $questionType = new QuestionType($question->question_type_id);
84 
85  switch($questionType->class_name)
86  {
87  case MultipleChoiceView:
88 
89  $this->optionAnswers[$question->$qPk] = $this->getSingleSelectQuestionResultData($question, $answers);
90  break;
91 
92  case RatingView:
93 
94  $this->optionAnswers[$question->$qPk] = $this->getRatingsQuestionResultData($question, $answers);
95  break;
96 
97  case ShortTextView:
98 
99  $this->textAnswers[$question->$qPk] = $answers;
100  break;
101 
102  case FreeTextView:
103 
104  $this->textAnswers[$question->$qPk] = $answers;
105  break;
106 
107  case CheckListView:
108 
109  $this->optionAnswers[$question->$qPk] = $this->getCheckListQuestionResultData($question, $answers);
110  break;
111 
112  case SelectFieldView:
113 
114  $this->optionAnswers[$question->$qPk] = $this->getSingleSelectQuestionResultData($question, $answers);
115  break;
116 
117  case HeadingView:
118  break;
119 
120  default:
121 
122  trace("getAggregateData: Unknown question type {$questionType->class_name}", 2);
123  die("QuestionniareDataView getAggregateData: Unknown question type {$questionType->class_name}");
124  }
125 
126  }
getCheckListQuestionResultData($question, $answers)
getRatingsQuestionResultData($question, $answers)
getSingleSelectQuestionResultData($question, $answers)

◆ getCheckListAnswerCounts()

static QuestionnaireDataView::getCheckListAnswerCounts (   $answers)
static

Definition at line 295 of file questionnaire_data_view.inc.

296  {
297  if(count($answers) == 0)
298  return;
299 
300  $count = array();
301 
302  foreach($answers as $answer)
303  {
304  $values = $answer->value;
305 
306  // include 0 value, first checkbox
307  if(strlen($values)==1 AND is_numeric($values))
308  $values = array($values);
309  elseif(strlen($values)==0)
310  $values = "";
311  else
312  $values = explode(",", $values);
313 
314  foreach($values as $value => $idx)
315  {
316  $count[$idx] += 1;
317  }
318  }
319  return $count;
320  }
foreach( $events as $event)
Definition: event_list.inc:60
if(! $process) else

◆ getCheckListQuestionResultData()

QuestionnaireDataView::getCheckListQuestionResultData (   $question,
  $answers 
)

Definition at line 271 of file questionnaire_data_view.inc.

272  {
273  $qPk = $this->mgr->getQuestionKey();
274  $options = explode("\n", $question->options);
275  $idx = 1;
276 
277  // Explode and record the count of each value answer
278  $answerCounts = $this->getCheckListAnswerCounts($answers);
279  if(count($options) > 0)
280  {
281  $optionAnswers = array();
282 
283  foreach($options as $option)
284  {
285  $count = $answerCounts[$idx];
286  if (!isset($count)) $count = 0;
287  $optionAnswer = new OptionAnswer($question->$qPk, $idx, $option, $count);
288  array_push($optionAnswers, $optionAnswer);
289  $idx++;
290  }
291  }
292  return $optionAnswers;
293  }
static getCheckListAnswerCounts($answers)

◆ getGroupTitle()

QuestionnaireDataView::getGroupTitle (   $question)

Definition at line 343 of file questionnaire_data_view.inc.

344  {
346  return "{$question->question_number}. {$question->question} " . $questionTypes[$question->question_type];
347  }
static getQuestionTypeList()
$questionTypes

◆ getHeading()

QuestionnaireDataView::getHeading ( )

Definition at line 390 of file questionnaire_data_view.inc.

391  {
392  $fn = array($this->mgr, formatResultsHeading);
393  if (is_callable($fn))
394  {
395  return call_user_func($fn);
396  }
397 
398  $recipientCount = $this->mgr->getRecipientCount();
399 
400  $countText = ($this->responseCount) ? $this->responseCount : "0";
401  $text = "<h3>Aggregated Survey Answers based on $countText ";
402  $text .= ($recipientCount) ? "out of $recipientCount " : "";
403  $text .= "Respondents</h3>\n";
404 
405  return $text;
406  }

◆ getMean()

QuestionnaireDataView::getMean (   $counts)

Definition at line 210 of file questionnaire_data_view.inc.

211  {
212  $total = 0;
213  $num = 0;
214 
215  foreach($counts as $value => $count)
216  {
217  $total += $value * $count;
218  $num += $count;
219  }
220 
221  $mean = ($num > 0) ? round($total / $num, 2) : 0;
222  return $mean;
223  }

◆ getMedian()

QuestionnaireDataView::getMedian (   $optionAnswers)

Definition at line 229 of file questionnaire_data_view.inc.

230  {
231  $median = 0.0;
232  $index_1 = 0;
233  $index_2 = 0;
234 
235  // determine if odd or even
236  $no_elements = count($optionAnswers);
237  //echo "no elements is $no_elements<br/>";
238  $odd = $no_elements % 2;
239 
240  //odd take the middle number
241  if ($odd == 1)
242  {
243  //determine the middle
244  $the_index_1 = $no_elements / 2;
245 
246  //cast to integer
247  settype($the_index_1, "integer");
248 
249  //calculate the median
250  $median = $optionAnswers[$the_index_1]->option;
251  }
252  else
253  {
254  //determine the two middle numbers
255  $the_index_1 = $no_elements / 2;
256  $the_index_2 = $the_index_1 - 1;
257 
258  //calculate the median
259  $median = ($optionAnswers[$the_index_1] + $optionAnswers[$the_index_2]) / 2;
260  }
261 
262  return $median;
263  }

◆ getOptionText()

QuestionnaireDataView::getOptionText (   $options)

Definition at line 191 of file questionnaire_data_view.inc.

192  {
193  $optionText = array();
194 
195  list($from, $to, $steps) = explode("\n", $options);
196  if (!$from) $from = "Lowest";
197  if (!$to) $to = "Highest";
198  if (!$steps) $steps = 5;
199 
200  for($idx = 1; $idx <= $steps; ++$idx)
201  {
202  if($idx > 1 AND $idx < $steps)
203  $optionText[$idx] = $idx;
204  else
205  $optionText[$idx] = ($idx == 1) ? $from : $to;
206  }
207  return $optionText;
208  }

◆ getRatingsQuestionResultData()

QuestionnaireDataView::getRatingsQuestionResultData (   $question,
  $answers 
)

Definition at line 163 of file questionnaire_data_view.inc.

164  {
165  $qPk = $this->mgr->getQuestionKey();
166  if(count($answers) > 0)
167  $answerValues = regroupList($answers, "value");
168 
169  $optionAnswers = array();
170  $count = array();
171  $optionText = $this->getOptionText($question->options);
172  $steps = count($optionText);
173 
174  for($idx = 1; $idx <= $steps; ++$idx)
175  {
176  //echo "idx is $idx<br/>";
177  // store for calculating mean and median
178  $counts[$idx] = count($answerValues[$idx]);
179  $optionAnswer = new OptionAnswer($question->$qPk, $idx, $optionText[$idx], $counts[$idx]);
180  array_push($optionAnswers, $optionAnswer);
181  }
182 
183  $mean = new OptionAnswer($question->$qPk, ++$idx, "Mean", $this->getMean($counts));
184  //$median = new OptionAnswer($question->$qPk, ++$idx, "Median", $this->getMedian($optionAnswers));
185  array_push($optionAnswers, $mean);
186  //array_push($optionAnswers, $median);
187 
188  return $optionAnswers;
189  }

◆ getSingleSelectQuestionResultData()

QuestionnaireDataView::getSingleSelectQuestionResultData (   $question,
  $answers 
)

Definition at line 132 of file questionnaire_data_view.inc.

133  {
134  $qPk = $this->mgr->getQuestionKey();
135  $options = explode("\n", $question->options);
136  $idx = 1;
137 
138  if(count($options) > 0)
139  {
140  if(count($answers) > 0)
141  $answerValues = regroupList($answers, "value");
142  else
143  $answerValues = array();
144  $optionAnswers = array();
145 
146  foreach($options as $option)
147  {
148  $count = count($answerValues[$idx]);
149  $optionAnswer = new OptionAnswer($question->$qPk, $idx, $option, $count);
150  array_push($optionAnswers, $optionAnswer);
151  $idx++;
152 
153  }
154  return $optionAnswers;
155  }
156  }

◆ QuestionnaireDataView()

QuestionnaireDataView::QuestionnaireDataView (   $mgr)

Definition at line 50 of file questionnaire_data_view.inc.

51  {
52  $this->mgr = $mgr;
53  $this->survey = $this->mgr->item;
54  $qPk = $this->mgr->getQuestionKey();
55 
56  $this->questionTypes = QuestionType::getQuestionTypeList();
57 
58  $this->questions = $this->mgr->getQuestions();
59 
60  if(count($this->questions) > 0)
61  $answers = $this->mgr->getAnswers();
62 
63  if(count($answers) > 0)
64  {
65  $this->responseCount = $this->mgr->getResponseCount();
66  $this->answers = regroupList($answers, $qPk);
67 
68  foreach($this->questions as $question)
69  {
70  $answers = $this->answers[$question->$qPk];
71  $this->getAggregateData($question, $answers);
72  }
73  }
74 
75  $this->buildOptionDataView();
76  $this->buildTextDataView();
77  }
getAggregateData($question, $answers)

◆ writeScript()

QuestionnaireDataView::writeScript ( )

Definition at line 322 of file questionnaire_data_view.inc.

323  {
324  $script = $this->optionDataView->writeScript();
325  $script .= $this->textDataView->writeScript();
326  return $script;
327  }

Member Data Documentation

◆ $answers

QuestionnaireDataView::$answers

Definition at line 42 of file questionnaire_data_view.inc.

◆ $emptyMessage

QuestionnaireDataView::$emptyMessage = "There are no results."

Definition at line 43 of file questionnaire_data_view.inc.

◆ $obj

QuestionnaireDataView::$obj

Definition at line 39 of file questionnaire_data_view.inc.

◆ $optionAnswers

QuestionnaireDataView::$optionAnswers

Definition at line 46 of file questionnaire_data_view.inc.

◆ $optionDataView

QuestionnaireDataView::$optionDataView

Definition at line 44 of file questionnaire_data_view.inc.

◆ $questions

QuestionnaireDataView::$questions

Definition at line 41 of file questionnaire_data_view.inc.

◆ $responseCount

QuestionnaireDataView::$responseCount

Definition at line 48 of file questionnaire_data_view.inc.

◆ $survey

QuestionnaireDataView::$survey

Definition at line 40 of file questionnaire_data_view.inc.

◆ $textAnswers

QuestionnaireDataView::$textAnswers

Definition at line 47 of file questionnaire_data_view.inc.

◆ $textDataView

QuestionnaireDataView::$textDataView

Definition at line 45 of file questionnaire_data_view.inc.


The documentation for this class was generated from the following file: