ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  // There are two different modes the programs calculation of the learning
17  // progress can run in. It is also possible, that the mode is not defined
18  // yet.
19  const MODE_UNDEFINED = 0;
20 
21  // User is successful if he collected enough points in the subnodes of
22  // this node.
23  const MODE_POINTS = 1;
24  // User is successful if he has the "completed" learning progress in any
25  // subobject.
26  const MODE_LP_COMPLETED = 2;
27 
31  );
32 
33 
34  // A program tree has a lifecycle during which it has three status.
35 
36  // The program is a draft, that is users won't be assigned to the program
37  // already.
38  const STATUS_DRAFT = 10;
39  // The program is active, that is used can be assigned to it.
40  const STATUS_ACTIVE = 20;
41  // The program is outdated, that is user won't be assigned to it but can
42  // still complete the program.
43  const STATUS_OUTDATED = 30;
44 
48  );
49 
50 
51  // Defaults
52  const DEFAULT_POINTS = 100;
53  const DEFAULT_SUBTYPE = 0; // TODO: What should that be?
54 
58  static function returnDbTableName() {
59  return "prg_settings";
60  }
61 
73  protected $obj_id;
74 
85  protected $last_change;
86 
99  protected $subtype_id;
100 
113  protected $points;
114 
125  protected $lp_mode;
126 
137  protected $status;
138 
139 
148  static public function createForObject(ilObject $a_object) {
149  if ($a_object->getType() != "prg") {
150  throw new ilException("ilStudyProgramme::createSettingsForObject: "
151  ."Object is no prg object.");
152  }
153  if(!$a_object->getId()) {
154  throw new ilException("ilStudyProgramme::createSettingsForObject: "
155  ."Object has no id.");
156  }
157 
158  $prg = new ilStudyProgramme();
159  $prg->subtype_id = self::DEFAULT_SUBTYPE;
160  $prg->setObjId($a_object->getId())
161  ->setStatus(self::STATUS_DRAFT)
162  ->setLPMode(self::MODE_UNDEFINED)
163  ->setPoints(self::DEFAULT_POINTS)
164  ->create();
165  return $prg;
166  }
167 
168 
169  protected function setObjId($a_id) {
170  $this->obj_id = $a_id;
171  return $this;
172  }
173 
179  public function getObjId() {
180  return (int)$this->obj_id;
181  }
182 
188  public function getSubtypeId() {
189  return $this->subtype_id;
190  }
191 
192 
198  public function setSubtypeId($subtype_id) {
199  $this->subtype_id = $subtype_id;
200  }
201 
207  public function getLastChange() {
208  return new ilDateTime($this->last_change, IL_CAL_DATETIME);
209  }
210 
216  public function updateLastChange() {
218  return $this;
219  }
220 
229  public function setLastChange(ilDateTime $a_timestamp) {
230  if (ilDateTime::_before($a_timestamp, $this->getLastChange())) {
231  throw new ilException("ilStudyProgramme::setLastChange: Given "
232  ."timestamp is before current timestamp. That "
233  ."is logically impossible.");
234  }
235 
236  $this->last_change = $a_timestamp->get(IL_CAL_DATETIME);
237  return $this;
238  }
239 
240 
241 
249  public function setPoints($a_points) {
250  $a_points = (int)$a_points;
251  if ($a_points < 0) {
252  throw new ilException("ilStudyProgramme::setPoints: Points cannot "
253  ."be smaller than zero.");
254  }
255 
256  $this->points = $a_points;
257  $this->updateLastChange();
258  return $this;
259  }
260 
266  public function getPoints() {
267  return (int)$this->points;
268  }
269 
278  public function setLPMode($a_mode) {
279  $a_mode = (int)$a_mode;
280  if (!in_array($a_mode, self::$MODES)) {
281  throw new ilException("ilStudyProgramme::setLPMode: No lp mode: "
282  ."'$a_mode'");
283  }
284  $this->lp_mode = $a_mode;
285  $this->updateLastChange();
286  return $this;
287  }
288 
294  public function getLPMode() {
295  return (int)$this->lp_mode;
296  }
297 
307  public function setStatus($a_status) {
308  $a_status = (int)$a_status;
309  if (!in_array($a_status, self::$STATUS)) {
310  throw new ilException("ilStudyProgramme::setStatus: No lp mode: "
311  ."'$a_status'");
312  }
313  $this->status = $a_status;
314  $this->updateLastChange();
315  return $this;
316  }
317 
323  public function getStatus() {
324  return (int)$this->status;
325  }
326 }
327 
328 ?>
setSubtypeId($subtype_id)
Sets the meta-data type id.
setStatus($a_status)
Set the status of the node.
Base class for ILIAS Exception handling.
const IL_CAL_DATETIME
Class ActiveRecord.
Class ilObject Basic functions for all objects.
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.