ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilLinkResourceItems.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 include_once "./classes/class.ilObjectGUI.php";
25 
35 {
40  function ilLinkResourceItems($webr_id)
41  {
42  global $ilDB;
43 
44  $this->webr_ref_id = 0;
45  $this->webr_id = $webr_id;
46 
47  $this->db =& $ilDB;
48  }
49 
50  // SET GET
51  function setLinkResourceRefId($a_ref_id)
52  {
53  $this->webr_ref_id = $a_ref_id;
54  }
56  {
57  return $this->webr_ref_id;
58  }
59  function setLinkResourceId($a_id)
60  {
61  $this->webr_id = $a_id;
62  }
63  function getLinkResourceId()
64  {
65  return $this->webr_id;
66  }
67  function setLinkId($a_id)
68  {
69  $this->id = $a_id;
70  }
71  function getLinkId()
72  {
73  return $this->id;
74  }
75  function setTitle($a_title)
76  {
77  $this->title = $a_title;
78  }
79  function getTitle()
80  {
81  return $this->title;
82  }
83  function setDescription($a_description)
84  {
85  $this->description = $a_description;
86  }
87  function getDescription()
88  {
89  return $this->description;
90  }
91  function setTarget($a_target)
92  {
93  $this->target = $a_target;
94  }
95  function getTarget()
96  {
97  return $this->target;
98  }
99  function setActiveStatus($a_status)
100  {
101  $this->status = (int) $a_status;
102  }
103  function getActiveStatus()
104  {
105  return (bool) $this->status;
106  }
107  function setDisableCheckStatus($a_status)
108  {
109  $this->check = (int) $a_status;
110  }
112  {
113  return (bool) $this->check;
114  }
115  // PRIVATE
116  function __setCreateDate($a_date)
117  {
118  $this->c_date = $a_date;
119  }
120  function getCreateDate()
121  {
122  return $this->c_date;
123  }
124  // PRIVATE
125  function __setLastUpdateDate($a_date)
126  {
127  $this->m_date = $a_date;
128  }
129  function getLastUpdateDate()
130  {
131  return $this->m_date;
132  }
133  function setLastCheckDate($a_date)
134  {
135  $this->last_check = $a_date;
136  }
137  function getLastCheckDate()
138  {
139  return $this->last_check;
140  }
141  function setValidStatus($a_status)
142  {
143  $this->valid = (int) $a_status;
144  }
145  function getValidStatus()
146  {
147  return (bool) $this->valid;
148  }
149 
157  public function cloneItems($a_new_id)
158  {
159  include_once 'Modules/WebResource/classes/class.ilParameterAppender.php';
160  $appender = new ilParameterAppender($this->getLinkResourceId());
161 
162  foreach($this->getAllItems() as $item)
163  {
164  $new_item = new ilLinkResourceItems($a_new_id);
165  $new_item->setTitle($item['title']);
166  $new_item->setDescription($item['description']);
167  $new_item->setTarget($item['target']);
168  $new_item->setActiveStatus($item['active']);
169  $new_item->setDisableCheckStatus($item['disable_check']);
170  $new_item->setLastCheckDate($item['last_check']);
171  $new_item->setValidStatus($item['valid']);
172  $new_item->add(true);
173 
174  // Add parameters
175  foreach(ilParameterAppender::_getParams($item['link_id']) as $param_id => $data)
176  {
177  $appender->setName($data['name']);
178  $appender->setValue($data['value']);
179  $appender->add($new_item->getLinkId());
180  }
181 
182  unset($new_item);
183  }
184  return true;
185  }
186 
187  function delete($a_item_id,$a_update_history = true)
188  {
189  global $ilDB;
190 
191  $query = "DELETE FROM webr_items ".
192  "WHERE webr_id = ".$ilDB->quote($this->getLinkResourceId())." ".
193  "AND link_id = ".$ilDB->quote($a_item_id);
194 
195  $this->db->query($query);
196 
197  if($a_update_history)
198  {
199  include_once("classes/class.ilHistory.php");
200  ilHistory::_createEntry($this->getLinkResourceId(), "delete",
201  $this->getTitle());
202  }
203 
204  return true;
205  }
206 
207  function update($a_update_history = true)
208  {
209  global $ilDB;
210 
211  if(!$this->getLinkId())
212  {
213  return false;
214  }
215 
216  $this->__setLastUpdateDate(time());
217  $query = "UPDATE webr_items ".
218  "SET title = ".$ilDB->quote($this->getTitle()).", ".
219  "description = ".$ilDB->quote($this->getDescription()).", ".
220  "target = ".$ilDB->quote($this->getTarget()).", ".
221  "active = ".$ilDB->quote($this->getActiveStatus()).", ".
222  "valid = ".$ilDB->quote($this->getValidStatus()).", ".
223  "disable_check = ".$ilDB->quote($this->getDisableCheckStatus()).", ".
224  "last_update = ".$ilDB->quote($this->getLastUpdateDate()).", ".
225  "last_check = ".$ilDB->quote($this->getLastCheckDate())." ".
226  "WHERE link_id = ".$ilDB->quote($this->getLinkId())." ".
227  "AND webr_id = ".$ilDB->quote($this->getLinkResourceId());
228 
229  $this->db->query($query);
230 
231  if($a_update_history)
232  {
233  include_once("classes/class.ilHistory.php");
234  ilHistory::_createEntry($this->getLinkResourceId(), "update",
235  $this->getTitle());
236  }
237 
238  return true;
239  }
240 
241  function updateValid($a_status)
242  {
243  global $ilDB;
244 
245  $query = "UPDATE webr_items ".
246  "SET valid = ".$ilDB->quote($a_status)." ".
247  "WHERE link_id = ".$ilDB->quote($this->getLinkId());
248 
249  $this->db->query($query);
250 
251  return true;
252  }
253 
254  function updateActive($a_status)
255  {
256  global $ilDB;
257 
258  $query = "UPDATE webr_items ".
259  "SET active = ".$ilDB->quote($a_status)." ".
260  "WHERE link_id = ".$ilDB->quote($this->getLinkId());
261 
262  $this->db->query($query);
263 
264  return true;
265  }
266  function updateDisableCheck($a_status)
267  {
268  global $ilDB;
269 
270  $query = "UPDATE webr_items ".
271  "SET disable_check = ".$ilDB->quote($a_status)." ".
272  "WHERE link_id = ".$ilDB->quote($this->getLinkId());
273 
274  $this->db->query($query);
275 
276  return true;
277  }
278 
279  function updateLastCheck($a_offset = 0)
280  {
281  global $ilDB;
282 
283  if($a_offset)
284  {
285  $period = $a_offset ? $a_offset : 0;
286  $time = time() - $period;
287 
288 
289  $query = "UPDATE webr_items ".
290  "SET last_check = ".$ilDB->quote(time())." ".
291  "WHERE webr_id = ".$ilDB->quote($this->getLinkResourceId())." ".
292  "AND disable_check = '0' ".
293  "AND last_check < ".$ilDB->quote($time);
294 
295  $this->db->query($query);
296  }
297  else
298  {
299  $query = "UPDATE webr_items ".
300  "SET last_check = ".$ilDB->quote(time())." ".
301  "WHERE webr_id = ".$ilDB->quote($this->getLinkResourceId())." ".
302  "AND disable_check = '0' ";
303 
304  $this->db->query($query);
305  }
306  return true;
307  }
308 
309  function updateValidByCheck($a_offset = 0)
310  {
311  global $ilDB;
312 
313  if($a_offset)
314  {
315  $period = $a_offset ? $a_offset : 0;
316  $time = time() - $period;
317 
318 
319  $query = "UPDATE webr_items ".
320  "SET valid = '1' ".
321  "WHERE disable_check = '0' ".
322  "AND webr_id = ".$ilDB->quote($this->getLinkResourceId())." ".
323  "AND last_check < ".$ilDB->quote($time);
324 
325  $this->db->query($query);
326  }
327  else
328  {
329  $query = "UPDATE webr_items ".
330  "SET valid = '1' ".
331  "WHERE disable_check = '0' ".
332  "AND webr_id = ".$ilDB->quote($this->getLinkResourceId());
333 
334  $this->db->query($query);
335  }
336  return true;
337  }
338 
339 
340  function add($a_update_history = true)
341  {
342  global $ilDB;
343 
344  $this->__setLastUpdateDate(time());
345  $this->__setCreateDate(time());
346 
347  $query = "INSERT INTO webr_items ".
348  "SET title = ".$ilDB->quote($this->getTitle()).", ".
349  "description = ".$ilDB->quote($this->getDescription()).", ".
350  "target = ".$ilDB->quote($this->getTarget()).", ".
351  "active = ".$ilDB->quote($this->getActiveStatus()).", ".
352  "disable_check = ".$ilDB->quote($this->getDisableCheckStatus()).", ".
353  "last_update = ".$ilDB->quote($this->getLastUpdateDate()).", ".
354  "create_date = ".$ilDB->quote($this->getCreateDate()).", ".
355  "webr_id = ".$ilDB->quote($this->getLinkResourceId());
356 
357  $this->db->query($query);
358 
359  $link_id = $this->db->getLastInsertId();
360  $this->setLinkId($link_id);
361 
362  if($a_update_history)
363  {
364  include_once("classes/class.ilHistory.php");
366  $this->getTitle());
367  }
368 
369  return $link_id;
370  }
371  function readItem($a_link_id)
372  {
373  global $ilDB;
374 
375  $query = "SELECT * FROM webr_items ".
376  "WHERE link_id = ".$ilDB->quote($a_link_id);
377 
378  $res = $this->db->query($query);
379  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
380  {
381  $this->setTitle($row->title);
382  $this->setDescription($row->description);
383  $this->setTarget($row->target);
384  $this->setActiveStatus($row->active);
385  $this->setDisableCheckStatus($row->disable_check);
386  $this->__setCreateDate($row->create_date);
387  $this->__setLastUpdateDate($row->last_update);
388  $this->setLastCheckDate($row->last_check);
389  $this->setValidStatus($row->valid);
390  $this->setLinkId($row->link_id);
391  }
392  return true;
393  }
394 
395 
396  function getItem($a_link_id)
397  {
398  global $ilDB;
399 
400  $query = "SELECT * FROM webr_items ".
401  "WHERE webr_id = ".$ilDB->quote($this->getLinkResourceId())." ".
402  "AND link_id = ".$ilDB->quote($a_link_id);
403 
404  $res = $this->db->query($query);
405  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
406  {
407  $item['title'] = $row->title;
408  $item['description'] = $row->description;
409  $item['target'] = $row->target;
410  $item['active'] = (bool) $row->active;
411  $item['disable_check'] = $row->disable_check;
412  $item['create_date'] = $row->create_date;
413  $item['last_update'] = $row->last_update;
414  $item['last_check'] = $row->last_check;
415  $item['valid'] = $row->valid;
416  $item['link_id'] = $row->link_id;
417  }
418  return $item ? $item : array();
419  }
420 
421 
422  function getAllItems()
423  {
424  global $ilDB;
425 
426  $query = "SELECT * FROM webr_items ".
427  "WHERE webr_id = ".$ilDB->quote($this->getLinkResourceId());
428 
429  $res = $this->db->query($query);
430  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
431  {
432  $items[$row->link_id]['title'] = $row->title;
433  $items[$row->link_id]['description'] = $row->description;
434  $items[$row->link_id]['target'] = $row->target;
435  $items[$row->link_id]['active'] = (bool) $row->active;
436  $items[$row->link_id]['disable_check'] = $row->disable_check;
437  $items[$row->link_id]['create_date'] = $row->create_date;
438  $items[$row->link_id]['last_update'] = $row->last_update;
439  $items[$row->link_id]['last_check'] = $row->last_check;
440  $items[$row->link_id]['valid'] = $row->valid;
441  $items[$row->link_id]['link_id'] = $row->link_id;
442  }
443  return $items ? $items : array();
444  }
445 
446  function getActivatedItems()
447  {
448  foreach($this->getAllItems() as $id => $item_data)
449  {
450  if($item_data['active'])
451  {
452  $active_items[$id] = $item_data;
453  }
454  }
455  return $active_items ? $active_items : array();
456  }
457 
458  function getCheckItems($a_offset = 0)
459  {
460  $period = $a_offset ? $a_offset : 0;
461  $time = time() - $period;
462 
463  foreach($this->getAllItems() as $id => $item_data)
464  {
465  if(!$item_data['disable_check'])
466  {
467  if(!$item_data['last_check'] or $item_data['last_check'] < $time)
468  {
469  $check_items[$id] = $item_data;
470  }
471  }
472  }
473  return $check_items ? $check_items : array();
474  }
475 
476 
477 
478  // STATIC
479  function _deleteAll($webr_id)
480  {
481  global $ilDB;
482 
483  $ilDB->query("DELETE FROM webr_items WHERE webr_id = ".$ilDB->quote($webr_id));
484 
485  return true;
486  }
487 
496  function _isSingular($a_webr_id)
497  {
498  global $ilDB;
499 
500  $res = $ilDB->query("SELECT * FROM webr_items WHERE webr_id = ".$ilDB->quote($a_webr_id)." AND active = '1'");
501 
502  return $res->numRows() == 1 ? true : false;
503  }
504 
513  function _getFirstLink($a_webr_id)
514  {
515  global $ilDB;
516 
517  $res = $ilDB->query("SELECT * FROM webr_items WHERE webr_id = ".
518  $ilDB->quote($a_webr_id)." AND active = '1'");
519  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
520  {
521  $item['title'] = $row->title;
522  $item['description'] = $row->description;
523  $item['target'] = $row->target;
524  $item['active'] = (bool) $row->active;
525  $item['disable_check'] = $row->disable_check;
526  $item['create_date'] = $row->create_date;
527  $item['last_update'] = $row->last_update;
528  $item['last_check'] = $row->last_check;
529  $item['valid'] = $row->valid;
530  $item['link_id'] = $row->link_id;
531  }
532  return $item ? $item : array();
533  }
534 
535 
536 
537 
538 }
539 
540 ?>