ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
38  public static function getInstance($a_container_id)
39  {
40  if (self::$instances[$a_container_id]) {
41  return self::$instances[$a_container_id];
42  }
43  return self::$instances[$a_container_id] = new self($a_container_id);
44  }
45 
50  public static function lookupContainerForTest($a_test_ref_id)
51  {
52  global $DIC;
53 
54  $ilDB = $DIC['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  return $row->container_id;
61  }
62  return 0;
63  }
64 
65  public function getContainerId()
66  {
67  return $this->container_id;
68  }
69 
74  public function getSettings()
75  {
76  return $this->settings;
77  }
78 
83  public function getAssignments()
84  {
85  return $this->assignments;
86  }
87 
93  public static function deleteByContainer($a_container_id)
94  {
95  global $DIC;
96 
97  $ilDB = $DIC['ilDB'];
98 
99  $query = 'DELETE FROM loc_tst_assignments ' .
100  'WHERE container_id = ' . $ilDB->quote($a_container_id, 'integer');
101  $ilDB->manipulate($query);
102  }
103 
104  public function getAssignmentsByType($a_type)
105  {
106  $by_type = array();
107  foreach ($this->assignments as $assignment) {
108  if ($assignment->getAssignmentType() == $a_type) {
109  $by_type[] = $assignment;
110  }
111  }
112  return $by_type;
113  }
114 
119  public function getTests()
120  {
121  $tests = array();
122  if ($this->getSettings()->getInitialTest()) {
123  $tests[] = $this->getSettings()->getInitialTest();
124  }
125  if ($this->getSettings()->getQualifiedTest()) {
126  $tests[] = $this->getSettings()->getQualifiedTest();
127  }
128  foreach ($this->assignments as $assignment) {
129  $tests[] = $assignment->getTestRefId();
130  }
131  return $tests;
132  }
133 
140  public function getTestByObjective($a_objective_id, $a_type)
141  {
142  switch ($a_type) {
144  if (!$this->getSettings()->hasSeparateInitialTests()) {
145  return $this->getSettings()->getInitialTest();
146  }
147  break;
148 
150  if (!$this->getSettings()->hasSeparateQualifiedTests()) {
151  return $this->getSettings()->getQualifiedTest();
152  }
153  break;
154  }
155 
156  $assignment = $this->getAssignmentByObjective($a_objective_id, $a_type);
157  if ($assignment) {
158  return $assignment->getTestRefId();
159  }
160  return 0;
161  }
162 
163  public function isSeparateTest($a_test_ref_id)
164  {
165  if (!$this->getSettings()->hasSeparateInitialTests()) {
166  if ($this->getSettings()->getInitialTest() == $a_test_ref_id) {
167  return false;
168  }
169  }
170  if (!$this->getSettings()->hasSeparateQualifiedTests()) {
171  if ($this->getSettings()->getQualifiedTest() == $a_test_ref_id) {
172  return false;
173  }
174  }
175  return true;
176  }
177 
182  public function getTypeByTest($a_test_ref_id)
183  {
184  if ($this->getSettings()->worksWithInitialTest() && !$this->getSettings()->hasSeparateInitialTests()) {
185  if ($this->getSettings()->getInitialTest() == $a_test_ref_id) {
187  }
188  } elseif ($this->getSettings()->worksWithInitialTest()) {
189  foreach ($this->assignments as $assignment) {
190  if ($assignment->getTestRefId() == $a_test_ref_id) {
192  }
193  }
194  }
195  if (!$this->getSettings()->hasSeparateQualifiedTests()) {
196  if ($this->getSettings()->getQualifiedTest() == $a_test_ref_id) {
198  }
199  } else {
200  foreach ($this->assignments as $assignment) {
201  if ($assignment->getTestRefId() == $a_test_ref_id) {
203  }
204  }
205  }
207  }
208 
209 
216  public function getAssignmentByObjective($a_objective_id, $a_type)
217  {
218  foreach ($this->assignments as $assignment) {
219  if (
220  ($assignment->getObjectiveId() == $a_objective_id) &&
221  ($assignment->getAssignmentType() == $a_type)
222  ) {
223  return $assignment;
224  }
225  }
226  return false;
227  }
228 
233  protected function readTestAssignments()
234  {
235  global $DIC;
236 
237  $ilDB = $DIC['ilDB'];
238 
239  $query = 'SELECT assignment_id FROM loc_tst_assignments ' .
240  'WHERE container_id = ' . $ilDB->quote($this->getContainerId(), 'integer');
241  $res = $ilDB->query($query);
242  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
243  include_once './Modules/Course/classes/Objectives/class.ilLOTestAssignment.php';
244  $assignment = new ilLOTestAssignment($row->assignment_id);
245 
246  $this->assignments[] = $assignment;
247  }
248  }
249 
254  public function toXml(ilXmlWriter $writer, $a_objective_id)
255  {
256  foreach ($this->getAssignments() as $assignment) {
257  if ($assignment->getObjectiveId() != $a_objective_id) {
258  continue;
259  }
260 
261  include_once './Modules/Course/classes/Objectives/class.ilLOXmlWriter.php';
262  $writer->xmlElement(
263  'Test',
264  array(
265  'type' => ilLOXmlWriter::TYPE_TST_PO,
266  'refId' => $assignment->getTestRefId(),
267  'testType' => $assignment->getAssignmentType()
268  )
269  );
270  }
271  }
272 
273 
279  public static function lookupObjectivesForTest($a_test_ref_id)
280  {
281  global $DIC;
282 
283  $ilDB = $DIC['ilDB'];
284 
285  $objectives = array();
286 
287  $query = 'SELECT objective_id FROM loc_tst_assignments ' .
288  'WHERE tst_ref_id = ' . $ilDB->quote($a_test_ref_id, 'integer');
289  $res = $ilDB->query($query);
290  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
291  $objectives[] = $row->objective_id;
292  }
293  return $objectives;
294  }
295 }
static getInstanceByObjId($a_obj_id)
get singleton instance
static getInstance($a_container_id)
Get instance by container id.
settings()
Definition: settings.php:2
getSettings()
get objective settings
global $DIC
Definition: saml.php:7
Settings for LO courses.
__construct($a_container_id)
Constructor.
XML writer class.
$a_type
Definition: workflow.php:92
getTests()
Get all assigned tests.
getAssignmentByObjective($a_objective_id, $a_type)
Get assignment by objective.
foreach($_POST as $key=> $value) $res
getTestByObjective($a_objective_id, $a_type)
readTestAssignments()
Read assignments type $ilDB.
$tests
Definition: bench.php:104
static deleteByContainer($a_container_id)
Delete assignments by container id (obj_id of course) type $ilDB.
$query
getAssignments()
Get assignments.
static lookupObjectivesForTest($a_test_ref_id)
Get all objectives that are assigned to given test.
$row
static lookupContainerForTest($a_test_ref_id)
xmlElement($tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
Settings for LO courses.
global $ilDB
toXml(ilXmlWriter $writer, $a_objective_id)
to xml
getTypeByTest($a_test_ref_id)
Get test type by test id.