ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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  if(!$max_points)
35  {
36  return TRUE;
37  }
38  else
39  {
40  return ($reached / $max_points * 100) >= $limit_perc;
41  }
42  }
43  }
44 
51  public static function lookupObjectiveRequiredPercentage($a_container_id, $a_objective_id, $a_test_type, $a_max_points)
52  {
53  include_once './Modules/Course/classes/Objectives/class.ilLOSettings.php';
54  $settings = ilLOSettings::getInstanceByObjId($a_container_id);
55 
56  if($a_test_type == ilLOSettings::TYPE_TEST_QUALIFIED)
57  {
58  $tst_ref_id = $settings->getQualifiedTest();
59  }
60  else
61  {
62  $tst_ref_id = $settings->getInitialTest();
63  }
64  if(self::lookupRandomTest(ilObject::_lookupObjId($tst_ref_id)))
65  {
66  include_once './Modules/Course/classes/Objectives/class.ilLORandomTestQuestionPools.php';
67  return (int) ilLORandomTestQuestionPools::lookupLimit($a_container_id, $a_objective_id, $a_test_type);
68  }
69  else
70  {
71  include_once './Modules/Course/classes/class.ilCourseObjectiveQuestion.php';
72  $limit = ilCourseObjectiveQuestion::loookupTestLimit(ilObject::_lookupObjId($tst_ref_id), $a_objective_id);
73  return $limit;
74  }
75  }
76 
84  public static function lookupMaxAttempts($a_container_id, $a_objective_id)
85  {
86  include_once './Modules/Course/classes/Objectives/class.ilLOSettings.php';
87  $settings = ilLOSettings::getInstanceByObjId($a_container_id);
88  if($settings->isGeneralQualifiedTestVisible())
89  {
90  return 0;
91  }
92  include_once './Modules/Course/classes/class.ilCourseObjective.php';
93  $max_passes = ilCourseObjective::lookupMaxPasses($a_objective_id);
94 
95  return (int) $max_passes;
96  }
97 
98 
104  public static function lookupRandomTest($a_test_obj_id)
105  {
106  include_once './Modules/Test/classes/class.ilObjTest.php';
107  return ilObjTest::_lookupRandomTest($a_test_obj_id);
108  }
109 
116  public static function lookupQplBySequence($a_test_ref_id, $a_sequence_id)
117  {
118  if(!$a_sequence_id)
119  {
120  return '';
121  }
122  $tst = ilObjectFactory::getInstanceByRefId($a_test_ref_id,false);
123  if(!$tst instanceof ilObjTest)
124  {
125  return '';
126  }
127  include_once './Modules/Test/classes/class.ilTestRandomQuestionSetSourcePoolDefinitionList.php';
128  include_once './Modules/Test/classes/class.ilTestRandomQuestionSetSourcePoolDefinitionFactory.php';
130  $GLOBALS['ilDB'],
131  $tst,
133  $GLOBALS['ilDB'],
134  $tst
135  )
136  );
137 
138  $list->loadDefinitions();
139 
140  include_once './Modules/Test/classes/class.ilTestTaxonomyFilterLabelTranslater.php';
141  $translator = new ilTestTaxonomyFilterLabelTranslater($GLOBALS['ilDB']);
142  $translator->loadLabels($list);
143 
144  $title = '';
145  foreach ($list as $definition)
146  {
147  if($definition->getId() != $a_sequence_id)
148  {
149  continue;
150  }
151  $title = self::buildQplTitleByDefinition($definition, $translator);
152  }
153  return $title;
154  }
155 
161  {
162  $title = $def->getPoolTitle();
163  $tax_id = $def->getMappedFilterTaxId();
164  if($tax_id)
165  {
166  $title .= (' -> '. $trans->getTaxonomyTreeLabel($tax_id));
167  }
168  $tax_node = $def->getMappedFilterTaxNodeId();
169  if($tax_node)
170  {
171  $title .= (' -> ' .$trans->getTaxonomyNodeLabel($tax_node));
172  }
173  return $title;
174  }
175 
176  public static function hasActiveRun($a_container_id, $a_test_ref_id, $a_objective_id)
177  {
178  // check if pass exists
179  include_once './Modules/Test/classes/class.ilObjTest.php';
180  if(
182  $a_test_ref_id,
183  $GLOBALS['ilUser']->getId())
184  )
185  {
186  return false;
187  }
188 
189  // check if multiple pass exists
190  include_once './Modules/Course/classes/Objectives/class.ilLOTestRun.php';
191  $last_objectives = ilLOTestRun::lookupObjectives(
192  $a_container_id,
193  $GLOBALS['ilUser']->getId(),
194  ilObject::_lookupObjId($a_test_ref_id)
195  );
196 
197  if(count((array) $last_objectives) and in_array((int) $a_objective_id, (array) $last_objectives))
198  {
199  return true;
200  }
201  return false;
202  }
203 }
204 ?>