ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilLOUtils.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=0);
24 class ilLOUtils
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 {
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 {
46  $required_perc = self::lookupObjectiveRequiredPercentage(
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 {
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  $query = 'SELECT nr_of_tries FROM tst_tests ' .
104  'WHERE obj_fi = ' . $ilDB->quote(ilObject::_lookupObjId($a_test_ref_id), 'integer');
105  $res = $ilDB->query($query);
106  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
107  return (int) $row->nr_of_tries;
108  }
109  return 0;
110  }
111 
112  public static function lookupRandomTest(int $a_test_obj_id): bool
113  {
114  return ilObjTest::_lookupRandomTest($a_test_obj_id);
115  }
116 
120  public static function lookupQplBySequence(int $a_test_ref_id, int $a_sequence_id): string
121  {
122  global $DIC;
123 
124  if (!$a_sequence_id) {
125  return '';
126  }
127  $tst = ilObjectFactory::getInstanceByRefId($a_test_ref_id, false);
128  if (!$tst instanceof ilObjTest) {
129  return '';
130  }
132  $DIC->database(),
133  $tst,
135  $DIC->database(),
136  $tst
137  )
138  );
139 
140  $list->loadDefinitions();
141 
142  $translator = new ilTestTaxonomyFilterLabelTranslater($GLOBALS['DIC']['ilDB']);
143  $translator->loadLabels($list);
144 
145  $title = '';
146  foreach ($list as $definition) {
147  if ($definition->getId() != $a_sequence_id) {
148  continue;
149  }
150  $title = self::buildQplTitleByDefinition($definition, $translator);
151  }
152  return $title;
153  }
154 
155  protected static function buildQplTitleByDefinition(
158  ): string {
159  $title = $def->getPoolTitle();
160  $filterTitle = array();
161  $filterTitle[] = $trans->getTaxonomyFilterLabel($def->getMappedTaxonomyFilter());
162  $filterTitle[] = $trans->getTypeFilterLabel($def->getTypeFilter());
163  if (!empty($filterTitle)) {
164  $title .= ' -> ' . implode(' / ', $filterTitle);
165  }
166  return $title;
167  }
168 
169  public static function hasActiveRun(int $a_container_id, int $a_test_ref_id, int $a_objective_id): bool
170  {
171  return false;
172  }
173 
174  public static function getTestResultLinkForUser(int $a_test_ref_id, int $a_user_id): string
175  {
176  global $DIC;
177 
178  $ilCtrl = $DIC->ctrl();
179  $ilUser = $DIC->user();
180  $ilAccess = $DIC->access();
181 
182  if ($ilUser->getId() == ANONYMOUS_USER_ID) {
183  return '';
184  }
185 
186  $valid = $tutor = false;
187  if ($a_user_id == $ilUser->getId()) {
188  $valid = $ilAccess->checkAccess('read', '', $a_test_ref_id);
189  }
190  if (!$valid) {
191  $valid = $ilAccess->checkAccess('write', '', $a_test_ref_id);
192  $tutor = true;
193  }
194  if ($valid) {
195  $testObjId = ilObject::_lookupObjId($a_test_ref_id);
196  if (!$tutor) {
197  if (ilObjTestAccess::visibleUserResultExists($testObjId, $a_user_id)) {
198  $ilCtrl->setParameterByClass('ilObjTestGUI', 'ref_id', $a_test_ref_id);
199  $ctrlClasses = array('ilRepositoryGUI', 'ilObjTestGUI', 'ilTestResultsGUI');
200  $link = $ilCtrl->getLinkTargetByClass($ctrlClasses);
201  $ilCtrl->setParameterByClass('ilObjTestGUI', 'ref_id', '');
202  return $link;
203  }
204  } else {
205  $testId = ilObjTest::_getTestIDFromObjectID($testObjId);
206  if ($testId) {
207  $userActiveId = ilObjTest::_getActiveIdOfUser($a_user_id, $testId);
208  if ($userActiveId) {
209  $ilCtrl->setParameterByClass('ilTestEvaluationGUI', 'ref_id', $a_test_ref_id);
210  $ilCtrl->setParameterByClass('ilTestEvaluationGUI', 'active_id', $userActiveId);
211  $link = $ilCtrl->getLinkTargetByClass(array('ilRepositoryGUI',
212  'ilObjTestGUI',
213  'ilTestEvaluationGUI'
214  ), 'outParticipantsResultsOverview');
215  $ilCtrl->setParameterByClass('ilTestEvaluationGUI', 'ref_id', '');
216  $ilCtrl->setParameterByClass('ilTestEvaluationGUI', 'active_id', '');
217  return $link;
218  }
219  }
220  }
221  }
222  return '';
223  }
224 }
static hasActiveRun(int $a_container_id, int $a_test_ref_id, int $a_objective_id)
static lookupLimit(int $a_container_id, int $a_objective_id, int $a_test_type)
static lookupQplBySequence(int $a_test_ref_id, int $a_sequence_id)
Lookup assigned qpl name (including taxonomy) by sequence.
$res
Definition: ltiservices.php:69
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
const ANONYMOUS_USER_ID
Definition: constants.php:27
static _lookupRandomTest($a_obj_id)
Returns the fact wether the test with passed obj id is a random questions test or not...
$valid
getTaxonomyFilterLabel($filter=array(), $filterDelimiter='+', $taxNodeDelimiter=':', $nodesDelimiter=', ')
Get the label for a taxonomy filter.
static loookupTestLimit(int $a_test_id, int $a_objective_id)
static lookupObjectiveRequiredPercentage(int $a_container_id, int $a_objective_id, int $a_test_ref_id, int $a_max_points)
static _lookupObjId(int $ref_id)
global $DIC
Definition: feed.php:28
static getTestResultLinkForUser(int $a_test_ref_id, int $a_user_id)
static visibleUserResultExists($testObjId, $userId)
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
$query
static _getTestIDFromObjectID($object_id)
Returns the ILIAS test id for a given object id.
getTypeFilterLabel($filter=array())
Get the label for a type filter.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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 getInstanceByObjId(int $a_obj_id)
static lookupRandomTest(int $a_test_obj_id)
$ilUser
Definition: imgupload.php:34
static getInstance(int $a_container_id)
$factory
Definition: metadata.php:75
static lookupMaxAttempts(int $a_container_id, int $a_objective_id, int $a_test_ref_id)
static _getActiveIdOfUser($user_id="", $test_id="")
static buildQplTitleByDefinition(ilTestRandomQuestionSetSourcePoolDefinition $def, ilTestTaxonomyFilterLabelTranslater $trans)