ILIAS  Release_4_0_x_branch Revision 61816
 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  // BEGIN PATCH Lucene search
51  public static function lookupItem($a_webr_id,$a_link_id)
52  {
53  global $ilDB;
54 
55  $query = "SELECT * FROM webr_items ".
56  "WHERE webr_id = ".$ilDB->quote($a_webr_id ,'integer')." ".
57  "AND link_id = ".$ilDB->quote($a_link_id ,'integer');
58 
59  $res = $ilDB->query($query);
60  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
61  {
62  $item['title'] = $row->title;
63  $item['description'] = $row->description;
64  $item['target'] = $row->target;
65  $item['active'] = (bool) $row->active;
66  $item['disable_check'] = $row->disable_check;
67  $item['create_date'] = $row->create_date;
68  $item['last_update'] = $row->last_update;
69  $item['last_check'] = $row->last_check;
70  $item['valid'] = $row->valid;
71  $item['link_id'] = $row->link_id;
72  }
73  return $item ? $item : array();
74 
75  }
76  // END PATCH Lucene Search
77 
78  // SET GET
79  function setLinkResourceRefId($a_ref_id)
80  {
81  $this->webr_ref_id = $a_ref_id;
82  }
84  {
85  return $this->webr_ref_id;
86  }
87  function setLinkResourceId($a_id)
88  {
89  $this->webr_id = $a_id;
90  }
91  function getLinkResourceId()
92  {
93  return $this->webr_id;
94  }
95  function setLinkId($a_id)
96  {
97  $this->id = $a_id;
98  }
99  function getLinkId()
100  {
101  return $this->id;
102  }
103  function setTitle($a_title)
104  {
105  $this->title = $a_title;
106  }
107  function getTitle()
108  {
109  return $this->title;
110  }
111  function setDescription($a_description)
112  {
113  $this->description = $a_description;
114  }
115  function getDescription()
116  {
117  return $this->description;
118  }
119  function setTarget($a_target)
120  {
121  $this->target = $a_target;
122  }
123  function getTarget()
124  {
125  return $this->target;
126  }
127  function setActiveStatus($a_status)
128  {
129  $this->status = (int) $a_status;
130  }
131  function getActiveStatus()
132  {
133  return (bool) $this->status;
134  }
135  function setDisableCheckStatus($a_status)
136  {
137  $this->check = (int) $a_status;
138  }
140  {
141  return (bool) $this->check;
142  }
143  // PRIVATE
144  function __setCreateDate($a_date)
145  {
146  $this->c_date = $a_date;
147  }
148  function getCreateDate()
149  {
150  return $this->c_date;
151  }
152  // PRIVATE
153  function __setLastUpdateDate($a_date)
154  {
155  $this->m_date = $a_date;
156  }
157  function getLastUpdateDate()
158  {
159  return $this->m_date;
160  }
161  function setLastCheckDate($a_date)
162  {
163  $this->last_check = $a_date;
164  }
165  function getLastCheckDate()
166  {
167  return $this->last_check;
168  }
169  function setValidStatus($a_status)
170  {
171  $this->valid = (int) $a_status;
172  }
173  function getValidStatus()
174  {
175  return (bool) $this->valid;
176  }
177 
185  public function cloneItems($a_new_id)
186  {
187  include_once 'Modules/WebResource/classes/class.ilParameterAppender.php';
188  $appender = new ilParameterAppender($this->getLinkResourceId());
189 
190  foreach($this->getAllItems() as $item)
191  {
192  $new_item = new ilLinkResourceItems($a_new_id);
193  $new_item->setTitle($item['title']);
194  $new_item->setDescription($item['description']);
195  $new_item->setTarget($item['target']);
196  $new_item->setActiveStatus($item['active']);
197  $new_item->setDisableCheckStatus($item['disable_check']);
198  $new_item->setLastCheckDate($item['last_check']);
199  $new_item->setValidStatus($item['valid']);
200  $new_item->add(true);
201 
202  // Add parameters
203  foreach(ilParameterAppender::_getParams($item['link_id']) as $param_id => $data)
204  {
205  $appender->setName($data['name']);
206  $appender->setValue($data['value']);
207  $appender->add($new_item->getLinkId());
208  }
209 
210  unset($new_item);
211  }
212  return true;
213  }
214 
215  function delete($a_item_id,$a_update_history = true)
216  {
217  global $ilDB;
218 
219  $item = $this->getItem($a_item_id);
220 
221  $query = "DELETE FROM webr_items ".
222  "WHERE webr_id = ".$ilDB->quote($this->getLinkResourceId() ,'integer')." ".
223  "AND link_id = ".$ilDB->quote($a_item_id ,'integer');
224  $res = $ilDB->manipulate($query);
225 
226  if($a_update_history)
227  {
228  include_once("classes/class.ilHistory.php");
229  ilHistory::_createEntry($this->getLinkResourceId(), "delete",
230  $item['title']);
231  }
232 
233  return true;
234  }
235 
236  function update($a_update_history = true)
237  {
238  global $ilDB;
239 
240  if(!$this->getLinkId())
241  {
242  return false;
243  }
244 
245  $this->__setLastUpdateDate(time());
246  $query = "UPDATE webr_items ".
247  "SET title = ".$ilDB->quote($this->getTitle() ,'text').", ".
248  "description = ".$ilDB->quote($this->getDescription() ,'text').", ".
249  "target = ".$ilDB->quote($this->getTarget() ,'text').", ".
250  "active = ".$ilDB->quote($this->getActiveStatus() ,'integer').", ".
251  "valid = ".$ilDB->quote($this->getValidStatus() ,'integer').", ".
252  "disable_check = ".$ilDB->quote($this->getDisableCheckStatus() ,'integer').", ".
253  "last_update = ".$ilDB->quote($this->getLastUpdateDate() ,'integer').", ".
254  "last_check = ".$ilDB->quote($this->getLastCheckDate() ,'integer')." ".
255  "WHERE link_id = ".$ilDB->quote($this->getLinkId() ,'integer')." ".
256  "AND webr_id = ".$ilDB->quote($this->getLinkResourceId() ,'integer');
257  $res = $ilDB->manipulate($query);
258 
259  if($a_update_history)
260  {
261  include_once("classes/class.ilHistory.php");
262  ilHistory::_createEntry($this->getLinkResourceId(), "update",
263  $this->getTitle());
264  }
265 
266  return true;
267  }
268 
269  function updateValid($a_status)
270  {
271  global $ilDB;
272 
273  $query = "UPDATE webr_items ".
274  "SET valid = ".$ilDB->quote($a_status ,'integer')." ".
275  "WHERE link_id = ".$ilDB->quote($this->getLinkId() ,'integer');
276  $res = $ilDB->manipulate($query);
277 
278  return true;
279  }
280 
281  function updateActive($a_status)
282  {
283  global $ilDB;
284 
285  $query = "UPDATE webr_items ".
286  "SET active = ".$ilDB->quote($a_status ,'integer')." ".
287  "WHERE link_id = ".$ilDB->quote($this->getLinkId() ,'integer');
288 
289  $this->db->query($query);
290 
291  return true;
292  }
293  function updateDisableCheck($a_status)
294  {
295  global $ilDB;
296 
297  $query = "UPDATE webr_items ".
298  "SET disable_check = ".$ilDB->quote($a_status ,'integer')." ".
299  "WHERE link_id = ".$ilDB->quote($this->getLinkId() ,'integer');
300  $res = $ilDB->manipulate($query);
301 
302  return true;
303  }
304 
305  function updateLastCheck($a_offset = 0)
306  {
307  global $ilDB;
308 
309  if($a_offset)
310  {
311  $period = $a_offset ? $a_offset : 0;
312  $time = time() - $period;
313 
314 
315  $query = "UPDATE webr_items ".
316  "SET last_check = ".$ilDB->quote(time() ,'integer')." ".
317  "WHERE webr_id = ".$ilDB->quote($this->getLinkResourceId() ,'integer')." ".
318  "AND disable_check = '0' ".
319  "AND last_check < ".$ilDB->quote($time ,'integer');
320  $res = $ilDB->manipulate($query);
321  }
322  else
323  {
324  $query = "UPDATE webr_items ".
325  "SET last_check = ".$ilDB->quote(time() ,'integer')." ".
326  "WHERE webr_id = ".$ilDB->quote($this->getLinkResourceId() ,'integer')." ".
327  "AND disable_check = '0' ";
328  $res = $ilDB->manipulate($query);
329  }
330  return true;
331  }
332 
333  function updateValidByCheck($a_offset = 0)
334  {
335  global $ilDB;
336 
337  if($a_offset)
338  {
339  $period = $a_offset ? $a_offset : 0;
340  $time = time() - $period;
341 
342 
343  $query = "UPDATE webr_items ".
344  "SET valid = '1' ".
345  "WHERE disable_check = '0' ".
346  "AND webr_id = ".$ilDB->quote($this->getLinkResourceId() ,'integer')." ".
347  "AND last_check < ".$ilDB->quote($time ,'integer');
348  $res = $ilDB->manipulate($query);
349  }
350  else
351  {
352  $query = "UPDATE webr_items ".
353  "SET valid = '1' ".
354  "WHERE disable_check = '0' ".
355  "AND webr_id = ".$ilDB->quote($this->getLinkResourceId() ,'integer');
356  $res = $ilDB->manipulate($query);
357  }
358  return true;
359  }
360 
361 
362  function add($a_update_history = true)
363  {
364  global $ilDB;
365 
366  $this->__setLastUpdateDate(time());
367  $this->__setCreateDate(time());
368 
369  $next_id = $ilDB->nextId('webr_items');
370  $query = "INSERT INTO webr_items (link_id,title,description,target,active,disable_check,".
371  "last_update,create_date,webr_id) ".
372  "VALUES( ".
373  $ilDB->quote($next_id ,'integer').", ".
374  $ilDB->quote($this->getTitle() ,'text').", ".
375  $ilDB->quote($this->getDescription() ,'text').", ".
376  $ilDB->quote($this->getTarget() ,'text').", ".
377  $ilDB->quote($this->getActiveStatus() ,'integer').", ".
378  $ilDB->quote($this->getDisableCheckStatus() ,'integer').", ".
379  $ilDB->quote($this->getLastUpdateDate() ,'integer').", ".
380  $ilDB->quote($this->getCreateDate() ,'integer').", ".
381  $ilDB->quote($this->getLinkResourceId() ,'integer')." ".
382  ")";
383  $res = $ilDB->manipulate($query);
384 
385  $link_id = $next_id;
386  $this->setLinkId($link_id);
387 
388  if($a_update_history)
389  {
390  include_once("classes/class.ilHistory.php");
392  $this->getTitle());
393  }
394 
395  return $link_id;
396  }
397  function readItem($a_link_id)
398  {
399  global $ilDB;
400 
401  $query = "SELECT * FROM webr_items ".
402  "WHERE link_id = ".$ilDB->quote($a_link_id ,'integer');
403 
404  $res = $this->db->query($query);
405  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
406  {
407  $this->setTitle($row->title);
408  $this->setDescription($row->description);
409  $this->setTarget($row->target);
410  $this->setActiveStatus($row->active);
411  $this->setDisableCheckStatus($row->disable_check);
412  $this->__setCreateDate($row->create_date);
413  $this->__setLastUpdateDate($row->last_update);
414  $this->setLastCheckDate($row->last_check);
415  $this->setValidStatus($row->valid);
416  $this->setLinkId($row->link_id);
417  }
418  return true;
419  }
420 
421 
422  function getItem($a_link_id)
423  {
424  global $ilDB;
425 
426  $query = "SELECT * FROM webr_items ".
427  "WHERE webr_id = ".$ilDB->quote($this->getLinkResourceId() ,'integer')." ".
428  "AND link_id = ".$ilDB->quote($a_link_id ,'integer');
429 
430  $res = $this->db->query($query);
431  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
432  {
433  $item['title'] = $row->title;
434  $item['description'] = $row->description;
435  $item['target'] = $row->target;
436  $item['active'] = (bool) $row->active;
437  $item['disable_check'] = $row->disable_check;
438  $item['create_date'] = $row->create_date;
439  $item['last_update'] = $row->last_update;
440  $item['last_check'] = $row->last_check;
441  $item['valid'] = $row->valid;
442  $item['link_id'] = $row->link_id;
443  }
444  return $item ? $item : array();
445  }
446 
447 
448  function getAllItems()
449  {
450  global $ilDB;
451 
452  $query = "SELECT * FROM webr_items ".
453  "WHERE webr_id = ".$ilDB->quote($this->getLinkResourceId() ,'integer');
454 
455  $res = $this->db->query($query);
456  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
457  {
458  $items[$row->link_id]['title'] = $row->title;
459  $items[$row->link_id]['description'] = $row->description;
460  $items[$row->link_id]['target'] = $row->target;
461  $items[$row->link_id]['active'] = (bool) $row->active;
462  $items[$row->link_id]['disable_check'] = $row->disable_check;
463  $items[$row->link_id]['create_date'] = $row->create_date;
464  $items[$row->link_id]['last_update'] = $row->last_update;
465  $items[$row->link_id]['last_check'] = $row->last_check;
466  $items[$row->link_id]['valid'] = $row->valid;
467  $items[$row->link_id]['link_id'] = $row->link_id;
468  }
469  return $items ? $items : array();
470  }
471 
477  public function sortItems($a_items)
478  {
479  include_once './Services/Container/classes/class.ilContainer.php';
480  include_once './Services/Container/classes/class.ilContainerSortingSettings.php';
482 
483  if($mode == ilContainer::SORT_TITLE)
484  {
485  $a_items = ilUtil::sortArray($a_items, 'title','asc',false,true);
486  return $a_items;
487  }
488 
489 
490  if($mode == ilContainer::SORT_MANUAL)
491  {
492  include_once './Services/Container/classes/class.ilContainerSorting.php';
494  foreach($a_items as $link_id => $item)
495  {
496  if(isset($pos[$link_id]))
497  {
498  $sorted[$link_id] = $item;
499  $sorted[$link_id]['position'] = $pos[$link_id];
500  }
501  else
502  {
503  $unsorted[$link_id] = $item;
504  }
505  }
506  $sorted = ilUtil::sortArray((array) $sorted, 'position','asc',true,true);
507  $unsorted = ilUtil::sortArray((array) $unsorted, 'title','asc',false,true);
508  $a_items = (array) $sorted + (array) $unsorted;
509  return $a_items;
510  }
511  return $a_items;
512  }
513 
514 
515 
516  function getActivatedItems()
517  {
518  foreach($this->getAllItems() as $id => $item_data)
519  {
520  if($item_data['active'])
521  {
522  $active_items[$id] = $item_data;
523  }
524  }
525  return $active_items ? $active_items : array();
526  }
527 
528  function getCheckItems($a_offset = 0)
529  {
530  $period = $a_offset ? $a_offset : 0;
531  $time = time() - $period;
532 
533  foreach($this->getAllItems() as $id => $item_data)
534  {
535  if(!$item_data['disable_check'])
536  {
537  if(!$item_data['last_check'] or $item_data['last_check'] < $time)
538  {
539  $check_items[$id] = $item_data;
540  }
541  }
542  }
543  return $check_items ? $check_items : array();
544  }
545 
546 
547 
548  // STATIC
549  function _deleteAll($webr_id)
550  {
551  global $ilDB;
552 
553  $ilDB->manipulate("DELETE FROM webr_items WHERE webr_id = ".$ilDB->quote($webr_id ,'integer'));
554 
555  return true;
556  }
557 
566  public static function _isSingular($a_webr_id)
567  {
568  global $ilDB;
569 
570  $res = $ilDB->query("SELECT * FROM webr_items WHERE webr_id = ".$ilDB->quote($a_webr_id ,'integer')." AND active = '1'");
571 
572  return $res->numRows() == 1 ? true : false;
573  }
574 
580  public static function lookupNumberOfLinks($a_webr_id)
581  {
582  global $ilDB;
583 
584  $query = "SELECT COUNT(*) num FROM webr_items ".
585  "WHERE webr_id = ".$ilDB->quote($a_webr_id,'integer');
586  $res = $ilDB->query($query);
587  $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
588  return $row->num;
589  }
590 
599  public static function _getFirstLink($a_webr_id)
600  {
601  global $ilDB;
602 
603  $res = $ilDB->query("SELECT * FROM webr_items WHERE webr_id = ".
604  $ilDB->quote($a_webr_id ,'integer')." AND active = '1'");
605  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
606  {
607  $item['title'] = $row->title;
608  $item['description'] = $row->description;
609  $item['target'] = $row->target;
610  $item['active'] = (bool) $row->active;
611  $item['disable_check'] = $row->disable_check;
612  $item['create_date'] = $row->create_date;
613  $item['last_update'] = $row->last_update;
614  $item['last_check'] = $row->last_check;
615  $item['valid'] = $row->valid;
616  $item['link_id'] = $row->link_id;
617  }
618  return $item ? $item : array();
619  }
620 
621 
622 
623 
624 }
625 
626 ?>