3 declare(strict_types=1);
18 if ($question_id < 1) {
22 $result = $this->database->queryF(
23 "SELECT title FROM qpl_questions WHERE qpl_questions.question_id = %s",
27 if ($result->numRows() === 1) {
28 $data = $this->database->fetchAssoc($result);
29 return $data[
"title"];
36 if ($question_id < 1) {
40 $result = $this->database->queryF(
41 "SELECT type_tag FROM qpl_questions, qpl_qst_type WHERE qpl_questions.question_id = %s AND qpl_questions.question_type_fi = qpl_qst_type.question_type_id",
46 if ($result->numRows() === 1) {
47 $data = $this->database->fetchAssoc($result);
48 return $data[
"type_tag"];
58 if ($question_type ===
'') {
62 if (file_exists(
"./Modules/TestQuestionPool/classes/class." . $question_type .
".php")) {
63 return $this->
lng->txt($question_type);
66 foreach ($this->component_factory->getActivePluginsInSlot(
'qst') as $pl) {
67 if ($pl->getQuestionType() === $question_type) {
68 return $pl->getQuestionTypeTranslation();
76 $result = $this->database->queryF(
77 "SELECT question_text FROM qpl_questions WHERE question_id = %s",
82 if ($result->numRows() === 1) {
83 $row = $this->database->fetchAssoc($result);
84 return $row[
"question_text"];
92 $result = $this->database->queryF(
93 "SELECT question_id FROM qpl_questions WHERE original_id = %s OR question_id = %s",
94 [
'integer',
'integer'],
97 if ($result->numRows() === 0) {
102 while ($row = $this->database->fetchAssoc($result)) {
103 $found_id[] = $row[
"question_id"];
106 $result = $this->database->query(
"SELECT question_fi, points FROM tst_test_result WHERE " . $this->database->in(
'question_fi', $found_id,
false,
'integer'));
108 while ($row = $this->database->fetchAssoc($result)) {
109 $reached = $row[
"points"];
111 $answers[] = [
"reached" => $reached,
"max" => $max];
116 foreach ($answers as
$key => $value) {
117 $max += $value[
"max"];
118 $reached += $value[
"reached"];
121 return $reached / $max;
129 $result = $this->database->queryF(
130 "SELECT points FROM qpl_questions WHERE question_id = %s",
134 if ($this->database->numRows($result) === 1) {
135 $row = $this->database->fetchAssoc($result);
136 $points = (float) $row[
"points"];
143 $result = $this->database->queryF(
144 "SELECT qpl_questions.*, qpl_qst_type.type_tag FROM qpl_qst_type, qpl_questions WHERE qpl_questions.question_id = %s AND qpl_questions.question_type_fi = qpl_qst_type.question_type_id",
149 if ($this->database->numRows($result)) {
150 return $this->database->fetchAssoc($result);
163 $res = $this->database->queryF(
164 "SELECT DISTINCT(question_fi) FROM tst_test_result JOIN tst_active " .
165 "ON (active_id = active_fi) " .
166 "WHERE " . $this->database->in(
'question_fi', $a_question_ids,
false,
'integer') .
171 return $res->numRows() === count($a_question_ids);
184 $row = $this->database->fetchAssoc($this->database->queryF($query, [
'integer',
'integer',
'integer'], [$activeId, $questionId, $pass]));
186 return $row[
'cnt'] > 0;
192 public function isClone(
int $question_id): bool
194 $result = $this->database->queryF(
195 "SELECT COUNT(original_id) cnt FROM qpl_questions WHERE question_id = %s",
199 $row = $this->database->fetchAssoc($result);
200 return ((
int) $row[
"cnt"]) > 0;
206 public function isInUse(
int $question_id = 0): bool
216 $result = $this->database->queryF(
217 "SELECT COUNT(qpl_questions.question_id) question_count FROM qpl_questions, tst_test_question WHERE qpl_questions.original_id = %s AND qpl_questions.question_id = tst_test_question.question_fi",
221 $row = $this->database->fetchAssoc($result);
222 $count = (
int) $row[
"question_count"];
224 $result = $this->database->queryF(
226 SELECT tst_active.test_fi 228 INNER JOIN tst_test_rnd_qst ON tst_test_rnd_qst.question_fi = qpl_questions.question_id 229 INNER JOIN tst_active ON tst_active.active_id = tst_test_rnd_qst.active_fi 230 WHERE qpl_questions.original_id = %s 231 GROUP BY tst_active.test_fi",
235 $count += $this->database->numRows($result);
242 if ($question_id < 1) {
246 $result = $this->database->queryF(
247 "SELECT question_id FROM qpl_questions WHERE question_id = %s",
251 return $result->numRows() === 1;
256 if ($question_id < 1) {
260 $result = $this->database->queryF(
261 "SELECT question_id FROM qpl_questions INNER JOIN object_data ON obj_fi = obj_id WHERE question_id = %s AND type = 'qpl'",
265 return $this->database->numRows($result) === 1;
270 $result = $this->database->queryF(
271 "SELECT test_random_question_id FROM tst_test_rnd_qst WHERE question_fi = %s",
275 return $this->database->numRows($result) > 0;
281 SELECT COUNT(dupl.question_id) cnt 282 FROM qpl_questions dupl 283 INNER JOIN qpl_questions orig 284 ON orig.question_id = dupl.original_id 285 WHERE dupl.question_id = %s 288 $res = $this->database->queryF($query, [
'integer'], [$questionId]);
289 $row = $this->database->fetchAssoc(
$res);
291 return $row[
'cnt'] > 0;
296 $result = $this->database->queryF(
297 "SELECT * FROM qpl_questions WHERE question_id = %s",
301 if ($this->database->numRows($result) > 0) {
302 $row = $this->database->fetchAssoc($result);
303 if ($row[
"original_id"] > 0) {
304 return $row[
"original_id"];
307 return (
int) $row[
"question_id"];
315 $IN_questionIds = $this->database->in(
'question_fi', $questionIds,
false,
'integer');
325 $res = $this->database->queryF(
327 [
'integer',
'integer'],
331 $questionsHavingResultRecord = [];
333 while ($row = $this->database->fetchAssoc(
$res)) {
334 $questionsHavingResultRecord[] = $row[
'question_fi'];
337 $questionsMissingResultRecordt = array_diff(
339 $questionsHavingResultRecord
342 return $questionsMissingResultRecordt;
347 $IN_questionIds = $this->database->in(
'question_fi', $questionIds,
false,
'integer');
357 $row = $this->database->fetchAssoc($this->database->queryF(
359 [
'integer',
'integer'],
363 return $row[
'cnt'] < count($questionIds);
368 $query =
'SELECT user_fi FROM tst_active ' . PHP_EOL
369 .
'JOIN tst_test_question ON tst_test_question.test_fi = tst_active.test_fi ' . PHP_EOL
370 .
'JOIN qpl_questions ON qpl_questions.question_id = tst_test_question.question_fi ' . PHP_EOL
371 .
'WHERE qpl_questions.obj_fi = ' . $this->database->quote($obj_id,
'integer');
373 $res = $this->database->query($query);
374 return $res->numRows() > 0;
379 $result = $this->database->queryF(
380 "SELECT * FROM qpl_questions WHERE obj_fi = %s AND title = %s",
382 [$questionpool_id, $title]
384 return $result->numRows() > 0;
getOriginalId(int $question_id)
getQuestionType(int $question_id)
questionTitleExistsInPool(int $questionpool_id, string $title)
isInUse(int $question_id=0)
Checks whether the question is in use or not in pools or tests.
getQuestionTitle(int $question_id)
getQuestionInfo(int $question_id)
isInActiveTest(int $obj_id)
originalQuestionExists(int $questionId)
getMaximumPoints(int $question_id)
__construct(private \ilDBInterface $database, private \ilComponentFactory $component_factory, private \ilLanguage $lng)
getQuestionsMissingResultRecord(int $activeId, int $pass, array $questionIds)
questionExistsInPool(int $question_id)
lookupResultRecordExist(int $activeId, int $questionId, int $pass)
isUsedInRandomTest(int $question_id)
getQuestionText(int $a_q_id)
missingResultRecordExists(int $activeId, int $pass, array $questionIds)
getQuestionTypeName(int $question_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
usageNumber(int $question_id=0)
Returns the number of place the question is in use in pools or tests.
questionExists(int $question_id)
areQuestionsAnsweredByUser(int $a_user_id, array $a_question_ids)
Checks if an array of question ids is answered by a user or not.
getFractionOfReachedToReachablePointsTotal(int $a_q_id)
isClone(int $question_id)
Checks whether the question is a clone of another question or not.