CMS  Version 3.9
abstract_questionnaire_response_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 
10 
20 abstract class AbstractQuestionnaireResponseManager extends AbstractQuestionnaireManager
21 {
22  var $item;
23 
24  function AbstractQuestionnaireResponseManager($item)
25  {
26  $this->item = $item;
27  }
28 
32  abstract function getComponentName();
33 
37  abstract function getQuestionClass();
38 
45  abstract function getXrefClass();
46 
47  /*
48  * Called by QuestionnaireForm function save to save the
49  * resonders answers to the questionnaire.
50  *
51  * Return the name of the DataItem class that stores the answers
52  * e.g., "Answer" or "SurveyAnswer"
53  */
54  abstract function getAnswerClass();
55 
56  function getExcludeHandler()
57  {
58  return "exclude_response";
59  }
60 
66  function getResponseIntroIdentifier()
67  {
68  $class = codify(strtolower($this->item->prettifyClassName()));
69  return "{$class}_intro";
70  }
71 
72 
78  function getResponseFormIdentifier()
79  {
80  return "{$this->item->table}_form";
81  }
82 
83  function getResetTokenHandler()
84  {
85  return "reset_token";
86  }
87 
92  function getQuestionnaire()
93  {
94  $response = $this->item;
95 
96  if($response->hasRelation(Questionnaire))
97  {
98  return $response->Questionnaire();
99  }
100  elseif($response->hasRelation(Survey))
101  {
102  return $response->Survey();
103  }
104  else
105  {
106  Fakoli::end("No relation from response to questionnaire/survey");
107  }
108  }
109 
110  /*
111  * merge code
112  * Called by the response dataitem class
113  *
114  * @param obj $item - class Survey/Questionnaire
115  */
116  function getEditUrl($item)
117  {
118  global $config;
119 
120  $identifier = $this->getResponseFormIdentifier();
121  $pk = $item->getPrimaryKey();
122 
123  // need full url for links placed inside email messages
124  $link = "http://". $config["http_host"] ."/". $item->format("{$identifier}?{$pk}={{$pk}}");
125  if($this->item->token)
126  {
127  $link .= "&token={$this->item->token}";
128  }
129  return "<a href='$link'>$link</a>";
130  }
131 
132  /*
133  * merge code
134  * Called by the response dataitem class
135  *
136  * @param obj $item - class Survey/Questionnaire
137  */
138  function getIntroUrl($item)
139  {
140  global $config;
141 
142  $identifier = $this->getResponseIntroIdentifier();
143  $pk = $item->getPrimaryKey();
144 
145  // need full url for links placed inside email messages
146  $link = "http://". $config["http_host"] ."/". $item->format("{$identifier}?{$pk}={{$pk}}");
147 
148  return "<a href='$link'>$link</a>";
149  }
150 
151 
158  function getAnswers()
159  {
160  $pk = $this->item->getPrimaryKey();
161  if(!$this->item->$pk)
162  {
163  return null;
164  }
165 
166  return $this->item->Answers();
167  }
168 
169 
176  function getRespondent()
177  {
178  return $this->item->format();
179  }
180 
184  function resetToken()
185  {
186  $response = $this->item;
187  $responsePk = $response->getPrimaryKey();
188  $answerClass = $this->getAnswerClass();
189 
190  if(!$response->$responsePk) return;
191 
192  $response->setDefaults();
193 
194  $answer = new $answerClass();
195  $answer->delete("WHERE {$responsePk}={$response->$responsePk}");
196  }
197 
203  function getQuestionNumber($question)
204  {
205  return QuestionnaireHelper::getQuestionNumber($this->item, $this->getQuestions(), $question);
206  }
207 
218  function writeScript()
219  {
220  $item = $this->item;
221 
222  $questionnaire = $this->getQuestionnaire();
223  $itemPk = $questionnaire->getPrimaryKey();
224  $item_id = $questionnaire->$itemPk;
225  $responsePk = $item->getPrimaryKey();
226  $component_name = $this->getComponentName();
227  $exclude_handler = $this->getExcludeHandler();
228  $response_intro_identifier = $this->getResponseIntroIdentifier();
229  $response_form_identifier = $this->getResponseFormIdentifier();
230  $reset_token_handler = $this->getResetTokenHandler();
231 
232  ob_start();
233  ?>
234 <script type="text/javascript" src="/components/questionnaire/js/questionnaire_response.js"></script>
235 <script type="text/javascript">
236 var questionnaireMgr;
237 
238 window.addEvent('domready', function()
239 {
240  questionnaireMgr = new QuestionnaireResponseManager(
241  '<?php echo $itemPk ?>',
242  <?php echo $item_id ?>,
243  '<?php echo $responsePk ?>',
244  '<?php echo $component_name ?>',
245  '<?php echo $exclude_handler ?>',
246  '<?php echo $response_intro_identifier ?>',
247  '<?php echo $response_form_identifier ?>',
248  '<?php echo $reset_token_handler ?>'
249  );
250 });
251 
252 </script>
253 <?
254  $script .= ob_get_contents();
255  ob_end_clean();
256 
257  return $script;
258  }
259 
260 } // end AbstractQuestionnaireResponseManager
261 
262 ?>
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 end($message="")
Use this method to terminate execution of a script instead of using the php keywords exit() or die().
Definition: core.inc:1149
static usingFile()
Uses the specified framework file(s) from the framework directory.
Definition: core.inc:369
static getQuestionNumber($item, $questions, $question)
if(! $questionnaire_id) $questionnaire
global $config
Definition: import.inc:4
$question
if(! $user) if(! $response_id) $response
$identifier
Definition: rss.inc:37