ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLOTestAssignment.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=0);
26{
27 private int $assignment_id = 0;
28 private int $container_id = 0;
29 private int $assignment_type = 0;
30 private int $objective_id = 0;
31 private int $test_ref_id = 0;
32
33 protected ilDBInterface $db;
34
35 public function __construct(int $a_id = 0)
36 {
37 global $DIC;
38
39 $this->db = $DIC->database();
40 $this->setAssignmentId($a_id);
41 $this->read();
42 }
43
44 public function setAssignmentId(int $a_id): void
45 {
46 $this->assignment_id = $a_id;
47 }
48
49 public function getAssignmentId(): int
50 {
52 }
53
54 public function setContainerId(int $a_id): void
55 {
56 $this->container_id = $a_id;
57 }
58
59 public function getContainerId(): int
60 {
62 }
63
64 public function setAssignmentType(int $a_type): void
65 {
66 $this->assignment_type = $a_type;
67 }
68
69 public function getAssignmentType(): int
70 {
72 }
73
74 public function setObjectiveId(int $a_id): void
75 {
76 $this->objective_id = $a_id;
77 }
78
79 public function getObjectiveId(): int
80 {
82 }
83
84 public function setTestRefId(int $a_id): void
85 {
86 $this->test_ref_id = $a_id;
87 }
88
89 public function getTestRefId(): int
90 {
91 return $this->test_ref_id;
92 }
93
94 public function save(): void
95 {
96 if ($this->getAssignmentId()) {
97 $this->update();
98 } else {
99 $this->create();
100 }
101 }
102
103 public function create(): void
104 {
105 $this->setAssignmentId($this->db->nextId('loc_tst_assignments'));
106 $query = 'INSERT INTO loc_tst_assignments (assignment_id, container_id, assignment_type, objective_id, tst_ref_id) ' .
107 'VALUES ( ' .
108 $this->db->quote($this->getAssignmentId(), 'integer') . ', ' .
109 $this->db->quote($this->getContainerId(), 'integer') . ', ' .
110 $this->db->quote($this->getAssignmentType(), 'integer') . ', ' .
111 $this->db->quote($this->getObjectiveId(), 'integer') . ', ' .
112 $this->db->quote($this->getTestRefId(), 'integer') . ' ' .
113 ') ';
114 $this->db->manipulate($query);
115 }
116
117 public function update(): void
118 {
119 $query = 'UPDATE loc_tst_assignments ' .
120 'SET container_id = ' . $this->db->quote($this->getContainerId(), 'integer') . ', ' .
121 'assignment_type = ' . $this->db->quote($this->getAssignmentType(), 'integer') . ', ' .
122 'objective_id = ' . $this->db->quote($this->getObjectiveId(), 'integer') . ', ' .
123 'tst_ref_id = ' . $this->db->quote($this->getTestRefId(), 'integer') . ' ' .
124 'WHERE assignment_id = ' . $this->db->quote($this->getAssignmentId(), 'integer');
125 $this->db->manipulate($query);
126 }
127
128 public function delete(): void
129 {
130 $query = 'DELETE FROM loc_tst_assignments ' .
131 'WHERE assignment_id = ' . $this->db->quote($this->getAssignmentId(), 'integer') . ' ';
132 $this->db->manipulate($query);
133 }
134
135 public function read(): void
136 {
137 if (!$this->getAssignmentId()) {
138 return;
139 }
140
141 $query = 'SELECT * FROM loc_tst_assignments ' .
142 'WHERE assignment_id = ' . $this->db->quote($this->getAssignmentId(), 'integer') . ' ';
143 $res = $this->db->query($query);
144 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
145 $this->setContainerId((int) $row->container_id);
146 $this->setObjectiveId((int) $row->objective_id);
147 $this->setAssignmentType((int) $row->assignment_type);
148 $this->setTestRefId((int) $row->tst_ref_id);
149 }
150 }
151
152 public function cloneSettings(int $a_copy_id, int $a_target_id, int $a_objective_id): void
153 {
154 $options = ilCopyWizardOptions::_getInstance($a_copy_id);
155 $mappings = $options->getMappings();
156
157 if (!array_key_exists($this->getTestRefId(), $mappings)) {
158 return;
159 }
160
161 $copy = new ilLOTestAssignment();
162 $copy->setContainerId($a_target_id);
163 $copy->setAssignmentType($this->getAssignmentType());
164 $copy->setObjectiveId($a_objective_id);
165 $copy->setTestRefId($mappings[$this->getTestRefId()]);
166 $copy->create();
167 }
168}
static _getInstance(int $a_copy_id)
Settings for LO courses.
cloneSettings(int $a_copy_id, int $a_target_id, int $a_objective_id)
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26