19declare(strict_types=1);
42 if ($question_id < 1) {
47 return $question_data[$question_id] ??
null;
77 $questions_result = $this->db->queryF(
78 'SELECT question_id, points FROM ' . self::MAIN_QUESTION_TABLE .
' WHERE original_id = %s OR question_id = %s',
80 [$question_id, $question_id]
82 if ($this->db->numRows($questions_result) === 0) {
86 $found_questions = [];
87 while ($found_questions_row = $this->db->fetchObject($questions_result)) {
88 $found_questions[$found_questions_row->question_id] = $found_questions_row->points;
91 $points_result = $this->db->query(
92 'SELECT question_fi, points FROM ' . self::TEST_RESULTS_TABLE
97 while ($points_row = $this->db->fetchObject($points_result)) {
99 'reached' => $points_row->points,
100 'reachable' => $found_questions[$points_row->question_fi]
106 foreach ($answers as $points) {
107 $reachable += $points[
'reachable'];
108 $reached += $points[
'reached'];
110 if ($reachable > 0) {
111 return $reached / $reachable;
124 $result = $this->db->queryF(
125 'SELECT COUNT(DISTINCT question_fi) cnt FROM ' . self::TEST_RESULTS_TABLE .
' JOIN tst_active'
126 .
' ON (active_id = active_fi)'
128 .
' AND user_fi = %s',
133 $row = $this->db->fetchObject($result);
134 return $row->cnt === count($question_ids);
139 $result = $this->db->queryF(
140 'SELECT COUNT(*) cnt '
141 .
' FROM ' . self::TEST_RESULTS_TABLE
142 .
' WHERE active_fi = %s'
143 .
' AND question_fi = %s'
146 [$active_id, $question_id, $pass]
149 $row = $this->db->fetchObject($result);
150 return $row->cnt > 0;
153 public function isInUse(
int $question_id = 0): bool
163 $result_tests_fixed = $this->db->queryF(
164 'SELECT COUNT(' . self::MAIN_QUESTION_TABLE .
'.question_id) question_count'
165 .
' FROM ' . self::MAIN_QUESTION_TABLE .
', ' . self::TEST_FIXED_QUESTION_TABLE
166 .
' WHERE ' . self::MAIN_QUESTION_TABLE .
'.question_id = ' . self::TEST_FIXED_QUESTION_TABLE .
'.question_fi'
167 .
' AND ' . self::MAIN_QUESTION_TABLE .
'.original_id = %s',
171 $row_tests_fixed = $this->db->fetchObject($result_tests_fixed);
172 $count = $row_tests_fixed->question_count;
174 $result_tests_random = $this->db->queryF(
175 'SELECT COUNT(' . self::TEST_TO_ACTIVE_USER_TABLE .
'.test_fi) question_count'
176 .
' FROM ' . self::MAIN_QUESTION_TABLE
177 .
' INNER JOIN ' . self::TEST_RANDOM_QUESTION_TABLE
178 .
' ON ' . self::TEST_RANDOM_QUESTION_TABLE .
'.question_fi = ' . self::MAIN_QUESTION_TABLE .
'.question_id'
179 .
' INNER JOIN ' . self::TEST_TO_ACTIVE_USER_TABLE
180 .
' ON ' . self::TEST_TO_ACTIVE_USER_TABLE .
'.active_id = ' . self::TEST_RANDOM_QUESTION_TABLE .
'.active_fi'
181 .
' WHERE ' . self::MAIN_QUESTION_TABLE .
'.original_id = %s'
182 .
' GROUP BY tst_active.test_fi',
186 $row_tests_random = $this->db->fetchObject($result_tests_random);
187 if ($row_tests_random !==
null) {
188 $count += $row_tests_random->question_count;
203 $result = $this->db->query(
204 'SELECT question_id FROM ' . self::MAIN_QUESTION_TABLE .
' WHERE '
209 static fn(\stdClass
$q):
int =>
$q->question_id,
216 if ($question_id < 1) {
220 $result = $this->db->queryF(
221 'SELECT COUNT(question_id) cnt FROM ' . self::MAIN_QUESTION_TABLE .
' WHERE question_id = %s',
226 $row = $this->db->fetchObject($result);
227 return $row->cnt === 1;
232 if ($question_id < 1) {
236 $result = $this->db->queryF(
237 'SELECT COUNT(question_id) cnt FROM ' . self::MAIN_QUESTION_TABLE
238 .
' INNER JOIN ' .
self::DATA_TABLE .
' ON obj_fi = obj_id WHERE question_id = %s AND type = "qpl"',
243 $row = $this->db->fetchObject($result);
244 return $row->cnt === 1;
249 $result = $this->db->queryF(
250 'SELECT COUNT(test_random_question_id) cnt'
251 .
' FROM ' . self::TEST_RANDOM_QUESTION_TABLE
252 .
' WHERE question_fi = %s',
257 $row = $this->db->fetchObject($result);
258 return $row->cnt > 0;
263 $res = $this->db->queryF(
264 'SELECT COUNT(dupl.question_id) cnt'
265 .
' FROM ' . self::MAIN_QUESTION_TABLE .
' dupl'
266 .
' INNER JOIN ' . self::MAIN_QUESTION_TABLE .
' orig'
267 .
' ON orig.question_id = dupl.original_id'
268 .
' WHERE dupl.question_id = %s',
272 $row = $this->db->fetchObject(
$res);
274 return $row->cnt > 0;
282 $in_question_ids = $this->db->in(
'question_fi', $question_ids, false, \
ilDBConstants::T_INTEGER);
284 $result = $this->db->queryF(
286 .
' FROM ' . self::TEST_RESULTS_TABLE
287 .
' WHERE active_fi = %s'
289 .
' AND ' . $in_question_ids,
294 $questions_having_result_record = [];
296 while ($row = $this->db->fetchObject($result)) {
297 $questions_having_result_record[] = $row->question_fi;
300 $questions_missing_result_record = array_diff(
302 $questions_having_result_record
305 return $questions_missing_result_record;
310 $result = $this->db->query(
311 'SELECT COUNT(user_fi) cnt FROM ' . self::TEST_TO_ACTIVE_USER_TABLE
312 .
' JOIN ' . self::TEST_FIXED_QUESTION_TABLE
313 .
' ON ' . self::TEST_FIXED_QUESTION_TABLE .
'.test_fi = ' . self::TEST_TO_ACTIVE_USER_TABLE .
'.test_fi '
314 .
' JOIN ' . self::MAIN_QUESTION_TABLE
315 .
' ON ' . self::MAIN_QUESTION_TABLE .
'.question_id = ' . self::TEST_FIXED_QUESTION_TABLE .
'.question_fi '
319 $row = $this->db->fetchObject($result);
320 return $row->cnt > 0;
326 $this->component_factory,
327 $db_record->question_id,
328 $db_record->original_id,
329 $db_record->external_id,
331 $db_record->oq_obj_fi,
332 $db_record->question_type_fi,
333 $db_record->type_tag,
336 $db_record->description,
337 $db_record->question_text,
339 $db_record->nr_of_tries,
340 $db_record->lifecycle,
344 (
bool) $db_record->complete,
345 $db_record->add_cont_edit_mode
354 $query_result = $this->db->query(
355 'SELECT q.*, qt.type_tag, qt.plugin as is_plugin, qt.plugin_name, oq.obj_fi as oq_obj_fi'
356 .
' FROM ' . self::MAIN_QUESTION_TABLE .
' q'
357 .
' INNER JOIN ' . self::QUESTION_TYPES_TABLE .
' qt'
358 .
' ON q.question_type_fi = qt.question_type_id'
359 .
' LEFT JOIN ' . self::MAIN_QUESTION_TABLE .
' oq'
360 .
' ON oq.question_id = q.original_id'
365 while ($db_record = $this->db->fetchObject($query_result)) {
366 if (!$this->isQuestionTypeAvailable($db_record->plugin_name)) {
369 $questions[$db_record->question_id] = $this
370 ->buildGeneralQuestionPropertyFromDBRecords($db_record);
380 if ($plugin_name ===
null) {
384 $plugin_slot = $this->component_repository->getComponentByTypeAndName(
387 )->getPluginSlotById(
'qst');
389 if (!$plugin_slot->hasPluginName($plugin_name)) {
393 return $plugin_slot->getPluginByName($plugin_name)->isActive();
isInUse(int $question_id=0)
areQuestionsAnsweredByUser(int $user_id, array $question_ids)
Checks if an array of question ids is answered by a user or not.
lookupResultRecordExist(int $active_id, int $question_id, int $pass)
getFractionOfReachedToReachablePointsTotal(int $question_id)
getForQuestionId(int $question_id)
const MAIN_QUESTION_TABLE
isInActiveTest(int $obj_id)
__construct(private \ilDBInterface $db, private \ilComponentFactory $component_factory, private \ilComponentRepository $component_repository)
questionExists(int $question_id)
getForQuestionIds(array $question_ids)
questionExistsInPool(int $question_id)
const TEST_FIXED_QUESTION_TABLE
isUsedInRandomTest(int $question_id)
searchQuestionIdsByTitle(string $title)
isQuestionTypeAvailable(?string $plugin_name)
getForWhereClause(string $where)
getForParentObjectId(int $obj_id)
originalQuestionExists(int $question_id)
const TEST_RANDOM_QUESTION_TABLE
buildGeneralQuestionPropertyFromDBRecords(\stdClass $db_record)
usageCount(int $question_id=0)
Returns the number of place the question is in use in pools or tests.
const QUESTION_TYPES_TABLE
getQuestionsMissingResultRecord(int $active_id, int $pass, array $question_ids)
const TEST_TO_ACTIVE_USER_TABLE
Readable part of repository interface to ilComponentDataDB.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...