CMS  Version 3.9
quiz_form.inc
Go to the documentation of this file.
1 <?php
7 Fakoli::using("questionnaire");
8 Fakoli::usingFile("/cms/components/questionnaire/questionnaire_form.inc");
9 
10 
12 {
13  var $isCompleted = false;
14  var $correctCount = 0;
16 
17  function QuizForm($mgr)
18  {
19  parent::QuestionnaireForm($mgr);
20  $this->id = "Quiz_form";
21  $this->checkCompleted();
22  $this->questionCount = count($this->questions);
23  $this->gradeQuiz();
24  }
25 
26  function writeHTML()
27  {
28  if(count($this->questions) == 0)
29  {
30  echo "There are no questions.<br/>";
31  return;
32  }
33 
34  if ($this->msg)
35  {
36  echo "<tr>\n <td colspan='2'><span class='error'>{$this->msg}</span</td></tr>\n";
37  $this->msg = "";
38  echo "</span>\n";
39  }
40 
41  echo "<dl>\n";
42 
43  foreach($this->questions as $question)
44  {
45  $this->writeOneQuestion($question);
46  }
47 
48  echo "</dl>\n";
49  }
50 
52  {
53  $qPk = $question->getID();
54  $num = ($question->question->question_number) ? $question->question->question_number : $this->mgr->getQuestionNumber();
55 
57 
58  echo " <dt id='dt_question_{$qPk}' class='{$class}'><label for='question_{$qPk}'>";
59 
60  if (!$question->skipNumbering)
61  {
62  echo "<b>{$num}.</b> ";
63  }
64 
65  echo "{$question->question->question}</label></dt>\n";
66 
67  echo " <dd>";
68 
69  $question->writeHTML();
70 
71  echo " <br/></dd>";
72  }
73 
74  function checkCompleted()
75  {
76  foreach($this->questions as $question)
77  {
78  if(!$question->answer->value)
79  {
80  $this->isCompleted = false;
81  return;
82  }
83  }
84  $this->isCompleted = true;
85  }
86 
87  function passed()
88  {
89  if($this->correctCount == $this->questionCount)
90  {
91  return true;
92  }
93  else
94  {
95  return false;
96  }
97  }
98 
99  function gradeQuiz()
100  {
101  foreach($this->questions as $question)
102  {
103  if($question->answer->value && $question->answer->value == $question->question->answer)
104  {
105  $this->correctCount ++;
106  }
107  }
108  }
109 
110  function formatMissed()
111  {
112  $count = $this->questionCount - $this->correctCount;
113 
114  return ($count > 1) ? "$count questions" : "$count question";
115  }
116 
117  function isCompleted()
118  {
119  return ($this->isCompleted) ? true : false;
120  }
121 
127  {
128  if(!$question->question->hasField("answer") || !$this->isCompleted() || !$question->answer->value)
129  {
130  return "";
131  }
132 
133  return ($question->answer->value == $question->question->answer) ? "correct_answer" : "incorrect_answer";
134  }
135 
136 }?>
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
QuizForm($mgr)
Definition: quiz_form.inc:17
gradeQuiz()
Definition: quiz_form.inc:99
writeHTML()
Definition: quiz_form.inc:26
writeOneQuestion($question)
Definition: quiz_form.inc:51
getQuestionClass($question)
Definition: quiz_form.inc:126
checkCompleted()
Definition: quiz_form.inc:74
$questionCount
Definition: quiz_form.inc:15
formatMissed()
Definition: quiz_form.inc:110
isCompleted()
Definition: quiz_form.inc:117
$question
$table column("Redirect From", "<a href='redirect_form?redirect_id={redirect_id}'>{redirect_from}</a>", true, "width: 30%") -> column("Redirect To", "<a href='{redirect_to}' target='_blank'>{redirect_to}</a>", true, "width: 30%") ->column("Last Modified", "{last_modified}", true, "width: 20%; text-align: center") ->column("Override", "{ override true
Definition: redirects.inc:9