ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilLinkResourceList.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2020 ILIAS open source, Extended GPL, see docs/LICENSE */
4
11{
15 protected $webr_id;
16
20 protected $title;
21
25 protected $description;
26
30 protected $c_date;
31
35 protected $m_date;
36
41 public function __construct(int $webr_id)
42 {
43 global $DIC;
44
45 $this->db = $DIC->database();
46 $this->webr_id = $webr_id;
47
48 $this->read();
49 }
50
54 public function setListResourceId(int $a_id)
55 {
56 $this->webr_id = $a_id;
57 }
58
62 public function getListResourceId()
63 {
64 return $this->webr_id;
65 }
66
70 public function setTitle(string $a_title)
71 {
72 $this->title = $a_title;
73 }
74
78 public function getTitle()
79 {
80 return $this->title;
81 }
82
86 public function setDescription(string $a_description)
87 {
88 $this->description = $a_description;
89 }
90
94 public function getDescription()
95 {
96 return $this->description;
97 }
98
102 protected function setCreateDate(int $a_date)
103 {
104 $this->c_date = $a_date;
105 }
106
110 public function getCreateDate()
111 {
112 return $this->c_date;
113 }
114
118 protected function setLastUpdateDate(int $a_date)
119 {
120 $this->m_date = $a_date;
121 }
122
126 public function getLastUpdateDate()
127 {
128 return $this->m_date;
129 }
130
131
135 public function read()
136 {
137 $ilDB = $this->db;
138
139 $query = "SELECT * FROM webr_lists " .
140 "WHERE webr_id = " . $ilDB->quote($this->getListResourceId(), 'integer');
141
142 $res = $ilDB->query($query);
143 if ($ilDB->numRows($res)) {
144 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
145 $this->setTitle((string) $row->title);
146 $this->setDescription((string) $row->description);
147 $this->setCreateDate((int) $row->create_date);
148 $this->setLastUpdateDate((int) $row->last_update);
149 }
150 return true;
151 }
152 return false;
153 }
154
159 public function delete(bool $a_update_history = true)
160 {
161 $ilDB = $this->db;
162
163 $query = "DELETE FROM webr_lists " .
164 "WHERE webr_id = " . $ilDB->quote($this->getListResourceId(), 'integer');
165 $res = $ilDB->manipulate($query);
166
167 if ($a_update_history) {
169 $this->getListResourceId(),
170 "delete",
171 $this->getTitle()
172 );
173 }
174
175 return true;
176 }
177
182 public function update($a_update_history = true)
183 {
184 $ilDB = $this->db;
185
186 if (!$this->getListResourceId()) {
187 return false;
188 }
189
190 $this->setLastUpdateDate(time());
191 $query = "UPDATE webr_lists " .
192 "SET title = " . $ilDB->quote($this->getTitle(), 'text') . ", " .
193 "description = " . $ilDB->quote($this->getDescription(), 'text') . ", " .
194 "last_update = " . $ilDB->quote($this->getLastUpdateDate(), 'integer') . " " .
195 "WHERE webr_id = " . $ilDB->quote($this->getListResourceId(), 'integer');
196 $res = $ilDB->manipulate($query);
197
198 if ($a_update_history) {
200 $this->getListResourceId(),
201 "update",
202 $this->getTitle()
203 );
204 }
205
206 return true;
207 }
208
213 public function add($a_update_history = true)
214 {
215 $ilDB = $this->db;
216
217 $now = time();
218 $this->setCreateDate($now);
219 $this->setLastUpdateDate($now);
220
221 $query = "INSERT INTO webr_lists (title,description,last_update,create_date,webr_id) " .
222 "VALUES( " .
223 $ilDB->quote($this->getTitle(), 'text') . ", " .
224 $ilDB->quote($this->getDescription(), 'text') . ", " .
225 $ilDB->quote($this->getLastUpdateDate(), 'integer') . ", " .
226 $ilDB->quote($this->getCreateDate(), 'integer') . ", " .
227 $ilDB->quote($this->getListResourceId(), 'integer') . " " .
228 ")";
229 $res = $ilDB->manipulate($query);
230
231 if ($a_update_history) {
233 $this->getListResourceId(),
234 "add",
235 $this->getTitle()
236 );
237 }
238
239 return true;
240 }
241
246 public static function lookupList(int $a_webr_id)
247 {
248 global $DIC;
249
250 $ilDB = $DIC->database();
251
252 $query = "SELECT * FROM webr_lists " .
253 "WHERE webr_id = " . $ilDB->quote($a_webr_id, 'integer');
254
255 $res = $ilDB->query($query);
256 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
257 $list['title'] = $row->title;
258 $list['description'] = $row->description;
259 $list['create_date'] = $row->create_date;
260 $list['last_update'] = $row->last_update;
261 $list['webr_id'] = $row->webr_id;
262 }
263 return $list ? $list : array();
264 }
265
269 public static function lookupAllLists()
270 {
271 global $DIC;
272
273 $ilDB = $DIC->database();
274
275 $query = "SELECT * FROM webr_lists";
276
277 $res = $ilDB->query($query);
278 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
279 $lists[$row->webr_id]['title'] = $row->title;
280 $lists[$row->webr_id]['description'] = $row->description;
281 $lists[$row->webr_id]['create_date'] = $row->create_date;
282 $lists[$row->webr_id]['last_update'] = $row->last_update;
283 $lists[$row->webr_id]['webr_id'] = $row->webr_id;
284 }
285 return $lists ? $lists : array();
286 }
287
292 public static function checkListStatus(int $a_webr_id)
293 {
294 global $DIC;
295
296 $ilDB = $DIC->database();
297
298 $query = "SELECT * FROM webr_lists " .
299 "WHERE webr_id = " . $ilDB->quote($a_webr_id, 'integer');
300
301 $res = $ilDB->query($query);
302 if ($ilDB->numRows($res)) {
303 return true;
304 }
305 return false;
306 }
307}
An exception for terminatinating execution or to throw for unit testing.
static _createEntry( $a_obj_id, $a_action, $a_info_params="", $a_obj_type="", $a_user_comment="", $a_update_last=false)
Creates a new history entry for an object.
Class ilLinkResourceList.
update($a_update_history=true)
static lookupList(int $a_webr_id)
static checkListStatus(int $a_webr_id)
Check if a weblink list was already created or transformed from a single weblink.
__construct(int $webr_id)
ilLinkResourceList constructor.
setDescription(string $a_description)
add($a_update_history=true)
global $DIC
Definition: goto.php:24
$query
foreach($_POST as $key=> $value) $res
global $ilDB