ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilLOTestAssignments.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
11 {
12  private static $instances = array();
13 
14  private $container_id = 0;
15  private $assignments = array();
16 
17  private $settings = null;
18 
19 
24  public function __construct($a_container_id)
25  {
26  $this->container_id = $a_container_id;
27 
28  include_once './Modules/Course/classes/Objectives/class.ilLOSettings.php';
29  $this->settings = ilLOSettings::getInstanceByObjId($a_container_id);
30  $this->readTestAssignments();
31 
32  }
33 
39  public static function getInstance($a_container_id)
40  {
41  if(self::$instances[$a_container_id])
42  {
43  return self::$instances[$a_container_id];
44  }
45  return self::$instances[$a_container_id] = new self($a_container_id);
46  }
47 
52  public static function lookupContainerForTest($a_test_ref_id)
53  {
54  global $ilDB;
55 
56  $query = 'SELECT container_id FROM loc_tst_assignments '.
57  'WHERE tst_ref_id = '.$ilDB->quote($a_test_ref_id,'integer');
58  $res = $ilDB->query($query);
59  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
60  {
61  return $row->container_id;
62  }
63  return 0;
64  }
65 
66  public function getContainerId()
67  {
68  return $this->container_id;
69  }
70 
75  public function getSettings()
76  {
77  return $this->settings;
78  }
79 
84  public function getAssignments()
85  {
86  return $this->assignments;
87  }
88 
94  public static function deleteByContainer($a_container_id)
95  {
96  global $ilDB;
97 
98  $query = 'DELETE FROM loc_tst_assignments '.
99  'WHERE container_id = '.$ilDB->quote($a_container_id,'integer');
100  $ilDB->manipulate($query);
101  }
102 
103  public function getAssignmentsByType($a_type)
104  {
105  $by_type = array();
106  foreach($this->assignments as $assignment)
107  {
108  if($assignment->getAssignmentType() == $a_type)
109  {
110  $by_type[] = $assignment;
111  }
112  }
113  return $by_type;
114  }
115 
120  public function getTests()
121  {
122  $tests = array();
123  if($this->getSettings()->getInitialTest())
124  {
125  $tests[] = $this->getSettings()->getInitialTest();
126  }
127  if($this->getSettings()->getQualifiedTest())
128  {
129  $tests[] = $this->getSettings()->getQualifiedTest();
130  }
131  foreach($this->assignments as $assignment)
132  {
133  $tests[] = $assignment->getTestRefId();
134  }
135  return $tests;
136  }
137 
144  public function getTestByObjective($a_objective_id, $a_type)
145  {
146  switch($a_type)
147  {
149  if(!$this->getSettings()->hasSeparateInitialTests())
150  {
151  return $this->getSettings()->getInitialTest();
152  }
153  break;
154 
156  if(!$this->getSettings()->hasSeparateQualifiedTests())
157  {
158  return $this->getSettings()->getQualifiedTest();
159  }
160  break;
161  }
162 
163  $assignment = $this->getAssignmentByObjective($a_objective_id, $a_type);
164  if($assignment)
165  {
166  return $assignment->getTestRefId();
167  }
168  return 0;
169  }
170 
171  public function isSeparateTest($a_test_ref_id)
172  {
173  if(!$this->getSettings()->hasSeparateInitialTests())
174  {
175  if($this->getSettings()->getInitialTest() == $a_test_ref_id)
176  {
177  return FALSE;
178  }
179  }
180  if(!$this->getSettings()->hasSeparateQualifiedTests())
181  {
182  if($this->getSettings()->getQualifiedTest() == $a_test_ref_id)
183  {
184  return FALSE;
185  }
186  }
187  return TRUE;
188  }
189 
194  public function getTypeByTest($a_test_ref_id)
195  {
196  if($this->getSettings()->worksWithInitialTest() && !$this->getSettings()->hasSeparateInitialTests())
197  {
198  if($this->getSettings()->getInitialTest() == $a_test_ref_id)
199  {
201  }
202  }
203  elseif($this->getSettings()->worksWithInitialTest())
204  {
205  foreach($this->assignments as $assignment)
206  {
207  if($assignment->getTestRefId() == $a_test_ref_id)
208  {
210  }
211  }
212 
213  }
214  if(!$this->getSettings()->hasSeparateQualifiedTests())
215  {
216  if($this->getSettings()->getQualifiedTest() == $a_test_ref_id)
217  {
219  }
220  }
221  else
222  {
223  foreach($this->assignments as $assignment)
224  {
225  if($assignment->getTestRefId() == $a_test_ref_id)
226  {
228  }
229  }
230  }
232  }
233 
234 
241  public function getAssignmentByObjective($a_objective_id, $a_type)
242  {
243 
244  foreach($this->assignments as $assignment)
245  {
246  if(
247  ($assignment->getObjectiveId() == $a_objective_id) &&
248  ($assignment->getAssignmentType() == $a_type)
249  )
250  {
251  return $assignment;
252  }
253  }
254  return FALSE;
255  }
256 
261  protected function readTestAssignments()
262  {
263  global $ilDB;
264 
265  $query = 'SELECT assignment_id FROM loc_tst_assignments '.
266  'WHERE container_id = '.$ilDB->quote($this->getContainerId(),'integer');
267  $res = $ilDB->query($query);
268  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
269  {
270  include_once './Modules/Course/classes/Objectives/class.ilLOTestAssignment.php';
271  $assignment = new ilLOTestAssignment($row->assignment_id);
272 
273  $this->assignments[] = $assignment;
274  }
275  }
276 
281  public function toXml(ilXmlWriter $writer, $a_objective_id)
282  {
283  foreach($this->getAssignments() as $assignment)
284  {
285  if($assignment->getObjectiveId() != $a_objective_id)
286  {
287  continue;
288  }
289 
290  include_once './Modules/Course/classes/Objectives/class.ilLOXmlWriter.php';
291  $writer->xmlElement(
292  'Test',
293  array(
294  'type' => ilLOXmlWriter::TYPE_TST_PO,
295  'refId' => $assignment->getTestRefId(),
296  'testType' => $assignment->getAssignmentType()
297  )
298  );
299  }
300  }
301 
302 
308  public static function lookupObjectivesForTest($a_test_ref_id)
309  {
310  global $ilDB;
311 
312  $objectives = array();
313 
314  $query = 'SELECT objective_id FROM loc_tst_assignments '.
315  'WHERE tst_ref_id = '.$ilDB->quote($a_test_ref_id,'integer');
316  $res = $ilDB->query($query);
317  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
318  {
319  $objectives[] = $row->objective_id;
320  }
321  return $objectives;
322  }
323 }
324 ?>
static getInstanceByObjId($a_obj_id)
get singleton instance
static getInstance($a_container_id)
Get instance by container id.
getSettings()
get objective settings
Settings for LO courses.
__construct($a_container_id)
Constructor.
XML writer class.
xmlElement($tag, $attrs=NULL, $data=Null, $encode=TRUE, $escape=TRUE)
Writes a basic element (no children, just textual content)
$a_type
Definition: workflow.php:93
getTests()
Get all assigned tests.
getAssignmentByObjective($a_objective_id, $a_type)
Get assignment by objective.
getTestByObjective($a_objective_id, $a_type)
readTestAssignments()
Read assignments type $ilDB.
static deleteByContainer($a_container_id)
Delete assignments by container id (obj_id of course) type $ilDB.
getAssignments()
Get assignments.
Create styles array
The data for the language used.
static lookupObjectivesForTest($a_test_ref_id)
Get all objectives that are assigned to given test.
static lookupContainerForTest($a_test_ref_id)
Settings for LO courses.
settings()
Definition: settings.php:2
global $ilDB
toXml(ilXmlWriter $writer, $a_objective_id)
to xml
getTypeByTest($a_test_ref_id)
Get test type by test id.