19 declare(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;
   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;
   312         $result = $this->db->queryF(
   313             'SELECT COUNT(*) cnt'   314             . 
' FROM ' . self::TEST_RESULTS_TABLE
   315             . 
' WHERE active_fi = %s'   317             . 
' AND ' . $in_question_ids,
   322         $row = $this->db->fetchAssoc($result);
   323         return $row->cnt < count($question_ids);
   328         $result = $this->db->query(
   329             'SELECT COUNT(user_fi) cnt FROM ' . self::TEST_TO_ACTIVE_USER_TABLE
   330             . 
' JOIN ' . self::TEST_FIXED_QUESTION_TABLE
   331             . 
' ON ' . self::TEST_FIXED_QUESTION_TABLE . 
'.test_fi = ' . self::TEST_TO_ACTIVE_USER_TABLE . 
'.test_fi '   332             . 
' JOIN ' . self::MAIN_QUESTION_TABLE
   333             . 
' ON ' . self::MAIN_QUESTION_TABLE . 
'.question_id = ' . self::TEST_FIXED_QUESTION_TABLE . 
'.question_fi '   337         $row = $this->db->fetchObject($result);
   338         return $row->cnt > 0;
   343         $result = $this->db->queryF(
   344             'SELECT COUNT(*) cnt FROM ' . self::MAIN_QUESTION_TABLE
   345             . 
' WHERE obj_fi = %s AND title = %s',
   347             [$questionpool_id, $title]
   349         $row = $this->db->fetchObject($result);
   350         return $row->cnt > 0;
   356             $this->component_factory,
   357             $db_record->question_id,
   358             $db_record->original_id,
   359             $db_record->external_id,
   361             $db_record->oq_obj_fi,
   362             $db_record->question_type_fi,
   363             $db_record->type_tag,
   366             $db_record->description,
   367             $db_record->question_text,
   369             $db_record->nr_of_tries,
   370             $db_record->lifecycle,
   374             (
bool) $db_record->complete,
   375             $db_record->add_cont_edit_mode
   384         $query_result = $this->db->query(
   385             'SELECT q.*, qt.type_tag, qt.plugin as is_plugin, qt.plugin_name, oq.obj_fi as oq_obj_fi'   386             . 
' FROM ' . self::MAIN_QUESTION_TABLE . 
' q'   387             . 
' INNER JOIN ' . self::QUESTION_TYPES_TABLE . 
' qt'   388             . 
' ON q.question_type_fi = qt.question_type_id'   389             . 
' LEFT JOIN ' . self::MAIN_QUESTION_TABLE . 
' oq'   390             . 
' ON oq.question_id = q.original_id'   395         while ($db_record = $this->db->fetchObject($query_result)) {
   399             $questions[$db_record->question_id] = $this
   400                 ->buildGeneralQuestionPropertyFromDBRecords($db_record);
   410         if ($plugin_name === null) {
   414         $plugin_slot = $this->component_repository->getComponentByTypeAndName(
   417         )->getPluginSlotById(
'qst');
   419         if (!$plugin_slot->hasPluginName($plugin_name)) {
   423         return $plugin_slot->getPluginByName($plugin_name)->isActive();
 
isInUse(int $question_id=0)
 
lookupResultRecordExist(int $active_id, int $question_id, int $pass)
 
Readable part of repository interface to ilComponentDataDB. 
 
questionTitleExistsInPool(int $questionpool_id, string $title)
 
isQuestionTypeAvailable(?string $plugin_name)
 
getForQuestionIds(array $question_ids)
 
getQuestionsMissingResultRecord(int $active_id, int $pass, array $question_ids)
 
getFractionOfReachedToReachablePointsTotal(int $question_id)
 
const TEST_FIXED_QUESTION_TABLE
 
questionExistsInPool(int $question_id)
 
isInActiveTest(int $obj_id)
 
usageCount(int $question_id=0)
Returns the number of place the question is in use in pools or tests. 
 
const QUESTION_TYPES_TABLE
 
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
 
buildGeneralQuestionPropertyFromDBRecords(\stdClass $db_record)
 
areQuestionsAnsweredByUser(int $user_id, array $question_ids)
Checks if an array of question ids is answered by a user or not. 
 
getForWhereClause(string $where)
 
__construct(private \ilDBInterface $db, private \ilComponentFactory $component_factory, private \ilComponentRepository $component_repository)
 
getForParentObjectId(int $obj_id)
 
const TEST_RANDOM_QUESTION_TABLE
 
const MAIN_QUESTION_TABLE
 
questionExists(int $question_id)
 
isUsedInRandomTest(int $question_id)
 
missingResultRecordExists(int $active_id, int $pass, array $question_ids)
 
searchQuestionIdsByTitle(string $title)
 
const TEST_TO_ACTIVE_USER_TABLE
 
originalQuestionExists(int $question_id)
 
getForQuestionId(int $question_id)