ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
5 require_once(dirname(__FILE__)."/../../../../Services/ActiveRecord/class.ActiveRecord.php");
6 
21 
22  // The progress of a user on a program node can have different status that
23  // determine how the node is taken into account for calculation of the learning
24  // progress.
25 
26  // User needs to be successful in the node, but currently isn't.
27  const STATUS_IN_PROGRESS = 1;
28  // User has completed the node successfully according to the program nodes
29  // mode.
30  const STATUS_COMPLETED = 2;
31  // User was marked as successful in the node without actually having
32  // successfully completed the program node according to his mode.
33  const STATUS_ACCREDITED = 3;
34  // The user does not need to be successful in this node.
36 
41  );
42 
46  static function returnDbTableName() {
47  return "prg_usr_progress";
48  }
49 
68  protected $id;
69 
80  protected $assignment_id;
81 
92  protected $prg_id;
93 
105  protected $usr_id;
118  protected $points;
119 
130  protected $points_cur;
131 
142  protected $status;
143 
157  protected $completion_by;
158 
159 
170  protected $last_change;
171 
182  protected $last_change_by;
183 
184 
191  static public function createFor( ilStudyProgramme $a_prg
192  , ilStudyProgrammeAssignment $a_ass) {
193  $prg = new ilStudyProgrammeProgress();
194  $prg->setAssignmentId($a_ass->getId())
195  ->setNodeId($a_prg->getObjId())
196  ->setUserId($a_ass->getUserId())
198  ->setAmountOfPoints($a_prg->getPoints())
200  ->setCompletionBy(null)
201  ->setLastChangeBy(null)
202  ->updateLastChange()
203  ->create();
204  return $prg;
205  }
206 
212  public function getAssignmentId() {
213  return $this->assignment_id;
214  }
215 
216  protected function setAssignmentId($a_id) {
217  $this->assignment_id = $a_id;
218  return $this;
219  }
220 
226  public function getNodeId() {
227  return $this->prg_id;
228  }
229 
230  protected function setNodeId($a_id) {
231  $this->prg_id = $a_id;
232  return $this;
233  }
234 
240  public function getUserId() {
241  return $this->usr_id;
242  }
243 
244  protected function setUserId($a_id) {
245  $this->usr_id = $a_id;
246  return $this;
247  }
248 
256  public function getAmountOfPoints() {
257  return $this->points;
258  }
259 
270  public function setAmountOfPoints($a_points) {
271  if (!is_numeric($a_points) || $a_points < 0) {
272  throw new ilException("ilStudyProgrammeProgress::setAmountOfPoints: "
273  ."Expected a number >= 0 as argument, got '$a_points'");
274  }
275 
276  $this->points = (int)$a_points;
277 
278  $this->updateLastChange();
279  return $this;
280  }
281 
287  public function getCurrentAmountOfPoints() {
288  return $this->points_cur;
289  }
290 
299  public function setCurrentAmountOfPoints($a_points) {
300  if (!is_numeric($a_points) || $a_points < 0) {
301  throw new ilException("ilStudyProgrammeProgress::setCurrentAmountOfPoints: "
302  ."Expected a number >= 0 as argument, got '$a_points'.");
303  }
304 
305  $this->points_cur = (int)$a_points;
306  $this->updateLastChange();
307  return $this;
308  }
309 
315  public function getStatus() {
316  return $this->status;
317  }
318 
329  public function setStatus($a_status) {
330  $a_status = (int)$a_status;
331  if (!in_array($a_status, self::$STATUS)) {
332  throw new ilException("ilStudyProgrammeProgress::setStatus: No status: "
333  ."'$a_status'");
334  }
335 
336  $this->status = $a_status;
337  $this->updateLastChange();
338  return $this;
339  }
340 
347  public function setCompletionBy($a_id) {
348  if ($a_id !== null) {
349  $a_id = (int)$a_id;
350  }
351  $this->completion_by = $a_id;
352  $this->updateLastChange();
353  return $this;
354  }
355 
362  public function getCompletionBy() {
363  return $this->completion_by;
364  }
370  public function getLastChangeBy() {
371  return $this->last_change_by;
372  }
373 
382  public function setLastChangeBy($a_usr_id) {
383  if ($a_usr_id !== null && ilObject::_lookupType($a_usr_id) != "usr") {
384  throw new ilException("ilStudyProgrammeProgress::setLastChangeBy: '$a_usr_id' "
385  ."is no id of a user.");
386  }
387  $this->last_change_by = $a_usr_id;
388  return $this;
389  }
390 
396  public function getLastChange() {
397  return new ilDateTime($this->last_change, IL_CAL_DATETIME);
398  }
399 
410  public function updateLastChange() {
412  return $this;
413  }
414 
424  public function setLastChange(ilDateTime $a_timestamp) {
425  if (ilDateTime::_before($a_timestamp, $this->getLastChange())) {
426  throw new ilException("ilStudyProgrammeProgress::setLastChange: Given "
427  ."timestamp is before current timestamp. That "
428  ."is logically impossible.");
429  }
430 
431  $this->last_change = $a_timestamp->get(IL_CAL_DATETIME);
432  return $this;
433  }
434 }
435 
436 ?>
Base class for ILIAS Exception handling.
const IL_CAL_DATETIME
static createFor(ilStudyProgramme $a_prg, ilStudyProgrammeAssignment $a_ass)
Create a new progress object for a given program node and assignment.
getUserId()
Get the id of the user who is assigned.
Class ActiveRecord.
getAssignmentId()
Get the assignment, this progress belongs to.
getLastChangeBy()
Get the id of the user who did the last change on this assignment.
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.
Class ilStudyProgramme.
getCurrentAmountOfPoints()
Get the amount of points the user currently has achieved on the node.
setStatus($a_status)
Set the status of this node.
setLastChangeBy($a_usr_id)
Set the id of the user who did the last change on this progress.
setCompletionBy($a_id)
Set the completion_by field.
getCompletionBy()
Get the id of object or user that lead to the successful completion of this node. ...
static now()
Return current timestamp in Y-m-d H:i:s format.
setCurrentAmountOfPoints($a_points)
Set the amount of points the user currently has achieved on this node.
getObjId()
Get the id of the study program.
getStatus()
Get the status the user has on this node.
updateLastChange()
Update the last change timestamp to the current time.
getAmountOfPoints()
Get the amount of points the user needs to achieve on the subnodes of this node.
getPoints()
Get the amount of points.
Date and time handling
Class ilStudyProgrammeAssignment.
get($a_format, $a_format_str='', $a_tz='')
get formatted date
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
getUserId()
Get the id of the user this progress is for.
Class ilStudyProgrammeProgress.
getLastChange()
Get the timestamp of the last change on this progress.
setAmountOfPoints($a_points)
Get the amount of points the user needs to achieve on the subnodes of this node.
getNodeId()
Get the id of the program node this progress belongs to.
setLastChange(ilDateTime $a_timestamp)
Set the last change timestamp to the given time.
getId()
Get the id of the assignment.