CMS  Version 3.9
QuestionnaireResultsGraph Class Reference

Draws a graph of the aggregated answers for a given question. More...

Static Public Member Functions

static drawSelectGraph ($question, $resultsManager, $answers)
 Draws an interactive graphical view of answers to one question. More...
 
static drawChecklistGraph ($question, $resultsManager, $answers)
 Draws an interactive graphical view of answers to one question. More...
 
static drawRatingsGraph ($question, $resultsManager, $answers)
 Draws an interactive graphical view of answers to one question. More...
 
static drawSelectResults ($surveyField, $qField, $survey_id, $question_id)
 Deprecated - call drawGraph from question renderer. More...
 
static drawChecklistResults ($surveyField, $qField, $survey_id, $question_id)
 Deprecated - call drawGraph from question renderer. More...
 
static drawRatingResults ($surveyField, $qField, $survey_id, $question_id)
 Deprecated - call drawGraph from question renderer. More...
 

Static Public Attributes

static $surveyManager
 

Detailed Description

Draws a graph of the aggregated answers for a given question.

Uses either the default SurveyCreateManager class or a custom manager class set in the calling code using the syntax

 QuestionnaireResultsGraph::$surveyManager = MyCustomSurveyManager;         

The custom survey manager must contain the following functions in order to use this graphing function:

static function getSurvey($survey_id) static function getQuestion($question_id)

