ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilTimingUser.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=0);
27{
28 private int $ref_id = 0;
29 private int $usr_id = 0;
32
33 private bool $is_scheduled = false;
34
35 protected ilDBInterface $db;
36
37 public function __construct(int $a_ref_id, int $a_usr_id)
38 {
39 global $DIC;
40
41 $this->db = $DIC->database();
42
43 $this->ref_id = $a_ref_id;
44 $this->usr_id = $a_usr_id;
45
46 $this->start = new ilDateTime(0, IL_CAL_UNIX);
47 $this->end = new ilDateTime(0, IL_CAL_UNIX);
48 $this->read();
49 }
50
51 public function getUserId(): int
52 {
53 return $this->usr_id;
54 }
55
56 public function getRefId(): int
57 {
58 return $this->ref_id;
59 }
60
61 public function isScheduled(): bool
62 {
64 }
65
69 public function getStart(): ilDateTime
70 {
71 return $this->start;
72 }
73
77 public function getEnd(): ilDateTime
78 {
79 return $this->end;
80 }
81
82 public function create(): void
83 {
84 if ($this->isScheduled()) {
85 $this->update();
86 return;
87 }
88
89 $query = 'INSERT INTO crs_timings_user (ref_id, usr_id, sstart, ssend ) VALUES ( ' .
90 $this->db->quote($this->getRefId(), 'integer') . ', ' .
91 $this->db->quote($this->getUserId(), 'integer') . ', ' .
92 $this->db->quote($this->getStart()->get(IL_CAL_UNIX), 'integer') . ', ' .
93 $this->db->quote($this->getEnd()->get(IL_CAL_UNIX), 'integer') . ' ' .
94 ')';
95 $this->db->manipulate($query);
96 $this->is_scheduled = true;
97 }
98
99 public function update(): void
100 {
101 if (!$this->isScheduled()) {
102 $this->create();
103 return;
104 }
105
106 $query = 'UPDATE crs_timings_user ' .
107 'SET sstart = ' . $this->db->quote($this->getStart()->get(IL_CAL_UNIX), 'integer') . ', ' .
108 'ssend = ' . $this->db->quote($this->getEnd()->get(IL_CAL_UNIX), 'integer') . ' ' .
109 'WHERE ref_id = ' . $this->db->quote($this->getRefId(), 'integer') . ' ' .
110 'AND usr_id = ' . $this->db->quote($this->getUserId(), 'integer');
111 $this->db->manipulate($query);
112 }
113
114 public function delete(): void
115 {
116 $query = 'DELETE FROM crs_timings_user ' . ' ' .
117 'WHERE ref_id = ' . $this->db->quote($this->getRefId(), 'integer') . ' ' .
118 'AND usr_id = ' . $this->db->quote($this->getUserId(), 'integer');
119 $this->db->manipulate($query);
120 $this->is_scheduled = false;
121 }
122
123 public function read(): void
124 {
125 $query = 'SELECT * FROM crs_timings_user ' .
126 'WHERE ref_id = ' . $this->db->quote($this->getRefId(), 'integer') . ' ' .
127 'AND usr_id = ' . $this->db->quote($this->getUserId(), 'integer');
128 $res = $this->db->query($query);
129 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
130 $this->is_scheduled = true;
131 $this->start = new ilDateTime((int) $row->sstart, IL_CAL_UNIX);
132 $this->end = new ilDateTime((int) $row->ssend, IL_CAL_UNIX);
133 }
134 }
135}
const IL_CAL_UNIX
@classDescription Date and time handling
TableGUI class for timings administration.
getStart()
Use to set start date.
ilDBInterface $db
getEnd()
Use to set date.
__construct(int $a_ref_id, int $a_usr_id)
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26