1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once('Modules/Test/exceptions/class.ilTestEvaluationException.php');
5
6/**
7* Class ilTestEvaluationPassData
8*
9* @author		Helmut Schottmüller <helmut.schottmueller@mac.com>
10* @author		Björn Heyser <bheyser@databay.de>
11* @version		$Id$
12*
13* @throws		ilTestEvaluationException
14*
15* @defgroup ModulesTest Modules/Test
16* @extends ilObject
17*/
18
19class ilTestEvaluationPassData
20{
21    /**
22    * Answered questions
23    *
24    * @var array
25    */
26    public $answeredQuestions;
27
28    /**
29    * Working time
30    *
31    * @var int
32    */
33    private $workingtime;
34
35    /**
36    * Question count
37    *
38    * @var int
39    */
40    private $questioncount;
41
42    /**
43    * Maximum points
44    *
45    * @var int
46    */
47    private $maxpoints;
48
49    /**
50    * Reached points
51    *
52    * @var int
53    */
54    private $reachedpoints;
55
56    /**
57    * Number of answered questions
58    *
59    * @var int
60    */
61    private $nrOfAnsweredQuestions;
62
63    /**
64    * Test pass
65    *
66    * @var integer
67    */
68    public $pass;
69
70    /**
71     * the number of hints that was requested by participant
72     *
73     * @var integer
74     */
75    private $requestedHintsCount = null;
76
77    /**
78     * the points that were deducted for the hints requested by participant
79     *
80     * @var integer
81     */
82    private $deductedHintPoints = null;
83
84    /**
85     * the fact wether all obligatory questions are answered
86     *
87     * @var boolean
88     */
89    private $obligationsAnswered = null;
90
91    /** @var string */
92    private $examId = '';
93
94    public function __sleep()
95    {
96        return array('answeredQuestions', 'pass', 'nrOfAnsweredQuestions', 'reachedpoints',
97            'maxpoints', 'questioncount', 'workingtime', 'examId');
98    }
99
100    /**
101    * Constructor
102    *
103    * @access	public
104    */
105    public function __construct()
106    {
107        $this->answeredQuestions = array();
108    }
109
110    public function getNrOfAnsweredQuestions()
111    {
112        return $this->nrOfAnsweredQuestions;
113    }
114
115    public function setNrOfAnsweredQuestions($nrOfAnsweredQuestions)
116    {
117        $this->nrOfAnsweredQuestions = $nrOfAnsweredQuestions;
118    }
119
120    public function getReachedPoints()
121    {
122        return $this->reachedpoints;
123    }
124
125    public function setReachedPoints($reachedpoints)
126    {
127        $this->reachedpoints = $reachedpoints;
128    }
129
130    public function getMaxPoints()
131    {
132        return $this->maxpoints;
133    }
134
135    public function setMaxPoints($maxpoints)
136    {
137        $this->maxpoints = $maxpoints;
138    }
139
140    public function getQuestionCount()
141    {
142        return $this->questioncount;
143    }
144
145    public function setQuestionCount($questioncount)
146    {
147        $this->questioncount = $questioncount;
148    }
149
150    public function getWorkingTime()
151    {
152        return $this->workingtime;
153    }
154
155    public function setWorkingTime($workingtime)
156    {
157        $this->workingtime = $workingtime;
158    }
159
160    public function getPass()
161    {
162        return $this->pass;
163    }
164
165    public function setPass($a_pass)
166    {
167        $this->pass = $a_pass;
168    }
169
170    public function getAnsweredQuestions()
171    {
172        return $this->answeredQuestions;
173    }
174
175    public function addAnsweredQuestion($question_id, $max_points, $reached_points, $isAnswered, $sequence = null, $manual = 0)
176    {
177        $this->answeredQuestions[] = array(
178            "id" => $question_id,
179            "points" => round($max_points, 2),
180            "reached" => round($reached_points, 2),
181            'isAnswered' => $isAnswered,
182            "sequence" => $sequence,
183            'manual' => $manual
184        );
185    }
186
187    public function getAnsweredQuestion($index)
188    {
189        if (array_key_exists($index, $this->answeredQuestions)) {
190            return $this->answeredQuestions[$index];
191        } else {
192            return null;
193        }
194    }
195
196    public function getAnsweredQuestionByQuestionId($question_id)
197    {
198        foreach ($this->answeredQuestions as $question) {
199            if ($question["id"] == $question_id) {
200                return $question;
201            }
202        }
203        return null;
204    }
205
206    public function getAnsweredQuestionCount()
207    {
208        return count($this->answeredQuestions);
209    }
210
211    /**
212     * Getter for $requestedHintsCount
213     *
214     * @return integer $requestedHintsCount
215     */
216    public function getRequestedHintsCount()
217    {
218        return $this->requestedHintsCount;
219    }
220
221    /**
222     * Setter for $requestedHintsCount
223     *
224     * @param integer $requestedHintsCount
225     */
226    public function setRequestedHintsCount($requestedHintsCount)
227    {
228        $this->requestedHintsCount = $requestedHintsCount;
229    }
230
231    /**
232     * Getter for $deductedHintPoints
233     *
234     * @return integer $deductedHintPoints
235     */
236    public function getDeductedHintPoints()
237    {
238        return $this->deductedHintPoints;
239    }
240
241    /**
242     * Setter for $deductedHintPoints
243     *
244     * @param integer $deductedHintPoints
245     */
246    public function setDeductedHintPoints($deductedHintPoints)
247    {
248        $this->deductedHintPoints = $deductedHintPoints;
249    }
250
251    /**
252     * setter for property obligationsAnswered
253     *
254     * @param boolean $obligationsAnswered
255     */
256    public function setObligationsAnswered($obligationsAnswered)
257    {
258        $this->obligationsAnswered = (bool) $obligationsAnswered;
259    }
260
261    /**
262     * @return string
263     */
264    public function getExamId() : string
265    {
266        return $this->examId;
267    }
268
269    /**
270     * @param string $examId
271     */
272    public function setExamId(string $examId) : void
273    {
274        $this->examId = $examId;
275    }
276
277    /**
278     * getter for property obligationsAnswered.
279     * if property wasn't set yet the method is trying
280     * to determine this information by iterating
281     * over the added questions.
282     * if both wasn't possible the method throws an exception
283     *
284     * @throws ilTestEvaluationException
285     * @return boolean
286     */
287    public function areObligationsAnswered()
288    {
289        if (!is_null($this->obligationsAnswered)) {
290            return $this->obligationsAnswered;
291        }
292
293        if (is_array($this->answeredQuestions) && count($this->answeredQuestions)) {
294            foreach ($this->answeredQuestions as $question) {
295                if (!$question['isAnswered']) {
296                    return false;
297                }
298            }
299
300            return true;
301        }
302
303        throw new ilTestEvaluationException(
304            'Neither the boolean property ilTestEvaluationPassData::obligationsAnswered was set, ' .
305            'nor the property array property ilTestEvaluationPassData::answeredQuestions contains elements!'
306        );
307    }
308} // END ilTestEvaluationPassData
309