ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
All Data Structures Namespaces Files Functions Variables Typedefs Modules Pages
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 $ilDB;
53 
54  $query = 'SELECT container_id FROM loc_tst_assignments ' .
55  'WHERE tst_ref_id = ' . $ilDB->quote($a_test_ref_id, 'integer');
56  $res = $ilDB->query($query);
57  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
58  return $row->container_id;
59  }
60  return 0;
61  }
62 
63  public function getContainerId()
64  {
65  return $this->container_id;
66  }
67 
72  public function getSettings()
73  {
74  return $this->settings;
75  }
76 
81  public function getAssignments()
82  {
83  return $this->assignments;
84  }
85 
91  public static function deleteByContainer($a_container_id)
92  {
93  global $ilDB;
94 
95  $query = 'DELETE FROM loc_tst_assignments ' .
96  'WHERE container_id = ' . $ilDB->quote($a_container_id, 'integer');
97  $ilDB->manipulate($query);
98  }
99 
100  public function getAssignmentsByType($a_type)
101  {
102  $by_type = array();
103  foreach ($this->assignments as $assignment) {
104  if ($assignment->getAssignmentType() == $a_type) {
105  $by_type[] = $assignment;
106  }
107  }
108  return $by_type;
109  }
110 
115  public function getTests()
116  {
117  $tests = array();
118  if ($this->getSettings()->getInitialTest()) {
119  $tests[] = $this->getSettings()->getInitialTest();
120  }
121  if ($this->getSettings()->getQualifiedTest()) {
122  $tests[] = $this->getSettings()->getQualifiedTest();
123  }
124  foreach ($this->assignments as $assignment) {
125  $tests[] = $assignment->getTestRefId();
126  }
127  return $tests;
128  }
129 
136  public function getTestByObjective($a_objective_id, $a_type)
137  {
138  switch ($a_type) {
140  if (!$this->getSettings()->hasSeparateInitialTests()) {
141  return $this->getSettings()->getInitialTest();
142  }
143  break;
144 
146  if (!$this->getSettings()->hasSeparateQualifiedTests()) {
147  return $this->getSettings()->getQualifiedTest();
148  }
149  break;
150  }
151 
152  $assignment = $this->getAssignmentByObjective($a_objective_id, $a_type);
153  if ($assignment) {
154  return $assignment->getTestRefId();
155  }
156  return 0;
157  }
158 
159  public function isSeparateTest($a_test_ref_id)
160  {
161  if (!$this->getSettings()->hasSeparateInitialTests()) {
162  if ($this->getSettings()->getInitialTest() == $a_test_ref_id) {
163  return false;
164  }
165  }
166  if (!$this->getSettings()->hasSeparateQualifiedTests()) {
167  if ($this->getSettings()->getQualifiedTest() == $a_test_ref_id) {
168  return false;
169  }
170  }
171  return true;
172  }
173 
178  public function getTypeByTest($a_test_ref_id)
179  {
180  if ($this->getSettings()->worksWithInitialTest() && !$this->getSettings()->hasSeparateInitialTests()) {
181  if ($this->getSettings()->getInitialTest() == $a_test_ref_id) {
183  }
184  } elseif ($this->getSettings()->worksWithInitialTest()) {
185  foreach ($this->assignments as $assignment) {
186  if ($assignment->getTestRefId() == $a_test_ref_id) {
188  }
189  }
190  }
191  if (!$this->getSettings()->hasSeparateQualifiedTests()) {
192  if ($this->getSettings()->getQualifiedTest() == $a_test_ref_id) {
194  }
195  } else {
196  foreach ($this->assignments as $assignment) {
197  if ($assignment->getTestRefId() == $a_test_ref_id) {
199  }
200  }
201  }
203  }
204 
205 
212  public function getAssignmentByObjective($a_objective_id, $a_type)
213  {
214  foreach ($this->assignments as $assignment) {
215  if (
216  ($assignment->getObjectiveId() == $a_objective_id) &&
217  ($assignment->getAssignmentType() == $a_type)
218  ) {
219  return $assignment;
220  }
221  }
222  return false;
223  }
224 
229  protected function readTestAssignments()
230  {
231  global $ilDB;
232 
233  $query = 'SELECT assignment_id FROM loc_tst_assignments ' .
234  'WHERE container_id = ' . $ilDB->quote($this->getContainerId(), 'integer');
235  $res = $ilDB->query($query);
236  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
237  include_once './Modules/Course/classes/Objectives/class.ilLOTestAssignment.php';
238  $assignment = new ilLOTestAssignment($row->assignment_id);
239 
240  $this->assignments[] = $assignment;
241  }
242  }
243 
248  public function toXml(ilXmlWriter $writer, $a_objective_id)
249  {
250  foreach ($this->getAssignments() as $assignment) {
251  if ($assignment->getObjectiveId() != $a_objective_id) {
252  continue;
253  }
254 
255  include_once './Modules/Course/classes/Objectives/class.ilLOXmlWriter.php';
256  $writer->xmlElement(
257  'Test',
258  array(
259  'type' => ilLOXmlWriter::TYPE_TST_PO,
260  'refId' => $assignment->getTestRefId(),
261  'testType' => $assignment->getAssignmentType()
262  )
263  );
264  }
265  }
266 
267 
273  public static function lookupObjectivesForTest($a_test_ref_id)
274  {
275  global $ilDB;
276 
277  $objectives = array();
278 
279  $query = 'SELECT objective_id FROM loc_tst_assignments ' .
280  'WHERE tst_ref_id = ' . $ilDB->quote($a_test_ref_id, 'integer');
281  $res = $ilDB->query($query);
282  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
283  $objectives[] = $row->objective_id;
284  }
285  return $objectives;
286  }
287 }
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.
$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.
static deleteByContainer($a_container_id)
Delete assignments by container id (obj_id of course) type $ilDB.
$query
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)
xmlElement($tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
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.