18 declare(strict_types=0);
42 $this->db = $DIC->database();
43 $this->questioninfo = $DIC->testQuestionPool()->questionInfo();
45 $this->user_id = $a_usr_id;
62 $ilDB = $DIC->database();
68 $query =
"SELECT objective_id FROM crs_objective_status " .
70 "AND user_id = " .
$ilDB->quote($a_user_id,
'integer') .
" ";
74 $accomplished[] = (
int) $row->objective_id;
79 public function getSuggested(
int $a_crs_id,
string $a_status = self::IL_OBJECTIVE_STATUS_FINAL): array
87 string $a_status = self::IL_OBJECTIVE_STATUS_FINAL
91 $ilDB = $DIC->database();
94 $finished = $suggested = [];
96 $a_status == self::IL_OBJECTIVE_STATUS_FINAL ||
97 $a_status == self::IL_OBJECTIVE_STATUS_FINISHED
100 $query =
"SELECT objective_id FROM crs_objective_status " .
102 "AND user_id = " .
$ilDB->quote($a_user_id,
'integer') .
" ";
105 $finished[] = (
int) $row->objective_id;
109 $query =
"SELECT objective_id FROM crs_objective_status_p " .
111 "AND user_id = " .
$ilDB->quote($a_user_id,
'integer');
114 $finished[] = (
int) $row->objective_id;
118 if (!in_array($objective_id, $finished)) {
119 $suggested[] = $objective_id;
128 foreach (self::_getSuggested($a_usr_id, $a_crs_id) as $objective_id) {
130 foreach ($obj->getFinalTestQuestions() as $qst) {
131 $qsts[] = $qst[
'question_id'];
141 $test_lp->resetLPDataForUserIds(array($a_user_id));
150 public function reset(
int $a_course_id): void
153 foreach (array_merge(
165 $participantData->setUserIdsFilter(array($this->
getUserId()));
166 $participantData->load($tst->getTestId());
167 $tst->removeTestResults($participantData);
179 if ($qualified_tst instanceof ilObjTest) {
186 $query =
"DELETE FROM crs_objective_status " .
187 "WHERE " . $this->db->in(
'objective_id',
$objectives,
false,
'integer') .
' ' .
188 "AND user_id = " . $this->db->quote($this->
getUserId(),
'integer') .
" ";
189 $res = $this->db->manipulate($query);
191 $query =
"DELETE FROM crs_objective_status_p " .
192 "WHERE " . $this->db->in(
'objective_id',
$objectives,
false,
'integer') .
' ' .
194 $res = $this->db->manipulate($query);
196 $query =
"DELETE FROM loc_user_results " .
197 "WHERE " . $this->db->in(
'objective_id',
$objectives,
false,
'integer') .
' ' .
211 if ($objective_ids === []) {
212 return self::IL_OBJECTIVE_STATUS_EMPTY;
215 if (count($accomplished) == count($objective_ids)) {
216 return self::IL_OBJECTIVE_STATUS_FINISHED;
219 $all_pretest_answered =
false;
220 $all_final_answered =
false;
222 if ($this->questioninfo->areQuestionsAnsweredByUser($this->getUserId(), $data[
'questions'])) {
223 if ($data[
'tst_status']) {
224 $all_final_answered =
true;
226 $all_pretest_answered =
true;
230 if ($all_final_answered) {
231 return self::IL_OBJECTIVE_STATUS_FINAL;
233 if ($all_pretest_answered && $suggested === []) {
234 return self::IL_OBJECTIVE_STATUS_PRETEST_NON_SUGGEST;
235 } elseif ($all_pretest_answered) {
236 return self::IL_OBJECTIVE_STATUS_PRETEST;
238 return self::IL_OBJECTIVE_STATUS_NONE;
243 $query =
"SELECT status FROM crs_objective_status " .
244 "WHERE objective_id = " . $this->db->quote($a_objective_id,
'integer') .
" " .
245 "AND user_id = " . $this->db->quote($this->
getUserId(),
'integer') .
"";
247 $res = $this->db->query($query);
264 if (!
$objectives = self::_readAssignedObjectivesOfQuestion($a_question_id)) {
269 self::_updateObjectiveStatus($a_user_id,
$objectives);
276 $ilDB = $DIC[
'ilDB'];
279 $query =
"SELECT q2.question_id qid,q2.objective_id ob FROM crs_objective_qst q1, " .
280 "crs_objective_qst q2 " .
281 "WHERE q1.question_id = " .
$ilDB->quote($a_question_id,
'integer') .
" " .
282 "AND q1.objective_id = q2.objective_id ";
301 $ilDB = $DIC[
'ilDB'];
304 $query =
"SELECT t.objective_id obj,t.ref_id ref, question_id,tst_status,tst_limit " .
305 "FROM crs_objective_tst t JOIN crs_objective_qst q " .
306 "ON (t.objective_id = q.objective_id AND t.ref_id = q.ref_id) " .
307 "WHERE " .
$ilDB->in(
't.objective_id', $a_all_objectives,
false,
'integer');
312 $objectives[$row->obj .
"_" . $row->tst_status][
'questions'][(
int) $row->question_id] = (
int) $row->question_id;
313 $objectives[$row->obj .
"_" . $row->tst_status][
'tst_status'] = (
int) $row->tst_status;
314 $objectives[$row->obj .
"_" . $row->tst_status][
'tst_limit'] = (
int) $row->tst_limit;
315 $objectives[$row->obj .
"_" . $row->tst_status][
'objective_id'] = (
int) $row->obj;
324 $ilDB = $DIC[
'ilDB'];
325 $ilUser = $DIC[
'ilUser'];
328 !count($objectives[
'all_questions']) ||
329 !count($objectives[
'all_objectives'])) {
333 $query =
"SELECT question_id,points FROM qpl_questions " .
334 "WHERE " .
$ilDB->in(
'question_id', (array) $objectives[
'all_questions'],
false,
'integer');
337 $objectives[
'all_question_points'][(
int) $row[
'question_id']][
'max_points'] = (
float) $row[
'points'];
340 $query =
"SELECT question_fi, MAX(points) as reached FROM tst_test_result " .
341 "JOIN tst_active ON (active_id = active_fi) " .
342 "WHERE user_fi = " .
$ilDB->quote($a_user_id,
'integer') .
" " .
343 "AND " .
$ilDB->in(
'question_fi', (array) $objectives[
'all_questions'],
false,
'integer') .
" " .
344 "GROUP BY question_fi,user_fi";
347 $objectives[
'all_question_points'][$row->question_fi][
'reached_points'] = (float) $row->reached;
351 $fullfilled = array();
353 foreach ($objectives[
'objectives'] as
$data) {
357 if ($data[
'tst_status']) {
358 $fullfilled[] = array($data[
'objective_id'], $ilUser->getId(), $data[
'tst_status']);
360 $pretest[] = array($data[
'objective_id'], $ilUser->getId());
364 if ($fullfilled !== []) {
365 foreach ($fullfilled as $fullfilled_arr) {
367 'crs_objective_status',
369 'objective_id' => array(
'integer', $fullfilled_arr[0]),
370 'user_id' => array(
'integer', $fullfilled_arr[1])
373 'status' => array(
'integer', $fullfilled_arr[2])
379 if ($pretest !== []) {
380 foreach ($pretest as $pretest_arr) {
382 'crs_objective_status_p',
384 'objective_id' => array(
'integer', $pretest_arr[0]),
385 'user_id' => array(
'integer', $pretest_arr[1])
394 public static function __isFullfilled(array $question_points, array $objective_data): bool
398 if (!is_array($objective_data[
'questions'])) {
403 foreach ($objective_data[
'questions'] as $question_id) {
404 if (array_key_exists($question_id, $question_points)) {
405 $max_points += $question_points[$question_id][
'max_points'];
406 $reached_points += $question_points[$question_id][
'reached_points'] ?? 0;
408 $DIC->logger()->crs()->warning(
'stale question in course objective assignment table id ' . $question_id);
414 return $reached_points >= $objective_data[
'tst_limit'];
417 protected static function __updatePassed(
int $a_user_id, array $objective_ids): void
421 $ilDB = $DIC[
'ilDB'];
425 $query =
"SELECT COUNT(t1.crs_id) num,t1.crs_id FROM crs_objectives t1 " .
426 "JOIN crs_objectives t2 WHERE t1.crs_id = t2.crs_id and " .
427 $ilDB->in(
't1.objective_id', $objective_ids,
false,
'integer') .
" " .
428 "GROUP BY t1.crs_id";
432 $query =
"SELECT COUNT(cs.objective_id) num_passed FROM crs_objective_status cs " .
433 "JOIN crs_objectives co ON cs.objective_id = co.objective_id " .
434 "WHERE crs_id = " .
$ilDB->quote($row->crs_id,
'integer') .
" " .
435 "AND user_id = " .
$ilDB->quote($a_user_id,
'integer') .
" ";
437 $user_res =
$ilDB->query($query);
439 if ((
int) $user_row->num_passed === (
int) $row->num) {
440 $passed[] = $row->crs_id;
443 $crs_ids[(
int) $row->crs_id] = (
int) $row->crs_id;
445 if ($passed !== []) {
446 foreach ($passed as $crs_id) {
448 $members->updatePassed($a_user_id,
true);
453 foreach ($crs_ids as $cid) {
static _getAccomplished(int $a_user_id, int $a_crs_id)
getStatus(int $a_course_id)
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($activeIds)
static getInstanceByObjId(int $a_obj_id)
ILIAS TestQuestionPool QuestionInfoService $questioninfo
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