Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 include_once "./classes/class.ilObjectGUI.php";
00025
00034 class ilLinkResourceItems
00035 {
00040 function ilLinkResourceItems($webr_id)
00041 {
00042 global $ilDB;
00043
00044 $this->webr_ref_id = 0;
00045 $this->webr_id = $webr_id;
00046
00047 $this->db =& $ilDB;
00048 }
00049
00050
00051 function setLinkResourceRefId($a_ref_id)
00052 {
00053 $this->webr_ref_id = $a_ref_id;
00054 }
00055 function getLinkResourceRefId()
00056 {
00057 return $this->webr_ref_id;
00058 }
00059 function setLinkResourceId($a_id)
00060 {
00061 $this->webr_id = $a_id;
00062 }
00063 function getLinkResourceId()
00064 {
00065 return $this->webr_id;
00066 }
00067 function setLinkId($a_id)
00068 {
00069 $this->id = $a_id;
00070 }
00071 function getLinkId()
00072 {
00073 return $this->id;
00074 }
00075 function setTitle($a_title)
00076 {
00077 $this->title = $a_title;
00078 }
00079 function getTitle()
00080 {
00081 return $this->title;
00082 }
00083 function setDescription($a_description)
00084 {
00085 $this->description = $a_description;
00086 }
00087 function getDescription()
00088 {
00089 return $this->description;
00090 }
00091 function setTarget($a_target)
00092 {
00093 $this->target = $a_target;
00094 }
00095 function getTarget()
00096 {
00097 return $this->target;
00098 }
00099 function setActiveStatus($a_status)
00100 {
00101 $this->status = (int) $a_status;
00102 }
00103 function getActiveStatus()
00104 {
00105 return (bool) $this->status;
00106 }
00107 function setDisableCheckStatus($a_status)
00108 {
00109 $this->check = (int) $a_status;
00110 }
00111 function getDisableCheckStatus()
00112 {
00113 return (bool) $this->check;
00114 }
00115
00116 function __setCreateDate($a_date)
00117 {
00118 $this->c_date = $a_date;
00119 }
00120 function getCreateDate()
00121 {
00122 return $this->c_date;
00123 }
00124
00125 function __setLastUpdateDate($a_date)
00126 {
00127 $this->m_date = $a_date;
00128 }
00129 function getLastUpdateDate()
00130 {
00131 return $this->m_date;
00132 }
00133 function setLastCheckDate($a_date)
00134 {
00135 $this->last_check = $a_date;
00136 }
00137 function getLastCheckDate()
00138 {
00139 return $this->last_check;
00140 }
00141 function setValidStatus($a_status)
00142 {
00143 $this->valid = (int) $a_status;
00144 }
00145 function getValidStatus()
00146 {
00147 return (bool) $this->valid;
00148 }
00149
00157 public function cloneItems($a_new_id)
00158 {
00159 include_once 'Modules/WebResource/classes/class.ilParameterAppender.php';
00160 $appender = new ilParameterAppender($this->getLinkResourceId());
00161
00162 foreach($this->getAllItems() as $item)
00163 {
00164 $new_item = new ilLinkResourceItems($a_new_id);
00165 $new_item->setTitle($item['title']);
00166 $new_item->setDescription($item['description']);
00167 $new_item->setTarget($item['target']);
00168 $new_item->setActiveStatus($item['active']);
00169 $new_item->setDisableCheckStatus($item['disable_check']);
00170 $new_item->setLastCheckDate($item['last_check']);
00171 $new_item->setValidStatus($item['valid']);
00172 $new_item->add(true);
00173
00174
00175 foreach(ilParameterAppender::_getParams($item['link_id']) as $param_id => $data)
00176 {
00177 $appender->setName($data['name']);
00178 $appender->setValue($data['value']);
00179 $appender->add($new_item->getLinkId());
00180 }
00181
00182 unset($new_item);
00183 }
00184 return true;
00185 }
00186
00187 function delete($a_item_id,$a_update_history = true)
00188 {
00189 global $ilDB;
00190
00191 $query = "DELETE FROM webr_items ".
00192 "WHERE webr_id = ".$ilDB->quote($this->getLinkResourceId())." ".
00193 "AND link_id = ".$ilDB->quote($a_item_id);
00194
00195 $this->db->query($query);
00196
00197 if($a_update_history)
00198 {
00199 include_once("classes/class.ilHistory.php");
00200 ilHistory::_createEntry($this->getLinkResourceId(), "delete",
00201 $this->getTitle());
00202 }
00203
00204 return true;
00205 }
00206
00207 function update($a_update_history = true)
00208 {
00209 global $ilDB;
00210
00211 if(!$this->getLinkId())
00212 {
00213 return false;
00214 }
00215
00216 $this->__setLastUpdateDate(time());
00217 $query = "UPDATE webr_items ".
00218 "SET title = ".$ilDB->quote($this->getTitle()).", ".
00219 "description = ".$ilDB->quote($this->getDescription()).", ".
00220 "target = ".$ilDB->quote($this->getTarget()).", ".
00221 "active = ".$ilDB->quote($this->getActiveStatus()).", ".
00222 "valid = ".$ilDB->quote($this->getValidStatus()).", ".
00223 "disable_check = ".$ilDB->quote($this->getDisableCheckStatus()).", ".
00224 "last_update = ".$ilDB->quote($this->getLastUpdateDate()).", ".
00225 "last_check = ".$ilDB->quote($this->getLastCheckDate())." ".
00226 "WHERE link_id = ".$ilDB->quote($this->getLinkId())." ".
00227 "AND webr_id = ".$ilDB->quote($this->getLinkResourceId());
00228
00229 $this->db->query($query);
00230
00231 if($a_update_history)
00232 {
00233 include_once("classes/class.ilHistory.php");
00234 ilHistory::_createEntry($this->getLinkResourceId(), "update",
00235 $this->getTitle());
00236 }
00237
00238 return true;
00239 }
00240
00241 function updateValid($a_status)
00242 {
00243 global $ilDB;
00244
00245 $query = "UPDATE webr_items ".
00246 "SET valid = ".$ilDB->quote($a_status)." ".
00247 "WHERE link_id = ".$ilDB->quote($this->getLinkId());
00248
00249 $this->db->query($query);
00250
00251 return true;
00252 }
00253
00254 function updateActive($a_status)
00255 {
00256 global $ilDB;
00257
00258 $query = "UPDATE webr_items ".
00259 "SET active = ".$ilDB->quote($a_status)." ".
00260 "WHERE link_id = ".$ilDB->quote($this->getLinkId());
00261
00262 $this->db->query($query);
00263
00264 return true;
00265 }
00266 function updateDisableCheck($a_status)
00267 {
00268 global $ilDB;
00269
00270 $query = "UPDATE webr_items ".
00271 "SET disable_check = ".$ilDB->quote($a_status)." ".
00272 "WHERE link_id = ".$ilDB->quote($this->getLinkId());
00273
00274 $this->db->query($query);
00275
00276 return true;
00277 }
00278
00279 function updateLastCheck($a_offset = 0)
00280 {
00281 global $ilDB;
00282
00283 if($a_offset)
00284 {
00285 $period = $a_offset ? $a_offset : 0;
00286 $time = time() - $period;
00287
00288
00289 $query = "UPDATE webr_items ".
00290 "SET last_check = ".$ilDB->quote(time())." ".
00291 "WHERE webr_id = ".$ilDB->quote($this->getLinkResourceId())." ".
00292 "AND disable_check = '0' ".
00293 "AND last_check < ".$ilDB->quote($time);
00294
00295 $this->db->query($query);
00296 }
00297 else
00298 {
00299 $query = "UPDATE webr_items ".
00300 "SET last_check = ".$ilDB->quote(time())." ".
00301 "WHERE webr_id = ".$ilDB->quote($this->getLinkResourceId())." ".
00302 "AND disable_check = '0' ";
00303
00304 $this->db->query($query);
00305 }
00306 return true;
00307 }
00308
00309 function updateValidByCheck($a_offset = 0)
00310 {
00311 global $ilDB;
00312
00313 if($a_offset)
00314 {
00315 $period = $a_offset ? $a_offset : 0;
00316 $time = time() - $period;
00317
00318
00319 $query = "UPDATE webr_items ".
00320 "SET valid = '1' ".
00321 "WHERE disable_check = '0' ".
00322 "AND webr_id = ".$ilDB->quote($this->getLinkResourceId())." ".
00323 "AND last_check < ".$ilDB->quote($time);
00324
00325 $this->db->query($query);
00326 }
00327 else
00328 {
00329 $query = "UPDATE webr_items ".
00330 "SET valid = '1' ".
00331 "WHERE disable_check = '0' ".
00332 "AND webr_id = ".$ilDB->quote($this->getLinkResourceId());
00333
00334 $this->db->query($query);
00335 }
00336 return true;
00337 }
00338
00339
00340 function add($a_update_history = true)
00341 {
00342 global $ilDB;
00343
00344 $this->__setLastUpdateDate(time());
00345 $this->__setCreateDate(time());
00346
00347 $query = "INSERT INTO webr_items ".
00348 "SET title = ".$ilDB->quote($this->getTitle()).", ".
00349 "description = ".$ilDB->quote($this->getDescription()).", ".
00350 "target = ".$ilDB->quote($this->getTarget()).", ".
00351 "active = ".$ilDB->quote($this->getActiveStatus()).", ".
00352 "disable_check = ".$ilDB->quote($this->getDisableCheckStatus()).", ".
00353 "last_update = ".$ilDB->quote($this->getLastUpdateDate()).", ".
00354 "create_date = ".$ilDB->quote($this->getCreateDate()).", ".
00355 "webr_id = ".$ilDB->quote($this->getLinkResourceId());
00356
00357 $this->db->query($query);
00358
00359 $link_id = $this->db->getLastInsertId();
00360 $this->setLinkId($link_id);
00361
00362 if($a_update_history)
00363 {
00364 include_once("classes/class.ilHistory.php");
00365 ilHistory::_createEntry($this->getLinkResourceId(), "add",
00366 $this->getTitle());
00367 }
00368
00369 return $link_id;
00370 }
00371 function readItem($a_link_id)
00372 {
00373 global $ilDB;
00374
00375 $query = "SELECT * FROM webr_items ".
00376 "WHERE link_id = ".$ilDB->quote($a_link_id);
00377
00378 $res = $this->db->query($query);
00379 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00380 {
00381 $this->setTitle($row->title);
00382 $this->setDescription($row->description);
00383 $this->setTarget($row->target);
00384 $this->setActiveStatus($row->active);
00385 $this->setDisableCheckStatus($row->disable_check);
00386 $this->__setCreateDate($row->create_date);
00387 $this->__setLastUpdateDate($row->last_update);
00388 $this->setLastCheckDate($row->last_check);
00389 $this->setValidStatus($row->valid);
00390 $this->setLinkId($row->link_id);
00391 }
00392 return true;
00393 }
00394
00395
00396 function getItem($a_link_id)
00397 {
00398 global $ilDB;
00399
00400 $query = "SELECT * FROM webr_items ".
00401 "WHERE webr_id = ".$ilDB->quote($this->getLinkResourceId())." ".
00402 "AND link_id = ".$ilDB->quote($a_link_id);
00403
00404 $res = $this->db->query($query);
00405 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00406 {
00407 $item['title'] = $row->title;
00408 $item['description'] = $row->description;
00409 $item['target'] = $row->target;
00410 $item['active'] = (bool) $row->active;
00411 $item['disable_check'] = $row->disable_check;
00412 $item['create_date'] = $row->create_date;
00413 $item['last_update'] = $row->last_update;
00414 $item['last_check'] = $row->last_check;
00415 $item['valid'] = $row->valid;
00416 $item['link_id'] = $row->link_id;
00417 }
00418 return $item ? $item : array();
00419 }
00420
00421
00422 function getAllItems()
00423 {
00424 global $ilDB;
00425
00426 $query = "SELECT * FROM webr_items ".
00427 "WHERE webr_id = ".$ilDB->quote($this->getLinkResourceId());
00428
00429 $res = $this->db->query($query);
00430 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00431 {
00432 $items[$row->link_id]['title'] = $row->title;
00433 $items[$row->link_id]['description'] = $row->description;
00434 $items[$row->link_id]['target'] = $row->target;
00435 $items[$row->link_id]['active'] = (bool) $row->active;
00436 $items[$row->link_id]['disable_check'] = $row->disable_check;
00437 $items[$row->link_id]['create_date'] = $row->create_date;
00438 $items[$row->link_id]['last_update'] = $row->last_update;
00439 $items[$row->link_id]['last_check'] = $row->last_check;
00440 $items[$row->link_id]['valid'] = $row->valid;
00441 $items[$row->link_id]['link_id'] = $row->link_id;
00442 }
00443 return $items ? $items : array();
00444 }
00445
00446 function getActivatedItems()
00447 {
00448 foreach($this->getAllItems() as $id => $item_data)
00449 {
00450 if($item_data['active'])
00451 {
00452 $active_items[$id] = $item_data;
00453 }
00454 }
00455 return $active_items ? $active_items : array();
00456 }
00457
00458 function getCheckItems($a_offset = 0)
00459 {
00460 $period = $a_offset ? $a_offset : 0;
00461 $time = time() - $period;
00462
00463 foreach($this->getAllItems() as $id => $item_data)
00464 {
00465 if(!$item_data['disable_check'])
00466 {
00467 if(!$item_data['last_check'] or $item_data['last_check'] < $time)
00468 {
00469 $check_items[$id] = $item_data;
00470 }
00471 }
00472 }
00473 return $check_items ? $check_items : array();
00474 }
00475
00476
00477
00478
00479 function _deleteAll($webr_id)
00480 {
00481 global $ilDB;
00482
00483 $ilDB->query("DELETE FROM webr_items WHERE webr_id = ".$ilDB->quote($webr_id));
00484
00485 return true;
00486 }
00487
00496 function _isSingular($a_webr_id)
00497 {
00498 global $ilDB;
00499
00500 $res = $ilDB->query("SELECT * FROM webr_items WHERE webr_id = ".$ilDB->quote($a_webr_id)." AND active = '1'");
00501
00502 return $res->numRows() == 1 ? true : false;
00503 }
00504
00513 function _getFirstLink($a_webr_id)
00514 {
00515 global $ilDB;
00516
00517 $res = $ilDB->query("SELECT * FROM webr_items WHERE webr_id = ".
00518 $ilDB->quote($a_webr_id)." AND active = '1'");
00519 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00520 {
00521 $item['title'] = $row->title;
00522 $item['description'] = $row->description;
00523 $item['target'] = $row->target;
00524 $item['active'] = (bool) $row->active;
00525 $item['disable_check'] = $row->disable_check;
00526 $item['create_date'] = $row->create_date;
00527 $item['last_update'] = $row->last_update;
00528 $item['last_check'] = $row->last_check;
00529 $item['valid'] = $row->valid;
00530 $item['link_id'] = $row->link_id;
00531 }
00532 return $item ? $item : array();
00533 }
00534
00535
00536
00537
00538 }
00539
00540 ?>