ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilStudyProgrammeProgress.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2015 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4
5require_once(dirname(__FILE__) . "/../../../../Services/ActiveRecord/class.ActiveRecord.php");
6
21{
22
23 // The progress of a user on a program node can have different status that
24 // determine how the node is taken into account for calculation of the learning
25 // progress.
26
27 // User needs to be successful in the node, but currently isn't.
29 // User has completed the node successfully according to the program nodes
30 // mode.
32 // User was marked as successful in the node without actually having
33 // successfully completed the program node according to his mode.
35 // The user does not need to be successful in this node.
37 // The user does not need to be successful in this node.
38 const STATUS_FAILED = 5;
39
45 );
46
50 public static function returnDbTableName()
51 {
52 return "prg_usr_progress";
53 }
54
73 protected $id;
74
85 protected $assignment_id;
86
97 protected $prg_id;
98
110 protected $usr_id;
123 protected $points;
124
135 protected $points_cur;
136
147 protected $status;
148
162 protected $completion_by;
163
164
175 protected $last_change;
176
188
198 protected $deadline;
199
206 public static function createFor(ilStudyProgramme $a_prg, ilStudyProgrammeAssignment $a_ass)
207 {
208 $prg = new ilStudyProgrammeProgress();
209 $prg->setAssignmentId($a_ass->getId())
210 ->setNodeId($a_prg->getObjId())
211 ->setUserId($a_ass->getUserId())
213 ->setAmountOfPoints($a_prg->getPoints())
214 ->setCurrentAmountOfPoints(0)
215 ->setCompletionBy(null)
216 ->setLastChangeBy(null)
217 ->updateLastChange()
218 ->create();
219 return $prg;
220 }
221
227 public function getAssignmentId()
228 {
230 }
231
232 protected function setAssignmentId($a_id)
233 {
234 $this->assignment_id = $a_id;
235 return $this;
236 }
237
243 public function getNodeId()
244 {
245 return $this->prg_id;
246 }
247
248 protected function setNodeId($a_id)
249 {
250 $this->prg_id = $a_id;
251 return $this;
252 }
253
259 public function getUserId()
260 {
261 return $this->usr_id;
262 }
263
264 protected function setUserId($a_id)
265 {
266 $this->usr_id = $a_id;
267 return $this;
268 }
269
277 public function getAmountOfPoints()
278 {
279 return $this->points;
280 }
281
292 public function setAmountOfPoints($a_points)
293 {
294 if (!is_numeric($a_points) || $a_points < 0) {
295 throw new ilException("ilStudyProgrammeProgress::setAmountOfPoints: "
296 . "Expected a number >= 0 as argument, got '$a_points'");
297 }
298
299 $this->points = (int) $a_points;
300
301 $this->updateLastChange();
302 return $this;
303 }
304
310 public function getCurrentAmountOfPoints()
311 {
312 return $this->points_cur;
313 }
314
323 public function setCurrentAmountOfPoints($a_points)
324 {
325 if (!is_numeric($a_points) || $a_points < 0) {
326 throw new ilException("ilStudyProgrammeProgress::setCurrentAmountOfPoints: "
327 . "Expected a number >= 0 as argument, got '$a_points'.");
328 }
329
330 $this->points_cur = (int) $a_points;
331 $this->updateLastChange();
332 return $this;
333 }
334
340 public function getStatus()
341 {
342 return $this->status;
343 }
344
355 public function setStatus($a_status)
356 {
357 $a_status = (int) $a_status;
358 if (!in_array($a_status, self::$STATUS)) {
359 throw new ilException("ilStudyProgrammeProgress::setStatus: No status: "
360 . "'$a_status'");
361 }
362
363 $this->status = $a_status;
364 $this->updateLastChange();
365 return $this;
366 }
367
374 public function setCompletionBy($a_id)
375 {
376 if ($a_id !== null) {
377 $a_id = (int) $a_id;
378 }
379 $this->completion_by = $a_id;
380 $this->updateLastChange();
381 return $this;
382 }
383
390 public function getCompletionBy()
391 {
393 }
399 public function getLastChangeBy()
400 {
402 }
403
412 public function setLastChangeBy($a_usr_id)
413 {
414 if ($a_usr_id !== null && ilObject::_lookupType($a_usr_id) != "usr") {
415 throw new ilException("ilStudyProgrammeProgress::setLastChangeBy: '$a_usr_id' "
416 . "is no id of a user.");
417 }
418 $this->last_change_by = $a_usr_id;
419 return $this;
420 }
421
427 public function getLastChange()
428 {
429 return new ilDateTime($this->last_change, IL_CAL_DATETIME);
430 }
431
442 public function updateLastChange()
443 {
445 return $this;
446 }
447
457 public function setLastChange(ilDateTime $a_timestamp)
458 {
459 if (ilDateTime::_before($a_timestamp, $this->getLastChange())) {
460 throw new ilException("ilStudyProgrammeProgress::setLastChange: Given "
461 . "timestamp is before current timestamp. That "
462 . "is logically impossible.");
463 }
464
465 $this->last_change = $a_timestamp->get(IL_CAL_DATETIME);
466 return $this;
467 }
468
474 public function getDeadline()
475 {
476 if ($this->deadline !== null) {
477 return new ilDateTime($this->deadline, IL_CAL_DATE);
478 }
479 return $this->deadline;
480 }
481
489 public function setDeadline(ilDateTime $deadline = null)
490 {
491 if ($deadline === null) {
492 $this->deadline = $deadline;
493 } else {
494 $this->deadline = $deadline->get(IL_CAL_DATE);
495 }
496
497 return $this;
498 }
499}
Class ActiveRecord.
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_DATE
const IL_CAL_DATETIME
@classDescription Date and time handling
get($a_format, $a_format_str='', $a_tz='')
get formatted date
static _before(ilDateTime $start, ilDateTime $end, $a_compare_field='', $a_tz='')
compare two dates and check start is before end This method does not consider tz offsets.
Base class for ILIAS Exception handling.
static _lookupType($a_id, $a_reference=false)
lookup object type
Class ilStudyProgrammeAssignment.
getUserId()
Get the id of the user who is assigned.
getId()
Get the id of the assignment.
Class ilStudyProgrammeProgress.
setCurrentAmountOfPoints($a_points)
Set the amount of points the user currently has achieved on this node.
getAssignmentId()
Get the assignment, this progress belongs to.
setLastChangeBy($a_usr_id)
Set the id of the user who did the last change on this progress.
getAmountOfPoints()
Get the amount of points the user needs to achieve on the subnodes of this node.
getStatus()
Get the status the user has on this node.
setAmountOfPoints($a_points)
Get the amount of points the user needs to achieve on the subnodes of this node.
getUserId()
Get the id of the user this progress is for.
getLastChange()
Get the timestamp of the last change on this progress.
updateLastChange()
Update the last change timestamp to the current time.
getCompletionBy()
Get the id of object or user that lead to the successful completion of this node.
getLastChangeBy()
Get the id of the user who did the last change on this assignment.
setStatus($a_status)
Set the status of this node.
getCurrentAmountOfPoints()
Get the amount of points the user currently has achieved on the node.
setLastChange(ilDateTime $a_timestamp)
Set the last change timestamp to the given time.
setDeadline(ilDateTime $deadline=null)
Set the deadline of this progress.
setCompletionBy($a_id)
Set the completion_by field.
static createFor(ilStudyProgramme $a_prg, ilStudyProgrammeAssignment $a_ass)
Create a new progress object for a given program node and assignment.
getNodeId()
Get the id of the program node this progress belongs to.
getDeadline()
Get the deadline of this progress.
Class ilStudyProgramme.
getPoints()
Get the amount of points.
getObjId()
Get the id of the study program.
static now()
Return current timestamp in Y-m-d H:i:s format.