ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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
5require_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.
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}
Class ActiveRecord.
An exception for terminatinating execution or to throw for unit testing.
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.
Class ilObject Basic functions for all objects.
getType()
get object type @access public
getId()
get object id @access public
Class ilStudyProgramme.
updateLastChange()
Update the last change timestamp to the current time.
getPoints()
Get the amount of points.
static createForObject(ilObject $a_object)
Create new study program settings for an object.
getSubtypeId()
Return the meta-data subtype id.
getLPMode()
Get the lp mode.
setLastChange(ilDateTime $a_timestamp)
Set the last change timestamp to the given time.
getStatus()
Get the status.
getLastChange()
Get the timestamp of the last change on this program or a sub program.
getObjId()
Get the id of the study program.
setLPMode($a_mode)
Set the lp mode.
setPoints($a_points)
Set the amount of points.
setStatus($a_status)
Set the status of the node.
setSubtypeId($subtype_id)
Sets the meta-data type id.
static now()
Return current timestamp in Y-m-d H:i:s format.