ILIAS  release_8 Revision v8.24
class.ilTestLP.php
Go to the documentation of this file.
1<?php
2
26class ilTestLP extends ilObjectLP
27{
28 private \ILIAS\Test\InternalRequestService $request;
29
33 protected $testObj;
34
35 public function __construct(int $obj_id)
36 {
37 global $DIC;
38 $this->request = $DIC->test()->internal()->request();
39
41 }
42
43 public static function getDefaultModes(bool $a_lp_active): array
44 {
45 return array(
49 );
50 }
51
52 public function getDefaultMode(): int
53 {
55 }
56
57 public function getValidModes(): array
58 {
59 return array(
63 );
64 }
65
66 public function isAnonymized(): bool
67 {
68 return (bool) ilObjTest::_lookupAnonymity($this->obj_id);
69 }
70
74 public function setTestObject(\ilObjTest $test)
75 {
76 $this->testObj = $test;
77 }
78
79 protected function resetCustomLPDataForUserIds(array $user_ids, bool $recursive = true): void
80 {
81 /* @var ilObjTest $testOBJ */
82 if ($this->testObj) {
83 // #19247
84 $testOBJ = $this->testObj;
85 } else {
86 $testOBJ = ilObjectFactory::getInstanceByObjId($this->obj_id);
87 }
88 $testOBJ->removeTestResultsByUserIds($user_ids);
89
90 // :TODO: there has to be a better way
91 $test_ref_id = $this->request->int('ref_id');
92 if ($this->testObj && $this->testObj->getRefId()) {
93 $test_ref_id = $this->testObj->getRefId();
94 }
95
96 if ($test_ref_id === 0) {
97 return;
98 }
99
100 $course_obj_id = ilLOTestAssignments::lookupContainerForTest($test_ref_id);
101 if ($course_obj_id === 0) {
102 return;
103 }
104
105 // remove objective results data
106 $lo_assignments = ilLOTestAssignments::getInstance($course_obj_id);
108 $course_obj_id,
109 $user_ids,
110 $lo_assignments->getTypeByTest($test_ref_id) === ilLOSettings::TYPE_TEST_INITIAL,
111 $lo_assignments->getTypeByTest($test_ref_id) === ilLOSettings::TYPE_TEST_QUALIFIED,
113 );
114 $lp_status = ilLPStatusFactory::_getInstance($course_obj_id);
115 if (strtolower(get_class($lp_status)) !== 'illpstatus') {
116 foreach ($user_ids as $user_id) {
117 $lp_status->_updateStatus($course_obj_id, $user_id);
118 }
119 }
120 }
121
122 protected static function isLPMember(array &$a_res, int $a_usr_id, array $a_obj_ids): bool
123 {
124 global $DIC;
125 $ilDB = $DIC['ilDB'];
126
127 // if active id
128 $set = $ilDB->query("SELECT tt.obj_fi" .
129 " FROM tst_active ta" .
130 " JOIN tst_tests tt ON (ta.test_fi = tt.test_id)" .
131 " WHERE " . $ilDB->in("tt.obj_fi", (array) $a_obj_ids, false, "integer") .
132 " AND ta.user_fi = " . $ilDB->quote($a_usr_id, "integer"));
133 while ($row = $ilDB->fetchAssoc($set)) {
134 $a_res[$row["obj_fi"]] = true;
135 }
136
137 return true;
138 }
139}
static lookupContainerForTest(int $a_test_ref_id)
static lookupObjectivesForTest(int $a_test_ref_id)
static getInstance(int $a_container_id)
static deleteResultsFromLP(int $a_course_id, array $a_user_ids, bool $a_remove_initial, bool $a_remove_qualified, array $a_objective_ids)
static _getInstance(int $a_obj_id, ?int $a_mode=null)
static _lookupAnonymity($a_obj_id)
Returns the anonymity status of a test with a given object id.
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
resetCustomLPDataForUserIds(array $user_ids, bool $recursive=true)
static isLPMember(array &$a_res, int $a_usr_id, array $a_obj_ids)
Find (lp-relevant) members for given object ids.
ILIAS Test InternalRequestService $request
__construct(int $obj_id)
static getDefaultModes(bool $a_lp_active)
Get available type-specific default modes (no administration needed)
setTestObject(\ilObjTest $test)
global $DIC
Definition: feed.php:28
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc