19 declare(strict_types=0);
37 protected \ILIAS\TestQuestionPool\Questions\PublicInterface
$questioninfo;
43 $this->db = $DIC->database();
44 $this->questioninfo = $DIC->testQuestion();
46 $this->user_id = $a_usr_id;
63 $ilDB = $DIC->database();
69 $query =
"SELECT objective_id FROM crs_objective_status " .
71 "AND user_id = " .
$ilDB->quote($a_user_id,
'integer') .
" ";
75 $accomplished[] = (
int) $row->objective_id;
80 public function getSuggested(
int $a_crs_id,
string $a_status = self::IL_OBJECTIVE_STATUS_FINAL): array
88 string $a_status = self::IL_OBJECTIVE_STATUS_FINAL
92 $ilDB = $DIC->database();
95 $finished = $suggested = [];
97 $a_status == self::IL_OBJECTIVE_STATUS_FINAL ||
98 $a_status == self::IL_OBJECTIVE_STATUS_FINISHED
101 $query =
"SELECT objective_id FROM crs_objective_status " .
103 "AND user_id = " .
$ilDB->quote($a_user_id,
'integer') .
" ";
106 $finished[] = (
int) $row->objective_id;
110 $query =
"SELECT objective_id FROM crs_objective_status_p " .
112 "AND user_id = " .
$ilDB->quote($a_user_id,
'integer');
115 $finished[] = (
int) $row->objective_id;
119 if (!in_array($objective_id, $finished)) {
120 $suggested[] = $objective_id;
129 foreach (self::_getSuggested($a_usr_id, $a_crs_id) as $objective_id) {
131 foreach ($obj->getFinalTestQuestions() as $qst) {
132 $qsts[] = $qst[
'question_id'];
142 $test_lp->resetLPDataForUserIds(array($a_user_id));
151 public function reset(
int $a_course_id): void
154 foreach (array_merge(
166 $participantData->setUserIdsFilter(array($this->
getUserId()));
167 $participantData->load($tst->getTestId());
168 $tst->removeTestResults($participantData);
180 if ($qualified_tst instanceof ilObjTest) {
187 $query =
"DELETE FROM crs_objective_status " .
188 "WHERE " . $this->db->in(
'objective_id',
$objectives,
false,
'integer') .
' ' .
189 "AND user_id = " . $this->db->quote($this->
getUserId(),
'integer') .
" ";
190 $res = $this->db->manipulate($query);
192 $query =
"DELETE FROM crs_objective_status_p " .
193 "WHERE " . $this->db->in(
'objective_id',
$objectives,
false,
'integer') .
' ' .
195 $res = $this->db->manipulate($query);
197 $query =
"DELETE FROM loc_user_results " .
198 "WHERE " . $this->db->in(
'objective_id',
$objectives,
false,
'integer') .
' ' .
212 if ($objective_ids === []) {
213 return self::IL_OBJECTIVE_STATUS_EMPTY;
216 if (count($accomplished) == count($objective_ids)) {
217 return self::IL_OBJECTIVE_STATUS_FINISHED;
220 $all_pretest_answered =
false;
221 $all_final_answered =
false;
223 if ($this->questioninfo->areQuestionsAnsweredByUser($this->getUserId(), $data[
'questions'])) {
224 if ($data[
'tst_status']) {
225 $all_final_answered =
true;
227 $all_pretest_answered =
true;
231 if ($all_final_answered) {
232 return self::IL_OBJECTIVE_STATUS_FINAL;
234 if ($all_pretest_answered && $suggested === []) {
235 return self::IL_OBJECTIVE_STATUS_PRETEST_NON_SUGGEST;
236 } elseif ($all_pretest_answered) {
237 return self::IL_OBJECTIVE_STATUS_PRETEST;
239 return self::IL_OBJECTIVE_STATUS_NONE;
244 $query =
"SELECT status FROM crs_objective_status " .
245 "WHERE objective_id = " . $this->db->quote($a_objective_id,
'integer') .
" " .
246 "AND user_id = " . $this->db->quote($this->
getUserId(),
'integer') .
"";
248 $res = $this->db->query($query);
265 if (!
$objectives = self::_readAssignedObjectivesOfQuestion($a_question_id)) {
270 self::_updateObjectiveStatus($a_user_id,
$objectives);
277 $ilDB = $DIC[
'ilDB'];
280 $query =
"SELECT q2.question_id qid,q2.objective_id ob FROM crs_objective_qst q1, " .
281 "crs_objective_qst q2 " .
282 "WHERE q1.question_id = " .
$ilDB->quote($a_question_id,
'integer') .
" " .
283 "AND q1.objective_id = q2.objective_id ";
302 $ilDB = $DIC[
'ilDB'];
305 $query =
"SELECT t.objective_id obj,t.ref_id ref, question_id,tst_status,tst_limit " .
306 "FROM crs_objective_tst t JOIN crs_objective_qst q " .
307 "ON (t.objective_id = q.objective_id AND t.ref_id = q.ref_id) " .
308 "WHERE " .
$ilDB->in(
't.objective_id', $a_all_objectives,
false,
'integer');
313 $objectives[$row->obj .
"_" . $row->tst_status][
'questions'][(
int) $row->question_id] = (
int) $row->question_id;
314 $objectives[$row->obj .
"_" . $row->tst_status][
'tst_status'] = (
int) $row->tst_status;
315 $objectives[$row->obj .
"_" . $row->tst_status][
'tst_limit'] = (
int) $row->tst_limit;
316 $objectives[$row->obj .
"_" . $row->tst_status][
'objective_id'] = (
int) $row->obj;
325 $ilDB = $DIC[
'ilDB'];
326 $ilUser = $DIC[
'ilUser'];
329 !count($objectives[
'all_questions']) ||
330 !count($objectives[
'all_objectives'])) {
334 $query =
"SELECT question_id,points FROM qpl_questions " .
335 "WHERE " .
$ilDB->in(
'question_id', (array) $objectives[
'all_questions'],
false,
'integer');
338 $objectives[
'all_question_points'][(
int) $row[
'question_id']][
'max_points'] = (
float) $row[
'points'];
341 $query =
"SELECT question_fi, MAX(points) as reached FROM tst_test_result " .
342 "JOIN tst_active ON (active_id = active_fi) " .
343 "WHERE user_fi = " .
$ilDB->quote($a_user_id,
'integer') .
" " .
344 "AND " .
$ilDB->in(
'question_fi', (array) $objectives[
'all_questions'],
false,
'integer') .
" " .
345 "GROUP BY question_fi,user_fi";
348 $objectives[
'all_question_points'][$row->question_fi][
'reached_points'] = (float) $row->reached;
352 $fullfilled = array();
354 foreach ($objectives[
'objectives'] as
$data) {
358 if ($data[
'tst_status']) {
359 $fullfilled[] = array($data[
'objective_id'], $ilUser->getId(), $data[
'tst_status']);
361 $pretest[] = array($data[
'objective_id'], $ilUser->getId());
365 if ($fullfilled !== []) {
366 foreach ($fullfilled as $fullfilled_arr) {
368 'crs_objective_status',
370 'objective_id' => array(
'integer', $fullfilled_arr[0]),
371 'user_id' => array(
'integer', $fullfilled_arr[1])
374 'status' => array(
'integer', $fullfilled_arr[2])
380 if ($pretest !== []) {
381 foreach ($pretest as $pretest_arr) {
383 'crs_objective_status_p',
385 'objective_id' => array(
'integer', $pretest_arr[0]),
386 'user_id' => array(
'integer', $pretest_arr[1])
395 public static function __isFullfilled(array $question_points, array $objective_data): bool
399 if (!is_array($objective_data[
'questions'])) {
404 foreach ($objective_data[
'questions'] as $question_id) {
405 if (array_key_exists($question_id, $question_points)) {
406 $max_points += $question_points[$question_id][
'max_points'];
407 $reached_points += $question_points[$question_id][
'reached_points'] ?? 0;
409 $DIC->logger()->crs()->warning(
'stale question in course objective assignment table id ' . $question_id);
415 return $reached_points >= $objective_data[
'tst_limit'];
418 protected static function __updatePassed(
int $a_user_id, array $objective_ids): void
422 $ilDB = $DIC[
'ilDB'];
426 $query =
"SELECT COUNT(t1.crs_id) num,t1.crs_id FROM crs_objectives t1 " .
427 "JOIN crs_objectives t2 WHERE t1.crs_id = t2.crs_id and " .
428 $ilDB->in(
't1.objective_id', $objective_ids,
false,
'integer') .
" " .
429 "GROUP BY t1.crs_id";
433 $query =
"SELECT COUNT(cs.objective_id) num_passed FROM crs_objective_status cs " .
434 "JOIN crs_objectives co ON cs.objective_id = co.objective_id " .
435 "WHERE crs_id = " .
$ilDB->quote($row->crs_id,
'integer') .
" " .
436 "AND user_id = " .
$ilDB->quote($a_user_id,
'integer') .
" ";
438 $user_res =
$ilDB->query($query);
440 if ((
int) $user_row->num_passed === (
int) $row->num) {
441 $passed[] = $row->crs_id;
444 $crs_ids[(
int) $row->crs_id] = (
int) $row->crs_id;
446 if ($passed !== []) {
447 foreach ($passed as $crs_id) {
449 $members->updatePassed($a_user_id,
true);
454 foreach ($crs_ids as $cid) {
static _getAccomplished(int $a_user_id, int $a_crs_id)
getStatus(int $a_course_id)
ILIAS TestQuestionPool Questions PublicInterface $questioninfo
static _getObjectiveIds(int $course_id, bool $a_activated_only=false)
const IL_OBJECTIVE_STATUS_FINISHED
getActiveIdOfUser($user_id="", $anonymous_id="")
Gets the active id of a given user.
hasAccomplishedObjective(int $a_objective_id)
const IL_OBJECTIVE_STATUS_FINAL
static _readAssignedObjectivesOfQuestion(int $a_question_id)
static __isFullfilled(array $question_points, array $objective_data)
static _updateObjectiveStatus(int $a_user_id, array $objectives)
const IL_OBJECTIVE_STATUS_PRETEST
static _getSuggested(int $a_user_id, int $a_crs_id, string $a_status=self::IL_OBJECTIVE_STATUS_FINAL)
static _getInstanceByObjId(int $a_obj_id)
const IL_OBJECTIVE_STATUS_PRETEST_NON_SUGGEST
getSuggested(int $a_crs_id, string $a_status=self::IL_OBJECTIVE_STATUS_FINAL)
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
getAccomplished(int $a_crs_id)
static _readAssignedObjectives(array $a_all_objectives)
removeTestActives(array $active_ids)
static getInstanceByObjId(int $a_obj_id)
resetTestForUser(ilObjTest $a_test, int $a_user_id)
readStatus(int $a_crs_id)
static getInstance(int $a_container_id)
const TYPE_TEST_QUALIFIED
static _updateObjectiveResult(int $a_user_id, int $a_active_id, int $a_question_id)
const IL_OBJECTIVE_STATUS_NONE
static __updatePassed(int $a_user_id, array $objective_ids)
static getInstance(int $obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getSuggestedQuestions(int $a_usr_id, int $a_crs_id)
__construct(int $a_usr_id)
static _updateStatus(int $a_obj_id, int $a_usr_id, ?object $a_obj=null, bool $a_percentage=false, bool $a_force_raise=false)
const IL_OBJECTIVE_STATUS_EMPTY