ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilLOUtils.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
10 class ilLOUtils
11 {
12 
16  public static function isCompleted($a_cont_oid, $a_test_rid, $a_objective_id, $max_points, $reached, $limit_perc)
17  {
18  include_once './Modules/Course/classes/Objectives/class.ilLOSettings.php';
19  $settings = ilLOSettings::getInstanceByObjId($a_cont_oid);
20 
21  if(self::lookupRandomTest(ilObject::_lookupObjId($a_test_rid)))
22  {
23  if(!$max_points)
24  {
25  return true;
26  }
27  else
28  {
29  return ($reached / $max_points * 100) >= $limit_perc;
30  }
31  }
32  else
33  {
34  $required_perc = self::lookupObjectiveRequiredPercentage($a_cont_oid, $a_objective_id, $a_test_rid, $max_points);
35 
36  if(!$max_points)
37  {
38  return TRUE;
39  }
40  else
41  {
42  return ($reached / $max_points * 100) >= $required_perc;
43  }
44  }
45  }
46 
53  public static function lookupObjectiveRequiredPercentage($a_container_id, $a_objective_id, $a_test_ref_id, $a_max_points)
54  {
55  include_once './Modules/Course/classes/Objectives/class.ilLOSettings.php';
56  $settings = ilLOSettings::getInstanceByObjId($a_container_id);
57 
58  include_once './Modules/Course/classes/Objectives/class.ilLOTestAssignments.php';
59  $assignments = ilLOTestAssignments::getInstance($a_container_id);
60  $a_test_type = $assignments->getTypeByTest($a_test_ref_id);
61 
62  if($assignments->isSeparateTest($a_test_ref_id))
63  {
64  include_once './Services/Object/classes/class.ilObjectFactory.php';
65  $factory = new ilObjectFactory();
66  $tst = $factory->getInstanceByRefId($a_test_ref_id, FALSE);
67  if($tst instanceof ilObjTest)
68  {
69  $schema = $tst->getMarkSchema();
70  foreach($schema->getMarkSteps() as $mark)
71  {
72  if($mark->getPassed())
73  {
74  return (int) $mark->getMinimumLevel();
75  }
76  }
77  }
78  }
79 
80 
81 
82  $tst_ref_id = $a_test_ref_id;
83  if(self::lookupRandomTest(ilObject::_lookupObjId($tst_ref_id)))
84  {
85  include_once './Modules/Course/classes/Objectives/class.ilLORandomTestQuestionPools.php';
86  return (int) ilLORandomTestQuestionPools::lookupLimit($a_container_id, $a_objective_id, $a_test_type);
87  }
88  else
89  {
90  include_once './Modules/Course/classes/class.ilCourseObjectiveQuestion.php';
91  $limit = ilCourseObjectiveQuestion::loookupTestLimit(ilObject::_lookupObjId($tst_ref_id), $a_objective_id);
92  return $limit;
93  }
94  }
95 
103  public static function lookupMaxAttempts($a_container_id, $a_objective_id, $a_test_ref_id)
104  {
105  global $ilDB;
106 
107  include_once './Modules/Course/classes/Objectives/class.ilLOTestAssignments.php';
111  $assignments = ilLOTestAssignments::getInstance($a_container_id);
112  if(!$assignments->isSeparateTest($a_test_ref_id))
113  {
114  // no limit of tries for tests assigned to multiple objectives.
115  return 0;
116  }
117 
118  $query = 'SELECT nr_of_tries FROM tst_tests '.
119  'WHERE obj_fi = '.$ilDB->quote(ilObject::_lookupObjId($a_test_ref_id),'integer');
120  $res = $ilDB->query($query);
121  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
122  {
123  return (int) $row->nr_of_tries;
124  }
125  return 0;
126  }
127 
128 
134  public static function lookupRandomTest($a_test_obj_id)
135  {
136  include_once './Modules/Test/classes/class.ilObjTest.php';
137  return ilObjTest::_lookupRandomTest($a_test_obj_id);
138  }
139 
146  public static function lookupQplBySequence($a_test_ref_id, $a_sequence_id)
147  {
148  if(!$a_sequence_id)
149  {
150  return '';
151  }
152  $tst = ilObjectFactory::getInstanceByRefId($a_test_ref_id,false);
153  if(!$tst instanceof ilObjTest)
154  {
155  return '';
156  }
157  include_once './Modules/Test/classes/class.ilTestRandomQuestionSetSourcePoolDefinitionList.php';
158  include_once './Modules/Test/classes/class.ilTestRandomQuestionSetSourcePoolDefinitionFactory.php';
160  $GLOBALS['ilDB'],
161  $tst,
163  $GLOBALS['ilDB'],
164  $tst
165  )
166  );
167 
168  $list->loadDefinitions();
169 
170  include_once './Modules/Test/classes/class.ilTestTaxonomyFilterLabelTranslater.php';
171  $translator = new ilTestTaxonomyFilterLabelTranslater($GLOBALS['ilDB']);
172  $translator->loadLabels($list);
173 
174  $title = '';
175  foreach ($list as $definition)
176  {
177  if($definition->getId() != $a_sequence_id)
178  {
179  continue;
180  }
181  $title = self::buildQplTitleByDefinition($definition, $translator);
182  }
183  return $title;
184  }
185 
191  {
192  $title = $def->getPoolTitle();
193  $tax_id = $def->getMappedFilterTaxId();
194  if($tax_id)
195  {
196  $title .= (' -> '. $trans->getTaxonomyTreeLabel($tax_id));
197  }
198  $tax_node = $def->getMappedFilterTaxNodeId();
199  if($tax_node)
200  {
201  $title .= (' -> ' .$trans->getTaxonomyNodeLabel($tax_node));
202  }
203  return $title;
204  }
205 
206  public static function hasActiveRun($a_container_id, $a_test_ref_id, $a_objective_id)
207  {
208  return FALSE;
209 
210  // check if pass exists
211  include_once './Modules/Test/classes/class.ilObjTest.php';
212  if(
214  $a_test_ref_id,
215  $GLOBALS['ilUser']->getId())
216  )
217  {
218  return false;
219  }
220 
221  // check if multiple pass exists
222  include_once './Modules/Course/classes/Objectives/class.ilLOTestRun.php';
223  $last_objectives = ilLOTestRun::lookupObjectives(
224  $a_container_id,
225  $GLOBALS['ilUser']->getId(),
226  ilObject::_lookupObjId($a_test_ref_id)
227  );
228 
229  if(count((array) $last_objectives) and in_array((int) $a_objective_id, (array) $last_objectives))
230  {
231  return true;
232  }
233  return false;
234  }
235 
236  public static function getTestResultLinkForUser($a_test_ref_id, $a_user_id)
237  {
238  global $ilCtrl, $ilUser, $ilAccess;
239 
240  if($ilUser->getId() == ANONYMOUS_USER_ID)
241  {
242  return;
243  }
244 
245  $valid = $tutor = false;
246  if($a_user_id == $ilUser->getId())
247  {
248  $valid = $ilAccess->checkAccess('read', '', $a_test_ref_id);
249  }
250  if(!$valid)
251  {
252  $valid = $ilAccess->checkAccess('write', '', $a_test_ref_id);
253  $tutor = true;
254  }
255  if($valid)
256  {
257  $testObjId = ilObject::_lookupObjId($a_test_ref_id);
258  if(!$tutor)
259  {
260  require_once 'Modules/Test/classes/class.ilObjTestAccess.php';
261  if(ilObjTestAccess::visibleUserResultExists($testObjId, $a_user_id))
262  {
263  $ilCtrl->setParameterByClass('ilObjTestGUI', 'ref_id', $a_test_ref_id);
264  $link = $ilCtrl->getLinkTargetByClass(array('ilRepositoryGUI', 'ilObjTestGUI'), 'userResultsGateway');
265  $ilCtrl->setParameterByClass('ilObjTestGUI', 'ref_id', '');
266  return $link;
267  }
268  }
269  else
270  {
271  include_once 'Modules/Test/classes/class.ilObjTest.php';
272  $testId = ilObjTest::_getTestIDFromObjectID($testObjId);
273  if($testId)
274  {
275  $userActiveId = ilObjTest::_getActiveIdOfUser($a_user_id, $testId);
276  if($userActiveId)
277  {
278  $ilCtrl->setParameterByClass('ilTestEvaluationGUI', 'ref_id', $a_test_ref_id);
279  $ilCtrl->setParameterByClass('ilTestEvaluationGUI', 'active_id', $userActiveId);
280  $link = $ilCtrl->getLinkTargetByClass(array('ilRepositoryGUI', 'ilObjTestGUI', 'ilTestEvaluationGUI'), 'outParticipantsResultsOverview');
281  $ilCtrl->setParameterByClass('ilTestEvaluationGUI', 'ref_id', '');
282  $ilCtrl->setParameterByClass('ilTestEvaluationGUI', 'active_id', '');
283  return $link;
284  }
285  }
286  }
287  }
288  }
289 }
290 ?>
static isCompleted($a_cont_oid, $a_test_rid, $a_objective_id, $max_points, $reached, $limit_perc)
Check if objective is completed.
static getInstanceByObjId($a_obj_id)
get singleton instance
static loookupTestLimit($a_test_id, $a_objective_id)
static getInstance($a_container_id)
Get instance by container id.
Class ilObjectFactory.
static _lookupRandomTest($a_obj_id)
Returns the fact wether the test with passed obj id is a random questions test or not...
$valid
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
static hasActiveRun($a_container_id, $a_test_ref_id, $a_objective_id)
global $ilCtrl
Definition: ilias.php:18
static lookupObjectives($a_container_id, $a_user_id, $a_test_id)
static visibleUserResultExists($testObjId, $userId)
static lookupRandomTest($a_test_obj_id)
Check if test is a random test.
static _lookupObjId($a_id)
$ilUser
Definition: imgupload.php:18
static lookupObjectiveRequiredPercentage($a_container_id, $a_objective_id, $a_test_ref_id, $a_max_points)
static _getTestIDFromObjectID($object_id)
Returns the ILIAS test id for a given object id.
Create styles array
The data for the language used.
Settings for LO courses.
static getTestResultLinkForUser($a_test_ref_id, $a_user_id)
global $ilDB
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
static lookupLimit($a_container_id, $a_objective_id, $a_test_type)
static isParticipantsLastPassActive($testRefId, $userId)
static lookupQplBySequence($a_test_ref_id, $a_sequence_id)
Lookup assigned qpl name (including taxonomy) by sequence.
static _getActiveIdOfUser($user_id="", $test_id="")
Gets the active id of the tst_active table for the active user.
static buildQplTitleByDefinition(ilTestRandomQuestionSetSourcePoolDefinition $def, ilTestTaxonomyFilterLabelTranslater $trans)
build title by definition