18 declare(strict_types=0);
41 $this->db = $DIC->database();
43 $this->user_id = $a_usr_id;
60 $ilDB = $DIC->database();
66 $query =
"SELECT objective_id FROM crs_objective_status " .
68 "AND user_id = " .
$ilDB->quote($a_user_id,
'integer') .
" ";
72 $accomplished[] = (
int) $row->objective_id;
77 public function getSuggested(
int $a_crs_id,
string $a_status = self::IL_OBJECTIVE_STATUS_FINAL): array
85 string $a_status = self::IL_OBJECTIVE_STATUS_FINAL
89 $ilDB = $DIC->database();
92 $finished = $suggested = [];
94 $a_status == self::IL_OBJECTIVE_STATUS_FINAL ||
95 $a_status == self::IL_OBJECTIVE_STATUS_FINISHED
98 $query =
"SELECT objective_id FROM crs_objective_status " .
100 "AND user_id = " .
$ilDB->quote($a_user_id,
'integer') .
" ";
103 $finished[] = (
int) $row->objective_id;
107 $query =
"SELECT objective_id FROM crs_objective_status_p " .
109 "AND user_id = " .
$ilDB->quote($a_user_id,
'integer');
112 $finished[] = (
int) $row->objective_id;
116 if (!in_array($objective_id, $finished)) {
117 $suggested[] = $objective_id;
126 foreach (self::_getSuggested($a_usr_id, $a_crs_id) as $objective_id) {
128 foreach ($obj->getFinalTestQuestions() as $qst) {
129 $qsts[] = $qst[
'question_id'];
139 $test_lp->resetLPDataForUserIds(array($a_user_id));
148 public function reset(
int $a_course_id): void
151 foreach (array_merge(
163 $participantData->setUserIdsFilter(array($this->
getUserId()));
164 $participantData->load($tst->getTestId());
165 $tst->removeTestResults($participantData);
177 if ($qualified_tst instanceof ilObjTest) {
184 $query =
"DELETE FROM crs_objective_status " .
185 "WHERE " . $this->db->in(
'objective_id',
$objectives,
false,
'integer') .
' ' .
186 "AND user_id = " . $this->db->quote($this->
getUserId(),
'integer') .
" ";
189 $query =
"DELETE FROM crs_objective_status_p " .
190 "WHERE " . $this->db->in(
'objective_id',
$objectives,
false,
'integer') .
' ' .
194 $query =
"DELETE FROM loc_user_results " .
195 "WHERE " . $this->db->in(
'objective_id',
$objectives,
false,
'integer') .
' ' .
209 if ($objective_ids === []) {
210 return self::IL_OBJECTIVE_STATUS_EMPTY;
213 if (count($accomplished) == count($objective_ids)) {
214 return self::IL_OBJECTIVE_STATUS_FINISHED;
217 $all_pretest_answered =
false;
218 $all_final_answered =
false;
221 if ($data[
'tst_status']) {
222 $all_final_answered =
true;
224 $all_pretest_answered =
true;
228 if ($all_final_answered) {
229 return self::IL_OBJECTIVE_STATUS_FINAL;
231 if ($all_pretest_answered && $suggested === []) {
232 return self::IL_OBJECTIVE_STATUS_PRETEST_NON_SUGGEST;
233 } elseif ($all_pretest_answered) {
234 return self::IL_OBJECTIVE_STATUS_PRETEST;
236 return self::IL_OBJECTIVE_STATUS_NONE;
241 $query =
"SELECT status FROM crs_objective_status " .
242 "WHERE objective_id = " . $this->db->quote($a_objective_id,
'integer') .
" " .
243 "AND user_id = " . $this->db->quote($this->
getUserId(),
'integer') .
"";
262 if (!
$objectives = self::_readAssignedObjectivesOfQuestion($a_question_id)) {
267 self::_updateObjectiveStatus($a_user_id,
$objectives);
274 $ilDB = $DIC[
'ilDB'];
277 $query =
"SELECT q2.question_id qid,q2.objective_id ob FROM crs_objective_qst q1, " .
278 "crs_objective_qst q2 " .
279 "WHERE q1.question_id = " .
$ilDB->quote($a_question_id,
'integer') .
" " .
280 "AND q1.objective_id = q2.objective_id ";
299 $ilDB = $DIC[
'ilDB'];
302 $query =
"SELECT t.objective_id obj,t.ref_id ref, question_id,tst_status,tst_limit " .
303 "FROM crs_objective_tst t JOIN crs_objective_qst q " .
304 "ON (t.objective_id = q.objective_id AND t.ref_id = q.ref_id) " .
305 "WHERE " .
$ilDB->in(
't.objective_id', $a_all_objectives,
false,
'integer');
310 $objectives[$row->obj .
"_" . $row->tst_status][
'questions'][(
int) $row->question_id] = (
int) $row->question_id;
311 $objectives[$row->obj .
"_" . $row->tst_status][
'tst_status'] = (
int) $row->tst_status;
312 $objectives[$row->obj .
"_" . $row->tst_status][
'tst_limit'] = (
int) $row->tst_limit;
313 $objectives[$row->obj .
"_" . $row->tst_status][
'objective_id'] = (
int) $row->obj;
322 $ilDB = $DIC[
'ilDB'];
326 !count($objectives[
'all_questions']) ||
327 !count($objectives[
'all_objectives'])) {
331 $query =
"SELECT question_id,points FROM qpl_questions " .
332 "WHERE " .
$ilDB->in(
'question_id', (array) $objectives[
'all_questions'],
false,
'integer');
335 $objectives[
'all_question_points'][(
int) $row[
'question_id']][
'max_points'] = (
float) $row[
'points'];
338 $query =
"SELECT question_fi, MAX(points) as reached FROM tst_test_result " .
339 "JOIN tst_active ON (active_id = active_fi) " .
340 "WHERE user_fi = " .
$ilDB->quote($a_user_id,
'integer') .
" " .
341 "AND " .
$ilDB->in(
'question_fi', (array) $objectives[
'all_questions'],
false,
'integer') .
" " .
342 "GROUP BY question_fi,user_fi";
345 $objectives[
'all_question_points'][$row->question_fi][
'reached_points'] = (float) $row->reached;
349 $fullfilled = array();
351 foreach ($objectives[
'objectives'] as
$data) {
355 if ($data[
'tst_status']) {
356 $fullfilled[] = array($data[
'objective_id'],
$ilUser->getId(), $data[
'tst_status']);
358 $pretest[] = array($data[
'objective_id'],
$ilUser->getId());
362 if ($fullfilled !== []) {
363 foreach ($fullfilled as $fullfilled_arr) {
365 'crs_objective_status',
367 'objective_id' => array(
'integer', $fullfilled_arr[0]),
368 'user_id' => array(
'integer', $fullfilled_arr[1])
371 'status' => array(
'integer', $fullfilled_arr[2])
377 if ($pretest !== []) {
378 foreach ($pretest as $pretest_arr) {
380 'crs_objective_status_p',
382 'objective_id' => array(
'integer', $pretest_arr[0]),
383 'user_id' => array(
'integer', $pretest_arr[1])
392 public static function __isFullfilled(array $question_points, array $objective_data): bool
396 if (!is_array($objective_data[
'questions'])) {
401 foreach ($objective_data[
'questions'] as $question_id) {
402 if (array_key_exists($question_id, $question_points)) {
403 $max_points += $question_points[$question_id][
'max_points'];
404 $reached_points += $question_points[$question_id][
'reached_points'] ?? 0;
406 $DIC->logger()->crs()->warning(
'stale question in course objective assignment table id ' . $question_id);
412 return $reached_points >= $objective_data[
'tst_limit'];
415 protected static function __updatePassed(
int $a_user_id, array $objective_ids): void
419 $ilDB = $DIC[
'ilDB'];
423 $query =
"SELECT COUNT(t1.crs_id) num,t1.crs_id FROM crs_objectives t1 " .
424 "JOIN crs_objectives t2 WHERE t1.crs_id = t2.crs_id and " .
425 $ilDB->in(
't1.objective_id', $objective_ids,
false,
'integer') .
" " .
426 "GROUP BY t1.crs_id";
430 $query =
"SELECT COUNT(cs.objective_id) num_passed FROM crs_objective_status cs " .
431 "JOIN crs_objectives co ON cs.objective_id = co.objective_id " .
432 "WHERE crs_id = " .
$ilDB->quote($row->crs_id,
'integer') .
" " .
433 "AND user_id = " .
$ilDB->quote($a_user_id,
'integer') .
" ";
437 if ((
int) $user_row->num_passed === (
int) $row->num) {
438 $passed[] = $row->crs_id;
441 $crs_ids[(
int) $row->crs_id] = (
int) $row->crs_id;
443 if ($passed !== []) {
444 foreach ($passed as $crs_id) {
446 $members->updatePassed($a_user_id,
true);
451 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 _areAnswered(int $a_user_id, array $a_question_ids)
Checks if an array of question ids is answered by a user or not.
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)
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)
class ilcourseobjectiveQuestion
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