ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilAssQuestionPreviewHintTracking.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4
12{
16 private $db;
17
22
24 {
25 $this->db = $db;
26 $this->previewSession = $previewSession;
27 }
28
29 public function requestsExist()
30 {
31 return (
32 $this->previewSession->getNumRequestedHints() > 0
33 );
34 }
35
36 public function requestsPossible()
37 {
38 $query = "
39 SELECT COUNT(qht_hint_id) cnt_available
40 FROM qpl_hints
41 WHERE qht_question_fi = %s
42 ";
43
44 $res = $this->db->queryF(
45 $query, array('integer'), array($this->previewSession->getQuestionId())
46 );
47
48 $row = $this->db->fetchAssoc($res);
49
50 if( $row['cnt_available'] > $this->previewSession->getNumRequestedHints() )
51 {
52 return true;
53 }
54
55 return false;
56 }
57
58 public function getNextRequestableHint()
59 {
60 $query = "
61 SELECT qht_hint_id
62
63 FROM qpl_hints
64
65 WHERE qht_question_fi = %s
66
67 ORDER BY qht_hint_index ASC
68 ";
69
70 $res = $this->db->queryF(
71 $query, array('integer'), array($this->previewSession->getQuestionId())
72 );
73
74 while( $row = $this->db->fetchAssoc($res) )
75 {
76 if( !$this->isRequested($row['qht_hint_id']) )
77 {
78 return ilAssQuestionHint::getInstanceById($row['qht_hint_id']);
79 }
80 }
81
82 throw new ilTestException(
83 "no next hint found for questionId={$this->previewSession->getQuestionId()}, userId={$this->previewSession->getUserId()}"
84 );
85 }
86
87 public function storeRequest(ilAssQuestionHint $questionHint)
88 {
89 $this->previewSession->addRequestedHint($questionHint->getId());
90 }
91
92 public function isRequested($hintId)
93 {
94 return $this->previewSession->isHintRequested($hintId);
95 }
96
97 public function getNumExistingRequests()
98 {
99 return $this->previewSession->getNumRequestedHints();
100 }
101
102 public function getRequestedHintsList()
103 {
104 $hintIds = $this->previewSession->getRequestedHints();
105
106 $requestedHintsList = ilAssQuestionHintList::getListByHintIds($hintIds);
107
108 return $requestedHintsList;
109 }
110
111 public function getRequestStatisticData()
112 {
113 $count = 0;
114 $points = 0;
115
116 foreach($this->getRequestedHintsList() as $hint)
117 {
118 $count++;
119 $points += $hint->getPoints();
120 }
121
122 require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintRequestStatisticData.php';
123 $requestsStatisticData = new ilAssQuestionHintRequestStatisticData();
124 $requestsStatisticData->setRequestsCount($count);
125 $requestsStatisticData->setRequestsPoints($points);
126
127 return $requestsStatisticData;
128 }
129}
An exception for terminatinating execution or to throw for unit testing.
static getListByHintIds($hintIds)
instantiates a question hint list for the passed hint ids
static getInstanceById($hintId)
creates a hint object instance, loads the persisted hint dataset identified by passed hint id from da...
getId()
returns the hint id
__construct(ilDBInterface $db, ilAssQuestionPreviewSession $previewSession)
Base Exception for all Exceptions relating to Modules/Test.
Interface ilDBInterface.