CMS  Version 3.9
survey_manager.inc
Go to the documentation of this file.
1 <?php
7 /**************************************************************
8 
9 Copyright (c) 2010 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 Fakoli::usingFile("/cms/components/questionnaire/questionnaire_manager.inc");
41 Fakoli::usingFile("/cms/components/questionnaire/results_graphs.inc");
42 
44 {
45  function SurveyManager()
46  {
47 
48  }
49 
50 
51  static function surveyTabs($key = "")
52  {
54  $qs = ($key) ? "survey_id=$key" : "";
55  $tabBar = new TwoLevelTabBar($tabs, $qs);
56 
57  return $tabBar;
58  }
59 
60  static function getSurveyTabs($key)
61  {
62  $formTitle = "Create a Survey";
63  $viewTitle = "Preview/Send";
64 
65  if($key)
66  {
67  $survey = new Survey($key);
68  $formTitle = ($survey->isEditable()) ? "Edit Survey" : "Survey Details";
69  $viewTitle = (!$survey->isSent()) ? "Preview/Send" : "Manage Survey";
70  }
71 
72  $images[0] = "<img src='/fakoli/images/tab_create_survey.gif' style='display: inline-block;vertical-align: middle; border: none'/>&nbsp;";
73  $images[1] = "<img src='/fakoli/images/tab_view_results.gif' style='display: inline-block;vertical-align: middle; border: none'/>&nbsp;";
74 
75  $tabs = array(
76  $images[0] . $formTitle => array(
77  "Introduction" => "survey_form",
78  "Questions" => "survey_questions",
79  "Email" => "survey_email",
80  "Confirmation" => "survey_confirmation",
81  $viewTitle => "survey_preview"
82  ),
83 
84  $images[1] . "View Results" => array(
85  "Survey Responses" => "survey_results",
86  "Graphical Data" => "survey_data",
87  "Tabular View" => "survey_data_table",
88  "Spreadsheet View" => "survey_spreadsheet"
89  ),
90  );
91 
92  return $tabs;
93  }
94 
95 } // end SurveyManager
96 
97 
98 class SurveySendManager extends AbstractQuestionnaireSendManager
99 {
101  {
102  parent::AbstractQuestionnaireSendManager($survey);
103  }
104 
105  function getComponentName()
106  {
107  return "survey";
108  }
109 
110  function getResponseClass()
111  {
112  return SurveyResponse;
113  }
114 
115  function getResultsManager()
116  {
117  return new SurveyResultsManager($this->item);
118  }
119 
120  function getReminderDialog()
121  {
122  return "survey_reminder_form";
123  }
124 
125  function getCreateManager()
126  {
127  return new SurveyCreateManager($this->item);
128  }
129 
130 } // end SurveySendManager
131 
132 /*
133  * Description: provides the more generic questionnaire
134  * classes with the specifics of the survey datamodels and
135  * page identifiers. For example, lets the QuestionSet
136  * class know the identifier name of the survey question form.
137  *
138  * @author Janice Gallant for Sonjara, Inc.
139  *
140  * 10/13/2010
141  */
142 class SurveyCreateManager extends AbstractQuestionnaireCreateManager
143 {
148  {
149  $this->item = $survey;
150  }
151 
152  function getQuestionClass()
153  {
154  return SurveyQuestion;
155  }
156 
157  function getComponentName()
158  {
159  return "survey";
160  }
161 
162  function getXrefClass()
163  {
164  return SurveyQuestionXref;
165  }
166 
167  /*
168  * Called by QuestionnaireForm
169  */
170  function getQuestionKey()
171  {
172  return "survey_question_id";
173  }
174 
175  function getAnswerKey()
176  {
177  return "survey_answer_id";
178  }
179 
180  /*
181  * Called by QuestionRenderer
182  */
184  {
185  return QuestionnaireHelper::getQuestionNumber($this->item, $this->item->Questions(), $question);
186  }
187 
188  /*
189  * Called by QuestionnaireForm
190  *
191  * If question_number pseudo field is set here then it won't need to be
192  * reset by each instance of QuestionRenderer
193  */
194  function getQuestions()
195  {
196  $questions = $this->item->Questions("ORDER BY sort_order");
198  }
199 
200  function isEditable()
201  {
202  return $this->item->isEditable();
203  }
204 
205  function getPrimaryKey()
206  {
207  return $this->item->getPrimaryKey();
208  }
209 
210  // The class that stores the answers
211  function getAnswerClass()
212  {
213  return "SurveyAnswer";
214  }
215 
216  function getAnswers()
217  {
218  return null;
219  }
220 
222  {
223  $item = $this->item;
224 
225  if($item->isOpen())
226  {
227  $item->setStatus("closed");
228  }
229  parent::logicalDeleteQuestionnaire();
230  }
231 
232  function getCloneFields()
233  {
234  return array("introduction", "instructions", "sender_email", "user_id", "message", "confirmation_message",
235  "allow_anonymous_responses", "show_preview_before_submitting");
236  }
237 
238 } // end class SurveyManager
239 
240 
241 class SurveyDashboardManager extends AbstractQuestionnaireDashboardManager
242 {
244  {
245  $this->item = $survey;
246  }
247 
248  function getComponentName()
249  {
250  return "survey";
251  }
252 
253  function getCreateManager($item)
254  {
255  return new SurveyCreateManager($item);
256  }
257 
258  function getResultsManager($item)
259  {
260  return new SurveyResultsManager($item);
261  }
262 
263  function getSendManager($item)
264  {
265  return new SurveySendManager($item);
266  }
267 
268  function getCloneDialog()
269  {
270  return "clone_survey";
271  }
272 
274  {
275  return "delete_survey";
276  }
277 
282  {
283  return "survey_results";
284  }
285 }
286 
287 class SurveyResponseManager extends AbstractQuestionnaireResponseManager
288 {
290  {
291  $this->item = $response;
292  }
293 
294  function getComponentName()
295  {
296  return "survey";
297  }
298 
299  function getQuestionClass()
300  {
301  return SurveyQuestion;
302  }
303 
304  function getXrefClass()
305  {
306  return SurveyQuestionXref;
307  }
308 
316  static function create($survey_id)
317  {
318  // create for js manager
319  $response = new SurveyResponse();
320  $response->response_id = 0;
321  $response->status = "not_started";
322  $response->survey_id = $survey_id;
323 
324  return new SurveyResponseManager($response);
325  }
326 
327  /*
328  * Called by QuestionnaireForm
329  */
330  function getQuestionKey()
331  {
332  return "survey_question_id";
333  }
334 
335 
336  function getAnswerKey()
337  {
338  return "survey_answer_id";
339  }
340 
341 
342  // The class that stores the answers
343  function getAnswerClass()
344  {
345  return "SurveyAnswer";
346  }
347 
348  function getQuestions()
349  {
350  $questions = $this->item->Questions("ORDER BY sort_order");
352  }
353 
358  function getAnswers()
359  {
360  return $this->item->Answers();
361  }
362 
363 
364  // How respondent is described in spreadsheet view.
365  // For some surveys, it will by by full name.
366  function getRespondent()
367  {
368  return $this->item->token;
369  }
370 
371  /*
372  * Called by QuestionRenderer
373  */
375  {
376  return QuestionnaireHelper::getQuestionNumber($this->item, $this->item->Questions(), $question);
377  }
378 }
379 
380 
381 /*
382  * Handle getting total results/response counts for one survey for
383  * display of results.
384  */
385 class SurveyResultsManager extends AbstractQuestionnaireResultsManager
386 {
388  {
389  $this->item = $survey;
390  }
391 
392  function getComponentName()
393  {
394  return "survey";
395  }
396 
397  function getQuestionClass()
398  {
399  return SurveyQuestion;
400  }
401 
402  function getXrefClass()
403  {
404  return SurveyQuestionXref;
405  }
406 
407  function getResponseClass()
408  {
409  return SurveyResponse;
410  }
411 
412  /*
413  * Called by QuestionnaireForm
414  */
415  function getQuestionKey()
416  {
417  return "survey_question_id";
418  }
419 
420  function getQuestions()
421  {
422  $questions = $this->item->Questions("ORDER BY sort_order");
424  }
425 
426  function Responses($constraint = "")
427  {
428  return $this->item->Responses($constraint);
429  }
430 
432  {
433  return new SurveyResponseManager($response);
434  }
435 
436  /*
437  * Only get answers to submitted (not in progress) questionnaires/surveys
438  */
439  function getAnswers()
440  {
441  return $this->item->Answers();
442  }
443 
444 
446  {
447  return "Token";
448  }
449 
451  {
452  return "survey_response_view";
453  }
454 
455  /*
456  * Called by QuestionRenderer
457  */
459  {
460  return QuestionnaireHelper::getQuestionNumber($this->item, $this->item->Questions(), $question);
461  }
462 
463  /* for survey aggregation */
464  function getResponseCount()
465  {
466  return $this->item->getResponseCount();
467  }
468 
469  function getRecipientCount()
470  {
471  return $this->item->getRecipientCount();
472  }
473 
474  function getSendManager()
475  {
476  return new SurveySendManager($this->item);
477  }
478 } // end AbstractQuestionnaireResultsManager
479 
480 class SurveyAggregatedResultsManager //extends AbstractQuestionnaireAggregatedResultsManager
481 {
483  {
484  $this->item = $item;
485  }
486 
487  function getQuestionClass()
488  {
489  return "SurveyQuestion";
490  }
491 
492  function getXrefClass()
493  {
494  return SurveyQuestionXref;
495  }
496 
497  function Responses()
498  {
499  return Query::create(SurveyResponse, "WHERE status='submitted'")->execute();
500  }
501 
502  function getAnswers()
503  {
504  $constraint = "WHERE response_id IN (SELECT response_id FROM survey_response WHERE status = 'submitted')";
505 
506  $answers = Query::create(SurveyAnswer, $constraint)->execute();
507  return $answers;
508  }
509 }
510 ?>
$constraint
$tabs
$images
Definition: images.inc:46
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
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)
getQuestionNumber($question)
SurveyCreateManager($survey)
Creates a new SurveyCreateManager object.
getResultsPageIdentifier()
Override default of "survey_responses".
static getSurveyTabs($key)
static surveyTabs($key="")
SurveyResponseManager($response)
getAnswers()
When SurveyCreateManager is used to draw the Survey, we are looking at a preview so no need to retrie...
static create($survey_id)
For response intro page, need to create a default instance of response manager.
getQuestionNumber($question)
getResponseManager($response)
Responses($constraint="")
SurveySendManager($survey)
$survey_id
if(! $survey_id) $survey
$question
$answers
if(! $user) if(! $response_id) $response