CMS  Version 3.9
QuestionField Class Reference
+ Inheritance diagram for QuestionField:

Public Member Functions

 QuestionField ($parent, $question)
 
 getID ()
 
 writeScript ()
 
 writeHTML ()
 
 drawGraph ()
 
 drawSummaryView ()
 
 getAnswer ()
 
 getSpreadsheetAnswer ()
 
 getOptionAnswer ()
 
 writeLimitScript ()
 
 renderLimitEnd ($limit, $field, $value)
 
 getRequired ()
 
 getRequiredValidator ()
 

Static Public Member Functions

static create ($parent, $question)
 

Public Attributes

 $parent
 The parent QuestionForm obj. More...
 
 $question
 The question renderer obj. More...
 
 $readonly
 Whether the questions should be drawn readonly. More...
 
 $answer
 The answer to the question obj. More...
 
 $answerSeparator = "<br>"
 for list of answers in checklist renderer More...
 

Detailed Description

Definition at line 61 of file question_renderer.inc.

Member Function Documentation

◆ create()

static QuestionField::create (   $parent,
  $question 
)
static

Definition at line 208 of file question_renderer.inc.

209  {
210  $questionType = new QuestionType($question->question_type_id);
211 
212  if($questionType AND $questionType->class_name)
213  return new $questionType->class_name($parent, $question);
214  else
215  {
216  trace("QuestionField::create(): Unknown question type", 2);
217  die("Unknown question type {$question->question_type_id}");
218  }
219  }
$question
The question renderer obj.
$parent
The parent QuestionForm obj.

◆ drawGraph()

QuestionField::drawGraph ( )

Definition at line 92 of file question_renderer.inc.

93  {
94 
95  }

◆ drawSummaryView()

QuestionField::drawSummaryView ( )

Reimplemented in HeadingView.

Definition at line 101 of file question_renderer.inc.

102  {
103  echo "<p>" . $this->getAnswer() . "</p>";
104  }

◆ getAnswer()

QuestionField::getAnswer ( )

Reimplemented in CheckListView, RatingView, SelectFieldView, and MultipleChoiceView.

Definition at line 111 of file question_renderer.inc.

112  {
113  return $this->parent->getAnswer($this->question);
114  }

◆ getID()

QuestionField::getID ( )

Definition at line 77 of file question_renderer.inc.

78  {
79  return $this->question->get($this->question->getPrimaryKey());
80  }

◆ getOptionAnswer()

QuestionField::getOptionAnswer ( )

Definition at line 123 of file question_renderer.inc.

124  {
125  $pk = $this->question->getPrimaryKey();
126  $options = explode("\n", $this->question->options);
127 
128  $valueAnswer = $this->parent->getAnswer($this->question);
129 
130  $count = count($options);
131  if($count > 0)
132  {
133  $idx = 1;
134  foreach($options as $value => $text)
135  {
136  if($valueAnswer == $idx)
137  {
138  $answer = $text;
139  break;
140  }
141  $idx++;
142  }
143  }
144 
145  return $answer;
146  }
$answer
The answer to the question obj.

◆ getRequired()

QuestionField::getRequired ( )

Reimplemented in CheckListView.

Definition at line 192 of file question_renderer.inc.

193  {
194  return ($this->question->required) ? "*" : "";
195  }

◆ getRequiredValidator()

QuestionField::getRequiredValidator ( )

Reimplemented in CheckListView, RatingView, and MultipleChoiceView.

Definition at line 197 of file question_renderer.inc.

198  {
199  // empty answer signals to validate from form and $_POST
200  $pk = $this->question->getPrimaryKey();
201 
202  $answer = ($this->parent->readOnlyForm) ? $this->answer : "";
203  $question_number = ($this->question->question_number) ? $this->question->question_number : $this->parent->mgr->getQuestionNumber($this->question);
204  return new RequiredQuestionValidator("question_{$this->question->$pk}", "Question {$question_number}", "", $answer);
205  }
RequiredQuestion Validator.
Definition: validation.inc:58

◆ getSpreadsheetAnswer()

QuestionField::getSpreadsheetAnswer ( )

Reimplemented in RatingView.

Definition at line 116 of file question_renderer.inc.

117  {
118  return $this->getAnswer();
119  }

◆ QuestionField()

QuestionField::QuestionField (   $parent,
  $question 
)

Definition at line 69 of file question_renderer.inc.

70  {
71  $this->parent = $parent;
72  $this->question = $question;
73  $qPk = $question->getPrimaryKey();
74  $this->answer = $this->parent->answers[$this->question->$qPk];
75  }

◆ renderLimitEnd()

QuestionField::renderLimitEnd (   $limit,
  $field,
  $value 
)

Definition at line 182 of file question_renderer.inc.

183  {
184  if ($limit)
185  {
186  echo strlen(trim($value));
187  echo "</span> of {$limit} characters";
188  }
189  }

◆ writeHTML()

QuestionField::writeHTML ( )

Reimplemented in CheckListView, FreeTextView, ShortTextView, RatingView, SelectFieldView, and MultipleChoiceView.

Definition at line 87 of file question_renderer.inc.

88  {
89  return "";
90  }

◆ writeLimitScript()

QuestionField::writeLimitScript ( )

Definition at line 148 of file question_renderer.inc.

149  {
150  if ($this->question->char_limit)
151  {
152 
153  $pk = $this->question->getPrimaryKey();
154  $field = "question_{$this->question->$pk}";
155 
156  $script = <<<ENDSCRIPT
157 
158 /* <![CDATA[ */
159  function {$field}_keyup(event)
160  {
161  var form = document.getElementById('Questionnaire_form');
162  var ctrl = form['{$field}'];
163  var len = ctrl.value.length;
164  if (len >= {$this->question->char_limit})
165  {
166  ctrl.value = ctrl.value.substring(0, {$this->question->char_limit});
167  len = {$this->question->char_limit};
168  }
169 
170  var count = document.getElementById('{$field}_length');
171  count.innerHTML = len;
172  }
173 
174 ENDSCRIPT;
175 
176  return $script;
177 
178  }
179  }

◆ writeScript()

QuestionField::writeScript ( )

Reimplemented in FreeTextView, and ShortTextView.

Definition at line 82 of file question_renderer.inc.

83  {
84  return "";
85  }

Member Data Documentation

◆ $answer

QuestionField::$answer

The answer to the question obj.

Definition at line 66 of file question_renderer.inc.

◆ $answerSeparator

QuestionField::$answerSeparator = "<br>"

for list of answers in checklist renderer

Definition at line 67 of file question_renderer.inc.

◆ $parent

QuestionField::$parent

The parent QuestionForm obj.

Definition at line 63 of file question_renderer.inc.

◆ $question

QuestionField::$question

The question renderer obj.

Definition at line 64 of file question_renderer.inc.

◆ $readonly

QuestionField::$readonly

Whether the questions should be drawn readonly.

Definition at line 65 of file question_renderer.inc.


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