ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilTimingPlaned.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=0);
25{
26 private int $item_id = 0;
27 private int $user_id = 0;
28 private int $start = 0;
29 private int $end = 0;
30
31 protected ilDBInterface $db;
32
33 public function __construct(int $item_id, int $a_usr_id)
34 {
35 global $DIC;
36
37 $this->db = $DIC->database();
38
39 $this->item_id = $item_id;
40 $this->user_id = $a_usr_id;
41 $this->__read();
42 }
43
44 public function getUserId(): int
45 {
46 return $this->user_id;
47 }
48
49 public function getItemId(): int
50 {
51 return $this->item_id;
52 }
53
54 public function getPlanedStartingTime(): int
55 {
56 return $this->start;
57 }
58
59 public function setPlanedStartingTime(int $a_time): void
60 {
61 $this->start = $a_time;
62 }
63
64 public function getPlanedEndingTime(): int
65 {
66 return $this->end;
67 }
68
69 public function setPlanedEndingTime(int $a_end): void
70 {
71 $this->end = $a_end;
72 }
73
74 public function validate(): bool
75 {
76 $item = ilObjectActivation::getItem($this->getItemId());
77 return true;
78 }
79
80 public function update(): bool
81 {
83 $this->create();
84 return true;
85 }
86
87 public function create(): void
88 {
89 $query = "INSERT INTO crs_timings_planed (item_id,usr_id,planed_start,planed_end) " .
90 "VALUES( " .
91 $this->db->quote($this->getItemId(), 'integer') . ", " .
92 $this->db->quote($this->getUserId(), 'integer') . ", " .
93 $this->db->quote($this->getPlanedStartingTime(), 'integer') . ", " .
94 $this->db->quote($this->getPlanedEndingTime(), 'integer') . " " .
95 ")";
96 $res = $this->db->manipulate($query);
97 }
98
99 public function delete(): void
100 {
101 ilTimingPlaned::_delete($this->getItemId(), $this->getUserId());
102 }
103
104 public static function _delete(int $a_item_id, int $a_usr_id): void
105 {
106 global $DIC;
107
108 $ilDB = $DIC->database();
109 $query = "DELETE FROM crs_timings_planed " .
110 "WHERE item_id = " . $ilDB->quote($a_item_id, 'integer') . " " .
111 "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " ";
112 $res = $ilDB->manipulate($query);
113 }
114
115 public static function _getPlanedTimings(int $a_usr_id, int $a_item_id): array
116 {
117 global $DIC;
118
119 $ilDB = $DIC->database();
120
121 $query = "SELECT * FROM crs_timings_planed " .
122 "WHERE item_id = " . $ilDB->quote($a_item_id, 'integer') . " " .
123 "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " ";
124 $res = $ilDB->query($query);
125 $data = [];
126 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
127 $data['planed_start'] = (int) $row->planed_start;
128 $data['planed_end'] = (int) $row->planed_end;
129 }
130 return $data;
131 }
132
133 public static function _getPlanedTimingsByItem($a_item_id): array
134 {
135 global $DIC;
136
137 $ilDB = $DIC->database();
138 $query = "SELECT * FROM crs_timings_planed " .
139 "WHERE item_id = " . $ilDB->quote($a_item_id, 'integer') . " ";
140 $res = $ilDB->query($query);
141 $data = [];
142 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
143 $data[(int) $row->usr_id]['start'] = (int) $row->planed_start;
144 $data[(int) $row->usr_id]['end'] = (int) $row->planed_end;
145 }
146 return $data;
147 }
148
149 public static function _deleteByItem(int $a_item_id): void
150 {
151 global $DIC;
152
153 $ilDB = $DIC->database();
154 $query = "DELETE FROM crs_timings_planed " .
155 "WHERE item_id = " . $ilDB->quote($a_item_id, 'integer') . " ";
156 $res = $ilDB->manipulate($query);
157 }
158
159 public static function _deleteByUser(int $a_usr_id): void
160 {
161 global $DIC;
162
163 $ilDB = $DIC->database();
164 $query = "DELETE FROM crs_timings_planed " .
165 "WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " ";
166 $res = $ilDB->manipulate($query);
167 }
168
169 public function __read(): void
170 {
171 $query = "SELECT * FROM crs_timings_planed " .
172 "WHERE item_id = " . $this->db->quote($this->getItemId(), 'integer') . " " .
173 "AND usr_id = " . $this->db->quote($this->getUserId(), 'integer') . " ";
174 $res = $this->db->query($query);
175 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
176 $this->setPlanedStartingTime((int) $row->planed_start);
177 $this->setPlanedEndingTime((int) $row->planed_end);
178 }
179 }
180}
static getItem(int $ref_id)
class ilTimingPlaned
static _getPlanedTimingsByItem($a_item_id)
static _delete(int $a_item_id, int $a_usr_id)
static _deleteByItem(int $a_item_id)
setPlanedEndingTime(int $a_end)
setPlanedStartingTime(int $a_time)
__construct(int $item_id, int $a_usr_id)
static _getPlanedTimings(int $a_usr_id, int $a_item_id)
static _deleteByUser(int $a_usr_id)
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26