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