ILIAS  release_8 Revision v8.24
class.ilExAssignmentMemberStatus.php
Go to the documentation of this file.
1<?php
2
26{
27 protected ilDBInterface $db;
28
29 protected int $ass_id = 0;
30 protected int $user_id = 0;
31 protected string $notice = "";
32 protected bool $returned = false;
33 protected bool $solved = false;
34 protected bool $sent = false;
35 protected string $sent_time = "";
36 protected bool $feedback = false;
37 protected string $feedback_time = "";
38 protected string $status = "notgraded";
39 protected string $status_time = "";
40 protected string $mark = "";
41 protected string $comment = "";
42 protected bool $db_exists = false;
43 protected bool $returned_update = false;
44 protected bool $status_update = false;
45
46 public function __construct(int $a_ass_id, int $a_user_id)
47 {
48 global $DIC;
49
50 $this->db = $DIC->database();
51 $this->ass_id = $a_ass_id;
52 $this->user_id = $a_user_id;
53
54 $this->read();
55 }
56
57 public function setNotice(string $a_value): void
58 {
59 $this->notice = $a_value;
60 }
61
62 public function getNotice(): string
63 {
64 return $this->notice;
65 }
66
67 public function setReturned(bool $a_value): void
68 {
69 if ($a_value &&
70 !$this->returned) {
71 $this->returned_update = true;
72 }
73 $this->returned = $a_value;
74 }
75
76 public function getReturned(): bool
77 {
78 return $this->returned;
79 }
80
84 public function setSolved(bool $a_value): void
85 {
86 $this->solved = $a_value;
87 }
88
92 public function getSolved(): bool
93 {
94 return $this->solved;
95 }
96
97 // Y-m-d H:i:s
98 protected function setStatusTime(string $a_value): void
99 {
100 $this->status_time = $a_value;
101 }
102
103 public function getStatusTime(): string
104 {
105 return $this->status_time;
106 }
107
108 public function setSent(bool $a_value): void
109 {
110 if ($a_value && $a_value != $this->sent) {
111 $this->setSentTime(ilUtil::now());
112 }
113 $this->sent = $a_value;
114 }
115
116 public function getSent(): bool
117 {
118 return $this->sent;
119 }
120
121 // Y-m-d H:i:s
122 protected function setSentTime(string $a_value): void
123 {
124 $this->sent_time = $a_value;
125 }
126
127 public function getSentTime(): string
128 {
129 return $this->sent_time;
130 }
131
132 public function setFeedback(bool $a_value): void
133 {
134 if ($a_value != $this->sent) {
136 }
137 $this->feedback = $a_value;
138 }
139
140 public function getFeedback(): bool
141 {
142 return $this->feedback;
143 }
144
145 // Y-m-d H:i:s
146 protected function setFeedbackTime(string $a_value): void
147 {
148 $this->feedback_time = $a_value;
149 }
150
151 public function getFeedbackTime(): string
152 {
154 }
155
156 public function setStatus(string $a_value): void
157 {
158 if ($a_value != $this->status) {
159 $this->setStatusTime(ilUtil::now());
160 $this->status = $a_value;
161 $this->status_update = true;
162 }
163 }
164
165 public function getStatus(): string
166 {
167 return $this->status;
168 }
169
170 public function setMark(string $a_value): void
171 {
172 if ($a_value != $this->mark) {
173 $this->setStatusTime(ilUtil::now());
174 }
175 $this->mark = $a_value;
176 }
177
178 public function getMark(): string
179 {
180 return $this->mark;
181 }
182
183 public function setComment(string $a_value): void
184 {
185 $this->comment = $a_value;
186 }
187
188 public function getComment(): string
189 {
190 return $this->comment;
191 }
192
193 protected function read(): void
194 {
196
197 $set = $ilDB->query("SELECT * FROM exc_mem_ass_status" .
198 " WHERE ass_id = " . $ilDB->quote($this->ass_id, "integer") .
199 " AND usr_id = " . $ilDB->quote($this->user_id, "integer"));
200 if ($ilDB->numRows($set)) {
201 $row = $ilDB->fetchAssoc($set);
202
203 // not using setters to circumvent any datetime-logic/-magic
204 $this->notice = (string) $row["notice"];
205 $this->returned = (bool) $row["returned"];
206 $this->solved = (bool) $row["solved"];
207 $this->status_time = (string) $row["status_time"];
208 $this->sent = (bool) $row["sent"];
209 $this->sent_time = (string) $row["sent_time"];
210 $this->feedback_time = (string) $row["feedback_time"];
211 $this->feedback = (bool) $row["feedback"];
212 $this->status = (string) $row["status"];
213 $this->mark = (string) $row["mark"];
214 $this->comment = (string) $row["u_comment"];
215 $this->db_exists = true;
216 }
217 }
218
219 protected function getFields(): array
220 {
221 return array(
222 "notice" => array("text", $this->getNotice())
223 ,"returned" => array("integer", (int) $this->getReturned())
224 ,"solved" => array("integer", $this->getSolved())
225 ,"status_time" => array("timestamp", $this->getStatusTime())
226 ,"sent" => array("integer", $this->getSent())
227 ,"sent_time" => array("timestamp", $this->getSentTime())
228 ,"feedback_time" => array("timestamp", $this->getFeedbackTime())
229 ,"feedback" => array("integer", (int) $this->getFeedback())
230 ,"status" => array("text", $this->getStatus())
231 ,"mark" => array("text", $this->getMark())
232 ,"u_comment" => array("text", $this->getComment())
233 );
234 }
235
239 public function update(): void
240 {
242
243 $keys = array(
244 "ass_id" => array("integer", $this->ass_id)
245 ,"usr_id" => array("integer", $this->user_id)
246 );
247 $fields = $this->getFields();
248 if (!$this->db_exists) {
249 $fields = array_merge($keys, $fields);
250 $ilDB->insert("exc_mem_ass_status", $fields);
251 } else {
252 $ilDB->update("exc_mem_ass_status", $fields, $keys);
253 }
254
255 if ($this->returned_update) {
256 $this->postUpdateReturned();
257 }
258 if ($this->status_update) {
259 $this->postUpdateStatus();
260 }
261 }
262
266 protected function postUpdateReturned(): void
267 {
269
270 // first upload => notification on submission?
271 $set = $ilDB->query("SELECT fb_cron, fb_date, fb_file" .
272 " FROM exc_assignment" .
273 " WHERE id = " . $ilDB->quote($this->ass_id, "integer"));
274 $row = $ilDB->fetchAssoc($set);
275 if ($row["fb_cron"] &&
276 $row["fb_file"] &&
277 $row["fb_date"] == ilExAssignment::FEEDBACK_DATE_SUBMISSION) { // #16200
278 ilExAssignment::sendFeedbackNotifications($this->ass_id, $this->user_id);
279 }
280 }
281
285 protected function postUpdateStatus(): void
286 {
287 $ass = new ilExAssignment($this->ass_id);
288 $exc = new ilObjExercise($ass->getExerciseId(), false);
289 $exc->updateUserStatus($this->user_id);
290 }
291
295 public function getStatusIcon(): string
296 {
297 switch ($this->getStatus()) {
298 case "passed":
299 return "scorm/passed.svg";
300
301 case "failed":
302 return "scorm/failed.svg";
303
304 default:
305 return "scorm/not_attempted.svg";
306 }
307 }
308
309 // Check whether exercise has been sent to any student per mail.
310 public static function lookupAnyExerciseSent(int $a_ass_id): bool
311 {
312 global $DIC;
313
314 $ilDB = $DIC->database();
315
316 $q = "SELECT count(*) AS cnt" .
317 " FROM exc_mem_ass_status" .
318 " WHERE NOT sent_time IS NULL" .
319 " AND ass_id = " . $ilDB->quote($a_ass_id, "integer");
320 $set = $ilDB->query($q);
321 $rec = $ilDB->fetchAssoc($set);
322 return ($rec["cnt"] > 0);
323 }
324}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(int $a_ass_id, int $a_user_id)
Exercise assignment.
static sendFeedbackNotifications(int $a_ass_id, int $a_user_id=null)
Class ilObjExercise.
static now()
Return current timestamp in Y-m-d H:i:s format.
global $DIC
Definition: feed.php:28
Interface ilDBInterface.
$keys
Definition: metadata.php:204