Parameters
String$surveyField- name of the field that has relation "Answers" so that it can retrieve an array of answer DataItem objects with field "value" using the constraint $qField=$question_id
String$qField- the name of the question_id field (e.g., question_id or survey_question_id
Number$survey_id- the key value of the survey or other object that can instantiate the DataItem object that has relation "Answers"
Number$question_id- the key value of the questionnaire or survey question that can instantiate the question DataItem object.

Definition at line 68 of file results_graphs.inc.

Member Function Documentation

◆ drawChecklistGraph()

static QuestionnaireResultsGraph::drawChecklistGraph (   $question,
  $resultsManager,
  $answers 
)
static

Draws an interactive graphical view of answers to one question.

Parameters
obj$question- object of class Question, SurveyQuestion or other question DataItem class
obj$resultsManager- object of the Survey/Questionnaire Results manager class; this class is currently not being used but may be used in the future to specify customization options for graphing
Array$answers- all survey or questionnaire answers to this question

Definition at line 148 of file results_graphs.inc.

149  {
150  $pk = $question->getPrimaryKey();
151  $question_id = $question->$pk;
153 
154  $datay = array();
155 
156  $optionAnswers = array();
157  $count = array();
158  $optionText = QuestionnaireResultsGraph::getOptionText($question->options);
159  $steps = count($optionText);
160 
161  for($idx = 1; $idx <= $steps; ++$idx)
162  {
163  //echo "idx is $idx<br/>";
164  // store for calculating mean and median
165  $totalValue += $idx * $counts[$idx];
166  $totalCount += $counts[$idx];
167  $datay[] = $counts[$idx] ? $counts[$idx] : 0;
168  $datax[] = $optionText[$idx];
169  }
170 
171  // Setup the graph.
172  $graph = new Histogram(650,300);
173  $graph = new Histogram("histogram_$question_id", count($datax) * 80 + 100, 400, 50, 10, count($datax) * 80, 300, "standard");
174  $graph->setLabels($datax);
175  $graph->ticks = 10;
176  $graph->columnMargin = 0.4;
177 
178  $series = new HistogramSeries("block", "Answers", $datay);
179  $graph->addSeries($series);
180  $graph->draw();
181  }
static getCheckListAnswerCounts($answers)
$question_id
$question
$answers
$series

◆ drawChecklistResults()

static QuestionnaireResultsGraph::drawChecklistResults (   $surveyField,
  $qField,
  $survey_id,
  $question_id 
)
static

Deprecated - call drawGraph from question renderer.

Parameters
String$surveyField
String$qField
Number$survey_id
Number$question_id

Definition at line 267 of file results_graphs.inc.

268  {
270  {
271  echo "<p><em>Survey Graphs are not available</em></p>";
272  return;
273  }
274 
276 
277  $question = $surveyManager->getQuestion($question_id);
278  $survey = $surveyManager->getSurvey($survey_id);
279 
280  $answers = $survey->Answers("WHERE $qField=$question_id");
281 
283  }
static drawChecklistGraph($question, $resultsManager, $answers)
Draws an interactive graphical view of answers to one question.
$survey_id
if(! $survey_id) $survey

◆ drawRatingResults()

static QuestionnaireResultsGraph::drawRatingResults (   $surveyField,
  $qField,
  $survey_id,
  $question_id 
)
static

Deprecated - call drawGraph from question renderer.

Parameters
String$surveyField
String$qField
Number$survey_id
Number$question_id

Definition at line 294 of file results_graphs.inc.

295  {
297  {
298  echo "<p><em>Survey Graphs are not available</em></p>";
299  return;
300  }
301 
303 
304  $question = $surveyManager->getQuestion($question_id);
305  $survey = $surveyManager->getSurvey($survey_id);
306 
307  $answers = $survey->Answers("WHERE $qField=$question_id");
308 
310 
311  }
static drawRatingsGraph($question, $resultsManager, $answers)
Draws an interactive graphical view of answers to one question.

◆ drawRatingsGraph()

static QuestionnaireResultsGraph::drawRatingsGraph (   $question,
  $resultsManager,
  $answers 
)
static

Draws an interactive graphical view of answers to one question.

Parameters
obj$question- object of class Question, SurveyQuestion or other question DataItem class
obj$resultsManager- object of the Survey/Questionnaire Results manager class; this class is currently not being used but may be used in the future to specify customization options for graphing
Array$answers- all survey or questionnaire answers to this question

Definition at line 194 of file results_graphs.inc.

195  {
196  $pk = $question->getPrimaryKey();
197  $question_id = $question->$pk;
198  $answerValues = regroupList($answers, "value");
199 
200  $datay = array();
201 
202  $optionAnswers = array();
203  $count = array();
204  $optionText = QuestionnaireResultsGraph::getRatingsOptionText($question->options);
205  $steps = count($optionText);
206 
207  for($idx = 1; $idx <= $steps; ++$idx)
208  {
209  //echo "idx is $idx<br/>";
210  // store for calculating mean and median
211  $counts[$idx] = count($answerValues[$idx]);
212  $totalValue += $idx * $counts[$idx];
213  $totalCount += $counts[$idx];
214  $datay[] = $counts[$idx];
215  $datax[] = $optionText[$idx];
216  }
217 
218  $mean = "Average: ".number_format($totalValue / $totalCount, 1);
219 
220  // Setup the graph.
221  $graph = new Histogram("histogram_$question_id", count($datax) * 80 + 100, 400, 50, 10, count($datax) * 80, 300, "standard");
222  $graph->setLabels($datax);
223  $graph->ticks = 10;
224  $graph->columnMargin = 0.4;
225 
226  //$graph->setTitle($mean);
227 
228  $series = new HistogramSeries("block", "Ratings", $datay);
229  $graph->addSeries($series);
230  $graph->draw();
231  }

◆ drawSelectGraph()

static QuestionnaireResultsGraph::drawSelectGraph (   $question,
  $resultsManager,
  $answers 
)
static

Draws an interactive graphical view of answers to one question.

Parameters
obj$question- object of class Question, SurveyQuestion or other question DataItem class
obj$resultsManager- object of the Survey/Questionnaire Results manager class; this class is currently not being used but may be used in the future to specify customization options for graphing
Array$answers- all survey or questionnaire answers to this question

Definition at line 83 of file results_graphs.inc.

84  {
85  $pk = $question->getPrimaryKey();
86  $question_id = $question->$pk;
87  $options = explode("\n", $question->options);
88  $idx = 1;
89  $optionAnswers = array();
90  $legends = array();
91 
92  $answerValues = regroupList($answers, "value");
93 
94  $total = 0;
95  foreach($options as $option)
96  {
97  $count = count($answerValues[$idx]);
98 
99  $total += $count;
100  $idx++;
101  }
102 
103  $idx = 1;
104  if(count($options) > 0)
105  {
106  foreach($options as $option)
107  {
108  $count = count($answerValues[$idx]);
109  $optionAnswers[] = $count;
110 
111  if ($total > 0)
112  {
113  $percent = number_format(100 * ($count / $total), 1);
114  $legends[] = trim($option) . " ( $percent% )";
115  }
116  else
117  {
118  $legends[] = trim($option);
119  }
120  $idx++;
121  }
122  }
123 
124 
125 
126  $pie = new PieChart("results_$question_id", 650, 400, $optionAnswers, $legends, "standard");
127  $pie->setRadius(150);
128  $pie->setCenter(180,180);
129  $pie->setLabelSize(12);
130  $pie->setStrokeWidth(2);
131  $pie->showLegend(true, 375, 20);
132  $pie->shadow = false;
133  //$pie->emboss = true;
134  $pie->draw();
135  }
$pie
Definition: test_pie.inc:4

◆ drawSelectResults()

static QuestionnaireResultsGraph::drawSelectResults (   $surveyField,
  $qField,
  $survey_id,
  $question_id 
)
static

Deprecated - call drawGraph from question renderer.

Parameters
String$surveyField
String$qField
Number$survey_id
Number$question_id

Definition at line 241 of file results_graphs.inc.

242  {
244  {
245  echo "<p><em>Survey Graphs are not available</em></p>";
246  return;
247  }
248 
250 
251  $question = $surveyManager->getQuestion($question_id);
252  $survey = $surveyManager->getSurvey($survey_id);
253 
254  $answers = $survey->Answers("WHERE $qField=$question_id");
255 
257  }
static drawSelectGraph($question, $resultsManager, $answers)
Draws an interactive graphical view of answers to one question.

Member Data Documentation

◆ $surveyManager

QuestionnaireResultsGraph::$surveyManager
static

Definition at line 70 of file results_graphs.inc.


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