ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilLinkResourceItems.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2011 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5include_once "./Services/Object/classes/class.ilObjectGUI.php";
6
16{
21 function ilLinkResourceItems($webr_id)
22 {
23 global $ilDB;
24
25 $this->webr_ref_id = 0;
26 $this->webr_id = $webr_id;
27
28 $this->db =& $ilDB;
29 }
30
31 // BEGIN PATCH Lucene search
32 public static function lookupItem($a_webr_id,$a_link_id)
33 {
34 global $ilDB;
35
36 $query = "SELECT * FROM webr_items ".
37 "WHERE webr_id = ".$ilDB->quote($a_webr_id ,'integer')." ".
38 "AND link_id = ".$ilDB->quote($a_link_id ,'integer');
39
40 $res = $ilDB->query($query);
41 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
42 {
43 $item['title'] = $row->title;
44 $item['description'] = $row->description;
45 $item['target'] = $row->target;
46 $item['active'] = (bool) $row->active;
47 $item['disable_check'] = $row->disable_check;
48 $item['create_date'] = $row->create_date;
49 $item['last_update'] = $row->last_update;
50 $item['last_check'] = $row->last_check;
51 $item['valid'] = $row->valid;
52 $item['link_id'] = $row->link_id;
53 }
54 return $item ? $item : array();
55
56 }
57 // END PATCH Lucene Search
58
64 public static function updateTitle($a_link_id, $a_title)
65 {
66 global $ilDB;
67
68 $query = 'UPDATE webr_items SET '.
69 'title = '.$ilDB->quote($a_title,'text').' '.
70 'WHERE link_id = '.$ilDB->quote($a_link_id,'integer');
71 $ilDB->manipulate($query);
72 return true;
73 }
74
75
76
77 // SET GET
78 function setLinkResourceRefId($a_ref_id)
79 {
80 $this->webr_ref_id = $a_ref_id;
81 }
83 {
84 return $this->webr_ref_id;
85 }
86 function setLinkResourceId($a_id)
87 {
88 $this->webr_id = $a_id;
89 }
91 {
92 return $this->webr_id;
93 }
94 function setLinkId($a_id)
95 {
96 $this->id = $a_id;
97 }
98 function getLinkId()
99 {
100 return $this->id;
101 }
102 function setTitle($a_title)
103 {
104 $this->title = $a_title;
105 }
106 function getTitle()
107 {
108 return $this->title;
109 }
110 function setDescription($a_description)
111 {
112 $this->description = $a_description;
113 }
114 function getDescription()
115 {
116 return $this->description;
117 }
118 function setTarget($a_target)
119 {
120 $this->target = $a_target;
121 }
122 function getTarget()
123 {
124 return $this->target;
125 }
126 function setActiveStatus($a_status)
127 {
128 $this->status = (int) $a_status;
129 }
131 {
132 return (bool) $this->status;
133 }
134 function setDisableCheckStatus($a_status)
135 {
136 $this->check = (int) $a_status;
137 }
139 {
140 return (bool) $this->check;
141 }
142 // PRIVATE
143 function __setCreateDate($a_date)
144 {
145 $this->c_date = $a_date;
146 }
147 function getCreateDate()
148 {
149 return $this->c_date;
150 }
151 // PRIVATE
152 function __setLastUpdateDate($a_date)
153 {
154 $this->m_date = $a_date;
155 }
157 {
158 return $this->m_date;
159 }
160 function setLastCheckDate($a_date)
161 {
162 $this->last_check = $a_date;
163 }
165 {
166 return $this->last_check;
167 }
168 function setValidStatus($a_status)
169 {
170 $this->valid = (int) $a_status;
171 }
172 function getValidStatus()
173 {
174 return (bool) $this->valid;
175 }
176
184 public function cloneItems($a_new_id)
185 {
186 include_once 'Modules/WebResource/classes/class.ilParameterAppender.php';
187 $appender = new ilParameterAppender($this->getLinkResourceId());
188
189 foreach($this->getAllItems() as $item)
190 {
191 $new_item = new ilLinkResourceItems($a_new_id);
192 $new_item->setTitle($item['title']);
193 $new_item->setDescription($item['description']);
194 $new_item->setTarget($item['target']);
195 $new_item->setActiveStatus($item['active']);
196 $new_item->setDisableCheckStatus($item['disable_check']);
197 $new_item->setLastCheckDate($item['last_check']);
198 $new_item->setValidStatus($item['valid']);
199 $new_item->add(true);
200
201 // Add parameters
202 foreach(ilParameterAppender::_getParams($item['link_id']) as $param_id => $data)
203 {
204 $appender->setName($data['name']);
205 $appender->setValue($data['value']);
206 $appender->add($new_item->getLinkId());
207 }
208
209 unset($new_item);
210 }
211 return true;
212 }
213
214 function delete($a_item_id,$a_update_history = true)
215 {
216 global $ilDB;
217
218 $item = $this->getItem($a_item_id);
219
220 $query = "DELETE FROM webr_items ".
221 "WHERE webr_id = ".$ilDB->quote($this->getLinkResourceId() ,'integer')." ".
222 "AND link_id = ".$ilDB->quote($a_item_id ,'integer');
223 $res = $ilDB->manipulate($query);
224
225 if($a_update_history)
226 {
227 include_once("./Services/History/classes/class.ilHistory.php");
229 $item['title']);
230 }
231
232 return true;
233 }
234
235 function update($a_update_history = true)
236 {
237 global $ilDB;
238
239 if(!$this->getLinkId())
240 {
241 return false;
242 }
243
244 $this->__setLastUpdateDate(time());
245 $query = "UPDATE webr_items ".
246 "SET title = ".$ilDB->quote($this->getTitle() ,'text').", ".
247 "description = ".$ilDB->quote($this->getDescription() ,'text').", ".
248 "target = ".$ilDB->quote($this->getTarget() ,'text').", ".
249 "active = ".$ilDB->quote($this->getActiveStatus() ,'integer').", ".
250 "valid = ".$ilDB->quote($this->getValidStatus() ,'integer').", ".
251 "disable_check = ".$ilDB->quote($this->getDisableCheckStatus() ,'integer').", ".
252 "last_update = ".$ilDB->quote($this->getLastUpdateDate() ,'integer').", ".
253 "last_check = ".$ilDB->quote($this->getLastCheckDate() ,'integer')." ".
254 "WHERE link_id = ".$ilDB->quote($this->getLinkId() ,'integer')." ".
255 "AND webr_id = ".$ilDB->quote($this->getLinkResourceId() ,'integer');
256 $res = $ilDB->manipulate($query);
257
258 if($a_update_history)
259 {
260 include_once("./Services/History/classes/class.ilHistory.php");
262 $this->getTitle());
263 }
264
265 return true;
266 }
267
268 function updateValid($a_status)
269 {
270 global $ilDB;
271
272 $query = "UPDATE webr_items ".
273 "SET valid = ".$ilDB->quote($a_status ,'integer')." ".
274 "WHERE link_id = ".$ilDB->quote($this->getLinkId() ,'integer');
275 $res = $ilDB->manipulate($query);
276
277 return true;
278 }
279
280 function updateActive($a_status)
281 {
282 global $ilDB;
283
284 $query = "UPDATE webr_items ".
285 "SET active = ".$ilDB->quote($a_status ,'integer')." ".
286 "WHERE link_id = ".$ilDB->quote($this->getLinkId() ,'integer');
287
288 $this->db->query($query);
289
290 return true;
291 }
292 function updateDisableCheck($a_status)
293 {
294 global $ilDB;
295
296 $query = "UPDATE webr_items ".
297 "SET disable_check = ".$ilDB->quote($a_status ,'integer')." ".
298 "WHERE link_id = ".$ilDB->quote($this->getLinkId() ,'integer');
299 $res = $ilDB->manipulate($query);
300
301 return true;
302 }
303
304 function updateLastCheck($a_offset = 0)
305 {
306 global $ilDB;
307
308 if($a_offset)
309 {
310 $period = $a_offset ? $a_offset : 0;
311 $time = time() - $period;
312
313
314 $query = "UPDATE webr_items ".
315 "SET last_check = ".$ilDB->quote(time() ,'integer')." ".
316 "WHERE webr_id = ".$ilDB->quote($this->getLinkResourceId() ,'integer')." ".
317 "AND disable_check = '0' ".
318 "AND last_check < ".$ilDB->quote($time ,'integer');
319 $res = $ilDB->manipulate($query);
320 }
321 else
322 {
323 $query = "UPDATE webr_items ".
324 "SET last_check = ".$ilDB->quote(time() ,'integer')." ".
325 "WHERE webr_id = ".$ilDB->quote($this->getLinkResourceId() ,'integer')." ".
326 "AND disable_check = '0' ";
327 $res = $ilDB->manipulate($query);
328 }
329 return true;
330 }
331
332 function updateValidByCheck($a_offset = 0)
333 {
334 global $ilDB;
335
336 if($a_offset)
337 {
338 $period = $a_offset ? $a_offset : 0;
339 $time = time() - $period;
340
341
342 $query = "UPDATE webr_items ".
343 "SET valid = '1' ".
344 "WHERE disable_check = '0' ".
345 "AND webr_id = ".$ilDB->quote($this->getLinkResourceId() ,'integer')." ".
346 "AND last_check < ".$ilDB->quote($time ,'integer');
347 $res = $ilDB->manipulate($query);
348 }
349 else
350 {
351 $query = "UPDATE webr_items ".
352 "SET valid = '1' ".
353 "WHERE disable_check = '0' ".
354 "AND webr_id = ".$ilDB->quote($this->getLinkResourceId() ,'integer');
355 $res = $ilDB->manipulate($query);
356 }
357 return true;
358 }
359
360
361 function add($a_update_history = true)
362 {
363 global $ilDB;
364
365 $this->__setLastUpdateDate(time());
366 $this->__setCreateDate(time());
367
368 $next_id = $ilDB->nextId('webr_items');
369 $query = "INSERT INTO webr_items (link_id,title,description,target,active,disable_check,".
370 "last_update,create_date,webr_id,valid) ".
371 "VALUES( ".
372 $ilDB->quote($next_id ,'integer').", ".
373 $ilDB->quote($this->getTitle() ,'text').", ".
374 $ilDB->quote($this->getDescription() ,'text').", ".
375 $ilDB->quote($this->getTarget() ,'text').", ".
376 $ilDB->quote($this->getActiveStatus() ,'integer').", ".
377 $ilDB->quote($this->getDisableCheckStatus() ,'integer').", ".
378 $ilDB->quote($this->getLastUpdateDate() ,'integer').", ".
379 $ilDB->quote($this->getCreateDate() ,'integer').", ".
380 $ilDB->quote($this->getLinkResourceId() ,'integer').", ".
381 $ilDB->quote($this->getValidStatus(),'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("./Services/History/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
452 public static function getAllItemIds($a_webr_id)
453 {
454 global $ilDB;
455
456 $query = "SELECT link_id FROM webr_items ".
457 "WHERE webr_id = ".$ilDB->quote($a_webr_id ,'integer');
458 $res = $ilDB->query($query);
459 while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
460 {
461 $link_ids[] = $row['link_id'];
462 }
463 return (array) $link_ids;
464 }
465
466 function getAllItems()
467 {
468 global $ilDB;
469
470 $query = "SELECT * FROM webr_items ".
471 "WHERE webr_id = ".$ilDB->quote($this->getLinkResourceId() ,'integer');
472
473 $res = $this->db->query($query);
474 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
475 {
476 $items[$row->link_id]['title'] = $row->title;
477 $items[$row->link_id]['description'] = $row->description;
478 $items[$row->link_id]['target'] = $row->target;
479 $items[$row->link_id]['active'] = (bool) $row->active;
480 $items[$row->link_id]['disable_check'] = $row->disable_check;
481 $items[$row->link_id]['create_date'] = $row->create_date;
482 $items[$row->link_id]['last_update'] = $row->last_update;
483 $items[$row->link_id]['last_check'] = $row->last_check;
484 $items[$row->link_id]['valid'] = $row->valid;
485 $items[$row->link_id]['link_id'] = $row->link_id;
486 }
487 return $items ? $items : array();
488 }
489
495 public function sortItems($a_items)
496 {
497 include_once './Services/Container/classes/class.ilContainer.php';
498 include_once './Services/Container/classes/class.ilContainerSortingSettings.php';
500
501 if($mode == ilContainer::SORT_TITLE)
502 {
503 $a_items = ilUtil::sortArray($a_items, 'title','asc',false,true);
504 return $a_items;
505 }
506
507
508 if($mode == ilContainer::SORT_MANUAL)
509 {
510 include_once './Services/Container/classes/class.ilContainerSorting.php';
512 foreach($a_items as $link_id => $item)
513 {
514 if(isset($pos[$link_id]))
515 {
516 $sorted[$link_id] = $item;
517 $sorted[$link_id]['position'] = $pos[$link_id];
518 }
519 else
520 {
521 $unsorted[$link_id] = $item;
522 }
523 }
524 $sorted = ilUtil::sortArray((array) $sorted, 'position','asc',true,true);
525 $unsorted = ilUtil::sortArray((array) $unsorted, 'title','asc',false,true);
526 $a_items = (array) $sorted + (array) $unsorted;
527 return $a_items;
528 }
529 return $a_items;
530 }
531
532
533
535 {
536 foreach($this->getAllItems() as $id => $item_data)
537 {
538 if($item_data['active'])
539 {
540 $active_items[$id] = $item_data;
541 }
542 }
543 return $active_items ? $active_items : array();
544 }
545
546 function getCheckItems($a_offset = 0)
547 {
548 $period = $a_offset ? $a_offset : 0;
549 $time = time() - $period;
550
551 foreach($this->getAllItems() as $id => $item_data)
552 {
553 if(!$item_data['disable_check'])
554 {
555 if(!$item_data['last_check'] or $item_data['last_check'] < $time)
556 {
557 $check_items[$id] = $item_data;
558 }
559 }
560 }
561 return $check_items ? $check_items : array();
562 }
563
564
565
566 // STATIC
567 function _deleteAll($webr_id)
568 {
569 global $ilDB;
570
571 $ilDB->manipulate("DELETE FROM webr_items WHERE webr_id = ".$ilDB->quote($webr_id ,'integer'));
572
573 return true;
574 }
575
584 public static function _isSingular($a_webr_id)
585 {
586 global $ilDB;
587
588 $query = "SELECT * FROM webr_items ".
589 "WHERE webr_id = ".$ilDB->quote($a_webr_id ,'integer').' '.
590 "AND active = ".$ilDB->quote(1,'integer').' ';
591 $res = $ilDB->query($query);
592 return $res->numRows() == 1 ? true : false;
593 }
594
600 public static function lookupNumberOfLinks($a_webr_id)
601 {
602 global $ilDB;
603
604 $query = "SELECT COUNT(*) num FROM webr_items ".
605 "WHERE webr_id = ".$ilDB->quote($a_webr_id,'integer');
606 $res = $ilDB->query($query);
607 $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
608 return $row->num;
609 }
610
619 public static function _getFirstLink($a_webr_id)
620 {
621 global $ilDB;
622
623 include_once("./Modules/WebResource/classes/class.ilObjLinkResourceAccess.php");
625 }
626
631 public function validate()
632 {
633 return $this->getTarget() and $this->getTitle();
634 }
635
636
642 public function toXML(ilXmlWriter $writer)
643 {
644 $items = $this->sortItems($this->getAllItems());
645
646 $position = 0;
647 foreach((array) $items as $item_id => $item)
648 {
649 ++$position;
650 $link = self::lookupItem($this->getLinkResourceId(), $item_id);
651
652 $writer->xmlStartTag(
653 'WebLink',
654 array(
655 'id' => $link['link_id'],
656 'active' => $link['active'] ? 1 : 0,
657 'valid' => $link['valid'] ? 1 : 0,
658 'disableValidation' => $link['disable_check'] ? 1 : 0,
659 'position' => $position
660 )
661 );
662 $writer->xmlElement('Title',array(),$link['title']);
663 $writer->xmlElement('Description',array(),$link['description']);
664 $writer->xmlElement('Target',array(),$link['target']);
665
666 // Dynamic parameters
667 include_once './Modules/WebResource/classes/class.ilParameterAppender.php';
668 foreach(ilParameterAppender::_getParams($link_id) as $param_id => $param)
669 {
670 $value = '';
671 switch($param['value'])
672 {
673 case LINKS_USER_ID:
674 $value = 'userId';
675 break;
676
677 case LINKS_LOGIN:
678 $value = 'userName';
679 break;
680
682 $value = 'matriculation';
683 break;
684 }
685
686 if(!$value)
687 {
688 // Fix for deprecated LINKS_SESSION
689 continue;
690 }
691
692 $writer->xmlElement(
693 'DynamicParameter',
694 array(
695 'id' => $param_id,
696 'name' => $param['name'],
697 'type' => $value
698 )
699 );
700 }
701
702 $writer->xmlEndTag('WebLink');
703 }
704 return true;
705 }
706}
707
708?>
const DB_FETCHMODE_ASSOC
Definition: class.ilDB.php:10
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
const LINKS_USER_ID
const LINKS_LOGIN
const LINKS_MATRICULATION
static _lookupSortMode($a_obj_id)
lookup sort mode
static lookupPositions($a_obj_id)
Get positions of subitems.
_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 ilObjLinkResourceGUI.
ilLinkResourceItems($webr_id)
Constructor @access public.
validate()
Validate required settings.
static updateTitle($a_link_id, $a_title)
Update title.
update($a_update_history=true)
static getAllItemIds($a_webr_id)
Get all link ids.
static lookupItem($a_webr_id, $a_link_id)
toXML(ilXmlWriter $writer)
Write link XML.
static _getFirstLink($a_webr_id)
Get first link item Check before with _isSingular() if there is more or less than one.
add($a_update_history=true)
cloneItems($a_new_id)
Copy web resource items.
sortItems($a_items)
Sort items (sorting mode depends on sorting setting)
static _isSingular($a_webr_id)
Check whether there is only one active link in the web resource.
static lookupNumberOfLinks($a_webr_id)
Get number of assigned links.
static _getFirstLink($a_webr_id)
Get first link item Check before with _isSingular() if there is more or less than one.
Class ilParameterAppender.
static _getParams($a_link_id)
Get dynamic parameter definitions.
static sortArray($array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
XML writer class.
xmlEndTag($tag)
Writes an endtag.
xmlStartTag($tag, $attrs=NULL, $empty=FALSE, $encode=TRUE, $escape=TRUE)
Writes a starttag.
xmlElement($tag, $attrs=NULL, $data=Null, $encode=TRUE, $escape=TRUE)
Writes a basic element (no children, just textual content)
$valid
$data
global $ilDB