ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilStudyProgramme.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 
15 {
16 
17  // There are two different modes the programs calculation of the learning
18  // progress can run in. It is also possible, that the mode is not defined
19  // yet.
20  const MODE_UNDEFINED = 0;
21 
22  // User is successful if he collected enough points in the subnodes of
23  // this node.
24  const MODE_POINTS = 1;
25  // User is successful if he has the "completed" learning progress in any
26  // subobject.
27  const MODE_LP_COMPLETED = 2;
28 
32  );
33 
34 
35  // A program tree has a lifecycle during which it has three status.
36 
37  // The program is a draft, that is users won't be assigned to the program
38  // already.
39  const STATUS_DRAFT = 10;
40  // The program is active, that is used can be assigned to it.
41  const STATUS_ACTIVE = 20;
42  // The program is outdated, that is user won't be assigned to it but can
43  // still complete the program.
44  const STATUS_OUTDATED = 30;
45 
49  );
50 
51 
52  // Defaults
53  const DEFAULT_POINTS = 100;
54  const DEFAULT_SUBTYPE = 0; // TODO: What should that be?
55 
59  public static function returnDbTableName()
60  {
61  return "prg_settings";
62  }
63 
75  protected $obj_id;
76 
87  protected $last_change;
88 
101  protected $subtype_id;
102 
115  protected $points;
116 
127  protected $lp_mode;
128 
139  protected $status;
140 
141 
150  public static function createForObject(ilObject $a_object)
151  {
152  if ($a_object->getType() != "prg") {
153  throw new ilException("ilStudyProgramme::createSettingsForObject: "
154  . "Object is no prg object.");
155  }
156  if (!$a_object->getId()) {
157  throw new ilException("ilStudyProgramme::createSettingsForObject: "
158  . "Object has no id.");
159  }
160 
161  $prg = new ilStudyProgramme();
162  $prg->subtype_id = self::DEFAULT_SUBTYPE;
163  $prg->setObjId($a_object->getId())
164  ->setStatus(self::STATUS_DRAFT)
165  ->setLPMode(self::MODE_UNDEFINED)
166  ->setPoints(self::DEFAULT_POINTS)
167  ->create();
168  return $prg;
169  }
170 
171 
172  protected function setObjId($a_id)
173  {
174  $this->obj_id = $a_id;
175  return $this;
176  }
177 
183  public function getObjId()
184  {
185  return (int) $this->obj_id;
186  }
187 
193  public function getSubtypeId()
194  {
195  return $this->subtype_id;
196  }
197 
198 
204  public function setSubtypeId($subtype_id)
205  {
206  $this->subtype_id = $subtype_id;
207  }
208 
214  public function getLastChange()
215  {
216  return new ilDateTime($this->last_change, IL_CAL_DATETIME);
217  }
218 
224  public function updateLastChange()
225  {
227  return $this;
228  }
229 
238  public function setLastChange(ilDateTime $a_timestamp)
239  {
240  if (ilDateTime::_before($a_timestamp, $this->getLastChange())) {
241  throw new ilException("ilStudyProgramme::setLastChange: Given "
242  . "timestamp is before current timestamp. That "
243  . "is logically impossible.");
244  }
245 
246  $this->last_change = $a_timestamp->get(IL_CAL_DATETIME);
247  return $this;
248  }
249 
250 
251 
259  public function setPoints($a_points)
260  {
261  $a_points = (int) $a_points;
262  if ($a_points < 0) {
263  throw new ilException("ilStudyProgramme::setPoints: Points cannot "
264  . "be smaller than zero.");
265  }
266 
267  $this->points = $a_points;
268  $this->updateLastChange();
269  return $this;
270  }
271 
277  public function getPoints()
278  {
279  return (int) $this->points;
280  }
281 
290  public function setLPMode($a_mode)
291  {
292  $a_mode = (int) $a_mode;
293  if (!in_array($a_mode, self::$MODES)) {
294  throw new ilException("ilStudyProgramme::setLPMode: No lp mode: "
295  . "'$a_mode'");
296  }
297  $this->lp_mode = $a_mode;
298  $this->updateLastChange();
299  return $this;
300  }
301 
307  public function getLPMode()
308  {
309  return (int) $this->lp_mode;
310  }
311 
321  public function setStatus($a_status)
322  {
323  $a_status = (int) $a_status;
324  if (!in_array($a_status, self::$STATUS)) {
325  throw new ilException("ilStudyProgramme::setStatus: No lp mode: "
326  . "'$a_status'");
327  }
328  $this->status = $a_status;
329  $this->updateLastChange();
330  return $this;
331  }
332 
338  public function getStatus()
339  {
340  return (int) $this->status;
341  }
342 }
setSubtypeId($subtype_id)
Sets the meta-data type id.
setStatus($a_status)
Set the status of the node.
const IL_CAL_DATETIME
Class ActiveRecord.
getLPMode()
Get the lp mode.
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.
updateLastChange()
Update the last change timestamp to the current time.
static now()
Return current timestamp in Y-m-d H:i:s format.
getObjId()
Get the id of the study program.
getId()
get object id public
getStatus()
Get the status.
getPoints()
Get the amount of points.
Date and time handling
get($a_format, $a_format_str='', $a_tz='')
get formatted date
getType()
get object type public
Create styles array
The data for the language used.
static createForObject(ilObject $a_object)
Create new study program settings for an object.
setLastChange(ilDateTime $a_timestamp)
Set the last change timestamp to the given time.
getSubtypeId()
Return the meta-data subtype id.
getLastChange()
Get the timestamp of the last change on this program or a sub program.
setLPMode($a_mode)
Set the lp mode.
setPoints($a_points)
Set the amount of points.