1 <?php declare(strict_types=1);
10 const TABLE =
'prg_usr_assignments';
34 throw new ilException(
"ilStudyProgrammeAssignment::createFor: '$usr_id' " 35 .
"is no id of a user.");
38 throw new ilException(
"ilStudyProgrammeAssignment::createFor: '$root_prg_id' " 39 .
"is no id of a prg.");
43 self::FIELD_ID => $this->
nextId(),
44 self::FIELD_USR_ID => $usr_id,
45 self::FIELD_ROOT_PRG_ID => $root_prg_id,
46 self::FIELD_LAST_CHANGE_BY => $assigning_usr_id,
48 self::FIELD_RESTART_DATE => null,
59 public function get(
int $id)
74 foreach ($this->
loadByFilterDB([self::FIELD_USR_ID => $usr_id]) as $row) {
87 foreach ($this->
loadByFilterDB([self::FIELD_ROOT_PRG_ID => $prg_id]) as $row) {
101 [self::FIELD_USR_ID => $usr_id
102 , self::FIELD_ROOT_PRG_ID => $prg_id]
137 $res = $this->db->query($q);
138 while ($rec = $this->db->fetchAssoc(
$res)) {
146 $q .=
' AND ' . self::FIELD_RESTART_MAIL .
' IS NULL';
148 $res = $this->db->query($q);
149 while ($rec = $this->db->fetchAssoc(
$res)) {
156 return 'SELECT ' . self::FIELD_ID
157 .
', ' . self::FIELD_USR_ID
158 .
', ' . self::FIELD_ROOT_PRG_ID
159 .
', ' . self::FIELD_LAST_CHANGE
160 .
', ' . self::FIELD_LAST_CHANGE_BY
161 .
', ' . self::FIELD_RESTART_DATE
162 .
', ' . self::FIELD_RESTARTED_ASSIGNMENT_ID . PHP_EOL
163 .
' FROM ' . self::TABLE . PHP_EOL;
169 .
' WHERE ' . self::FIELD_RESTARTED_ASSIGNMENT_ID
170 .
' = ' . $this->db->quote(
174 .
' AND ' . self::FIELD_RESTART_DATE .
' IS NOT NULL' . PHP_EOL
175 .
' AND DATE(' . self::FIELD_RESTART_DATE .
') <= ' 177 (
new DateTime())->format(
202 $date =
new DateTime();
203 $date->sub(
new DateInterval(
'P' . $days_before_end .
'D'));
205 .
' WHERE ' . self::FIELD_RESTARTED_ASSIGNMENT_ID
206 .
' = ' . $this->db->quote(
210 .
' AND ' . self::FIELD_RESTART_DATE .
' IS NOT NULL' . PHP_EOL
211 .
' AND DATE(' . self::FIELD_RESTART_DATE .
') <= ' 218 $res = $this->db->query($q);
219 while ($rec = $this->db->fetchAssoc(
$res)) {
230 self::FIELD_ID => $assignment->
getId(),
231 self::FIELD_USR_ID => $assignment->
getUserId(),
232 self::FIELD_ROOT_PRG_ID => $assignment->
getRootId(),
246 $this->
deleteDB($assignment->getId());
259 self::FIELD_RESTART_MAIL => [
265 $this->db->update(self::TABLE, $values, $where);
275 $q =
'SELECT ' . self::FIELD_ID
276 .
', ' . self::FIELD_USR_ID
277 .
', ' . self::FIELD_ROOT_PRG_ID
278 .
', ' . self::FIELD_LAST_CHANGE
279 .
', ' . self::FIELD_LAST_CHANGE_BY
280 .
', ' . self::FIELD_RESTART_DATE
281 .
', ' . self::FIELD_RESTARTED_ASSIGNMENT_ID
282 .
' FROM ' . self::TABLE
283 .
' WHERE ' . self::FIELD_USR_ID .
' = ' . $usr_id
284 .
' ORDER BY ' . self::FIELD_ROOT_PRG_ID .
', ' . self::FIELD_ID
290 while ($row =
$db->fetchAssoc(
$res)) {
292 $prg = $row[
'root_prg_id'];
294 if ($prg != $row[
'root_prg_id']) {
295 $ret[$prg] = $assignments;
296 $prg = $row[
'root_prg_id'];
301 if (count($assignments) > 0) {
302 $ret[$prg] = $assignments;
314 ->
withRootId((
int) $row[self::FIELD_ROOT_PRG_ID])
315 ->withUserId((
int) $row[self::FIELD_USR_ID])
317 (
int) $row[self::FIELD_LAST_CHANGE_BY],
318 DateTimeImmutable::createFromFormat(
320 $row[self::FIELD_LAST_CHANGE]
324 (
int) $row[self::FIELD_RESTARTED_ASSIGNMENT_ID],
325 $row[self::FIELD_RESTART_DATE] ?
333 $q =
'SELECT ' . self::FIELD_ID
334 .
' ,' . self::FIELD_USR_ID
335 .
' ,' . self::FIELD_ROOT_PRG_ID
336 .
' ,' . self::FIELD_LAST_CHANGE
337 .
' ,' . self::FIELD_LAST_CHANGE_BY
338 .
' ,' . self::FIELD_RESTART_DATE
339 .
' ,' . self::FIELD_RESTARTED_ASSIGNMENT_ID
340 .
' FROM ' . self::TABLE
342 foreach ($filter as $field => $value) {
343 $q .=
' AND ' . $field .
' = ' . $this->db->quote($value,
'text');
345 $res = $this->db->query($q);
346 while ($rec = $this->db->fetchAssoc(
$res)) {
356 self::FIELD_ID => [
'integer', $row[self::FIELD_ID]]
357 , self::FIELD_USR_ID => [
'integer', $row[self::FIELD_USR_ID]]
358 , self::FIELD_ROOT_PRG_ID => [
'integer', $row[self::FIELD_ROOT_PRG_ID]]
359 , self::FIELD_LAST_CHANGE => [
'text', $row[self::FIELD_LAST_CHANGE]]
360 , self::FIELD_LAST_CHANGE_BY => [
'integer', $row[self::FIELD_LAST_CHANGE_BY]]
361 , self::FIELD_RESTART_DATE => [
'timestamp', $row[self::FIELD_RESTART_DATE]]
362 , self::FIELD_RESTARTED_ASSIGNMENT_ID => [
'integer', $row[self::FIELD_RESTARTED_ASSIGNMENT_ID]]
369 $q =
'UPDATE ' . self::TABLE
371 .
' ' . self::FIELD_USR_ID .
' = ' . $this->db->quote($values[self::FIELD_USR_ID],
'integer')
372 .
' ,' . self::FIELD_ROOT_PRG_ID .
' = ' . $this->db->quote($values[self::FIELD_ROOT_PRG_ID],
'integer')
373 .
' ,' . self::FIELD_LAST_CHANGE .
' = ' . $this->db->quote($values[self::FIELD_LAST_CHANGE],
'text')
374 .
' ,' . self::FIELD_LAST_CHANGE_BY .
' = ' . $this->db->quote($values[self::FIELD_LAST_CHANGE_BY],
'integer')
375 .
' ,' . self::FIELD_RESTART_DATE .
' = ' . $this->db->quote($values[self::FIELD_RESTART_DATE],
'timestamp')
376 .
' ,' . self::FIELD_RESTARTED_ASSIGNMENT_ID .
' = ' . $this->db->quote($values[self::FIELD_RESTARTED_ASSIGNMENT_ID],
'integer')
377 .
' WHERE ' . self::FIELD_ID .
' = ' . $this->db->quote($values[self::FIELD_ID],
'integer');
378 $this->db->manipulate($q);
383 $this->db->manipulate(
'DELETE FROM ' . self::TABLE .
' WHERE ' . self::FIELD_ID .
' = ' . $this->db->quote($id,
'integer'));
388 return $this->db->nextId(self::TABLE);
394 $query =
'DELETE FROM ' . self::TABLE . PHP_EOL
395 .
'WHERE ' . self::FIELD_ROOT_PRG_ID .
'=' . $this->db->quote($prg_obj_id,
'integer');
396 $this->db->manipulate(
$query);
401 return [self::TABLE, self::FIELD_ID];
413 return $this->
get($id);
424 $tree = $DIC[
'tree'];
431 foreach ($assignments as $ass) {
433 if ($tree->isInTree($value)) {
update(ilStudyProgrammeAssignment $assignment)
Update settings belonging to a SP-Object.Will throw if the record does not exist yet.
getDueToRestart()
Get all assignments due to restart and not restrted yet.ilStudyProgrammeAssignment[] ...
deleteAllAssignmentsForProgrammeId(int $prg_obj_id)
loadDueToRestartAndMail()
const FIELD_RESTARTED_ASSIGNMENT_ID
loadDueToManuelRestart(int $days_before_end)
getByPrgId(int $prg_id)
Get all assignments to a prg.
getRestartedAssignmentId()
getInstanceByModel(\ilStudyProgrammeAssignment $assignment)
getByUsrId(int $usr_id)
Get all assignments of a user.
createFor(int $root_prg_id, int $usr_id, int $assigning_usr_id)
Create a record corresponding to a SP-Object and return represending settings.Will throw if a record ...
getDashboardInstancesforUser(int $usr_id)
getInstanceById(int $id)
Backport ilStudyProgrammeUserAssignmentDB
static now()
Return current timestamp in Y-m-d H:i:s format.
static _getAllReferences($a_id)
get all reference ids of object
reminderSendFor(int $assignment_id)
const NO_RESTARTED_ASSIGNMENT
foreach($_POST as $key=> $value) $res
updatedRowDB(array $values)
__construct(ilDBInterface $db)
Represents one assignment of the user to a program tree.
getInstancesOfUser(int $user_id)
static _lookupType($a_id, $a_reference=false)
lookup object type
assignmentByRow(array $row)
getDueToManuelRestart(int $days_before_end)
Get all assignments due to restart and not restrted yet.
getTableAndFieldOfAssignmentIds()
loadByFilterDB(array $filter)
getByUsrIdAndPrgId(int $usr_id, int $prg_id)
const FIELD_LAST_CHANGE_BY
withRootId(int $root_prg_id)