ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilStudyProgrammeAssignment.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
20{
24 public static function returnDbTableName()
25 {
26 return "prg_usr_assignments";
27 }
28
41 protected $id;
42
53 protected $usr_id;
54
66 protected $root_prg_id;
67
68
78 protected $last_change;
79
90 protected $last_change_by;
91
92
103 public static function createFor(ilStudyProgramme $a_prg, $a_usr_id, $a_assigning_usr_id)
104 {
105 if (ilObject::_lookupType($a_usr_id) != "usr") {
106 throw new ilException("ilStudyProgrammeAssignment::createFor: '$a_usr_id' "
107 . "is no id of a user.");
108 }
109
110 $ass = new ilStudyProgrammeAssignment();
111 $ass->setRootId($a_prg->getObjId())
112 ->setUserId($a_usr_id)
113 ->setLastChangeBy($a_assigning_usr_id)
114 ->updateLastChange()
115 ->create();
116 return $ass;
117 }
118
124 public function getId()
125 {
126 return $this->id;
127 }
128
134 public function getRootId()
135 {
136 return $this->root_prg_id;
137 }
138
139 protected function setRootId($a_id)
140 {
141 $this->root_prg_id = $a_id;
142 return $this;
143 }
144
150 public function getUserId()
151 {
152 return $this->usr_id;
153 }
154
155 protected function setUserId($a_usr_id)
156 {
157 $this->usr_id = $a_usr_id;
158 return $this;
159 }
160
166 public function getLastChangeBy()
167 {
169 }
170
179 public function setLastChangeBy($a_usr_id)
180 {
181 if (ilObject::_lookupType($a_usr_id) != "usr") {
182 throw new ilException("ilStudyProgrammeAssignment::setLastChangeBy: '$a_usr_id' "
183 . "is no id of a user.");
184 }
185 $this->last_change_by = $a_usr_id;
186 return $this;
187 }
188
194 public function getLastChange()
195 {
196 return new ilDateTime($this->last_change, IL_CAL_DATETIME);
197 }
198
204 public function updateLastChange()
205 {
207 return $this;
208 }
209
219 public function setLastChange(ilDateTime $a_timestamp)
220 {
221 if (ilDateTime::_before($a_timestamp, $this->getLastChange())) {
222 throw new ilException("ilStudyProgrammeAssignment::setLastChange: Given "
223 . "timestamp is before current timestamp. That "
224 . "is logically impossible.");
225 }
226
227 $this->last_change = $a_timestamp->get(IL_CAL_DATETIME);
228 return $this;
229 }
230}
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.
static _lookupType($a_id, $a_reference=false)
lookup object type
Class ilStudyProgrammeAssignment.
getUserId()
Get the id of the user who is assigned.
updateLastChange()
Update the last change timestamp to the current time.
getId()
Get the id of the assignment.
setLastChange(ilDateTime $a_timestamp)
Set the last change timestamp to the given time.
setLastChangeBy($a_usr_id)
Set the id of the user who did the last change on this assignment.
static createFor(ilStudyProgramme $a_prg, $a_usr_id, $a_assigning_usr_id)
Create new assignment object for study program and user.
getLastChange()
Get the timestamp of the last change on this program or a sub program.
getRootId()
Get the object id of the program the user was assigned to.
getLastChangeBy()
Get the id of the user who did the last change on this assignment.
Class ilStudyProgramme.
getObjId()
Get the id of the study program.
static now()
Return current timestamp in Y-m-d H:i:s format.