ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
class.ilLOUtils.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=0);
25{
29 public static function isCompleted(
30 int $a_cont_oid,
31 int $a_test_rid,
32 int $a_objective_id,
33 int $max_points,
34 int $reached,
35 int $limit_perc
36 ): bool {
37 $settings = ilLOSettings::getInstanceByObjId($a_cont_oid);
38
39 if (self::lookupRandomTest(ilObject::_lookupObjId($a_test_rid))) {
40 if ($max_points === 0) {
41 return true;
42 } else {
43 return ($reached / $max_points * 100) >= $limit_perc;
44 }
45 } else {
47 $a_cont_oid,
48 $a_objective_id,
49 $a_test_rid,
50 $max_points
51 );
52
53 if ($max_points === 0) {
54 return true;
55 } else {
56 return ($reached / $max_points * 100) >= $required_perc;
57 }
58 }
59 }
60
61 public static function lookupObjectiveRequiredPercentage(
62 int $a_container_id,
63 int $a_objective_id,
64 int $a_test_ref_id,
65 int $a_max_points
66 ): int {
67 $settings = ilLOSettings::getInstanceByObjId($a_container_id);
68 $assignments = ilLOTestAssignments::getInstance($a_container_id);
69 $a_test_type = $assignments->getTypeByTest($a_test_ref_id);
70
71 if ($assignments->isSeparateTest($a_test_ref_id)) {
72 $factory = new ilObjectFactory();
73 $tst = $factory->getInstanceByRefId($a_test_ref_id, false);
74 if ($tst instanceof ilObjTest) {
75 $schema = $tst->getMarkSchema();
76 foreach ($schema->getMarkSteps() as $mark) {
77 if ($mark->getPassed()) {
78 return (int) $mark->getMinimumLevel();
79 }
80 }
81 }
82 }
83 $tst_ref_id = $a_test_ref_id;
84 if (self::lookupRandomTest(ilObject::_lookupObjId($tst_ref_id))) {
85 return ilLORandomTestQuestionPools::lookupLimit($a_container_id, $a_objective_id, $a_test_type);
86 } else {
87 return ilCourseObjectiveQuestion::loookupTestLimit(ilObject::_lookupObjId($tst_ref_id), $a_objective_id);
88 }
89 }
90
91 public static function lookupMaxAttempts(int $a_container_id, int $a_objective_id, int $a_test_ref_id): int
92 {
93 global $DIC;
94
95 $ilDB = $DIC->database();
96
97 $assignments = ilLOTestAssignments::getInstance($a_container_id);
98 if (!$assignments->isSeparateTest($a_test_ref_id)) {
99 // no limit of tries for tests assigned to multiple objectives.
100 return 0;
101 }
102
103 $test_obj = new ilObjTest($a_test_ref_id, true);
104 return $test_obj->getNrOfTries();
105 }
106
107 public static function lookupRandomTest(int $a_test_obj_id): bool
108 {
109 return ilObjTest::_lookupRandomTest($a_test_obj_id);
110 }
111
115 public static function lookupQplBySequence(int $a_test_ref_id, int $a_sequence_id): string
116 {
118 global $DIC;
119
120 if (!$a_sequence_id) {
121 return '';
122 }
123 $tst = ilObjectFactory::getInstanceByRefId($a_test_ref_id, false);
124 if (!$tst instanceof ilObjTest) {
125 return '';
126 }
128 $DIC->database(),
129 $tst,
131 $DIC->database(),
132 $tst
133 )
134 );
135
136 $list->loadDefinitions();
137
138 $translator = new ilTestQuestionFilterLabelTranslator($DIC['ilDB'], $DIC['lng']);
139 $translator->loadLabels($list);
140
141 $title = '';
142 foreach ($list as $definition) {
143 if ($definition->getId() != $a_sequence_id) {
144 continue;
145 }
146 $title = self::buildQplTitleByDefinition($definition, $translator);
147 }
148 return $title;
149 }
150
151 protected static function buildQplTitleByDefinition(
154 ): string {
155 $title = $def->getPoolTitle();
156 $filterTitle = array();
157 $filterTitle[] = $trans->getTaxonomyFilterLabel($def->getMappedTaxonomyFilter());
158 $filterTitle[] = $trans->getTypeFilterLabel($def->getTypeFilter());
159 if (!empty($filterTitle)) {
160 $title .= ' -> ' . implode(' / ', $filterTitle);
161 }
162 return $title;
163 }
164
165 public static function hasActiveRun(int $a_container_id, int $a_test_ref_id, int $a_objective_id): bool
166 {
167 return false;
168 }
169
170 public static function getTestResultLinkForUser(int $a_test_ref_id, int $a_user_id): string
171 {
172 global $DIC;
173
174 $ilCtrl = $DIC->ctrl();
175 $ilUser = $DIC->user();
176 $ilAccess = $DIC->access();
177
178 if ($ilUser->getId() == ANONYMOUS_USER_ID) {
179 return '';
180 }
181
182 $valid = $tutor = false;
183 if ($a_user_id == $ilUser->getId()) {
184 $valid = $ilAccess->checkAccess('read', '', $a_test_ref_id);
185 }
186 if (!$valid) {
187 $valid = $ilAccess->checkAccess('write', '', $a_test_ref_id);
188 $tutor = true;
189 }
190 if ($valid) {
191 $testObjId = ilObject::_lookupObjId($a_test_ref_id);
192 if (!$tutor) {
193 if (ilObjTestAccess::visibleUserResultExists($testObjId, $a_user_id)) {
194 $ilCtrl->setParameterByClass('ilObjTestGUI', 'ref_id', $a_test_ref_id);
195 $ctrlClasses = array('ilRepositoryGUI', 'ilObjTestGUI', 'ilTestResultsGUI');
196 $link = $ilCtrl->getLinkTargetByClass($ctrlClasses);
197 $ilCtrl->setParameterByClass('ilObjTestGUI', 'ref_id', '');
198 return $link;
199 }
200 } else {
201 $testId = ilObjTest::_getTestIDFromObjectID($testObjId);
202 if ($testId) {
203 $userActiveId = ilObjTest::_getActiveIdOfUser($a_user_id, $testId);
204 if ($userActiveId) {
205 $ilCtrl->setParameterByClass('ilTestEvaluationGUI', 'ref_id', $a_test_ref_id);
206 $ilCtrl->setParameterByClass('ilTestEvaluationGUI', 'active_id', $userActiveId);
207 $link = $ilCtrl->getLinkTargetByClass(array('ilRepositoryGUI',
208 'ilObjTestGUI',
209 'ilTestEvaluationGUI'
210 ), 'outParticipantsResultsOverview');
211 $ilCtrl->setParameterByClass('ilTestEvaluationGUI', 'ref_id', '');
212 $ilCtrl->setParameterByClass('ilTestEvaluationGUI', 'active_id', '');
213 return $link;
214 }
215 }
216 }
217 }
218 return '';
219 }
220}
static loookupTestLimit(int $a_test_id, int $a_objective_id)
static lookupLimit(int $a_container_id, int $a_objective_id, int $a_test_type)
Settings for LO courses.
static getInstance(int $a_container_id)
Settings for LO courses.
static buildQplTitleByDefinition(ilTestRandomQuestionSetSourcePoolDefinition $def, ilTestQuestionFilterLabelTranslator $trans)
static lookupObjectiveRequiredPercentage(int $a_container_id, int $a_objective_id, int $a_test_ref_id, int $a_max_points)
static isCompleted(int $a_cont_oid, int $a_test_rid, int $a_objective_id, int $max_points, int $reached, int $limit_perc)
Check if objective is completed.
static lookupRandomTest(int $a_test_obj_id)
static hasActiveRun(int $a_container_id, int $a_test_ref_id, int $a_objective_id)
static lookupMaxAttempts(int $a_container_id, int $a_objective_id, int $a_test_ref_id)
static getTestResultLinkForUser(int $a_test_ref_id, int $a_user_id)
static visibleUserResultExists(int $test_obj_id, int $user_id)
static _getTestIDFromObjectID($object_id)
Returns the ILIAS test id for a given object id.
static _lookupRandomTest(int $obj_id)
static _getActiveIdOfUser($user_id="", $test_id="")
Class ilObjectFactory This class offers methods to get instances of the type-specific object classes ...
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
static _lookupObjId(int $ref_id)
getTaxonomyFilterLabel(array $filter=[], string $filter_delimiter='+', string $tax_node_delimiter=':', string $nodes_delimiter=', ')
const ANONYMOUS_USER_ID
Definition: constants.php:27
$valid
global $DIC
Definition: shib_login.php:26