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
00034 include_once "./classes/class.ilObjectGUI.php";
00035
00036 class ilLinkResourceItems
00037 {
00042 function ilLinkResourceItems($webr_id)
00043 {
00044 global $ilDB;
00045
00046 $this->webr_ref_id = $webr_ref_id;
00047 $this->webr_id = $webr_id;
00048
00049 $this->db =& $ilDB;
00050 }
00051
00052
00053 function setLinkResourceRefId($a_ref_id)
00054 {
00055 $this->webr_ref_id = $a_ref_id;
00056 }
00057 function getLinkResourceRefId()
00058 {
00059 return $this->webr_ref_id;
00060 }
00061 function setLinkResourceId($a_id)
00062 {
00063 $this->webr_id = $a_id;
00064 }
00065 function getLinkResourceId()
00066 {
00067 return $this->webr_id;
00068 }
00069 function setLinkId($a_id)
00070 {
00071 $this->id = $a_id;
00072 }
00073 function getLinkId()
00074 {
00075 return $this->id;
00076 }
00077 function setTitle($a_title)
00078 {
00079 $this->title = $a_title;
00080 }
00081 function getTitle()
00082 {
00083 return $this->title;
00084 }
00085 function setTarget($a_target)
00086 {
00087 $this->target = $a_target;
00088 }
00089 function getTarget()
00090 {
00091 return $this->target;
00092 }
00093 function setActiveStatus($a_status)
00094 {
00095 $this->status = (int) $a_status;
00096 }
00097 function getActiveStatus()
00098 {
00099 return (bool) $this->status;
00100 }
00101 function setDisableCheckStatus($a_status)
00102 {
00103 $this->check = (int) $a_status;
00104 }
00105 function getDisableCheckStatus()
00106 {
00107 return (bool) $this->check;
00108 }
00109
00110 function __setCreateDate($a_date)
00111 {
00112 $this->c_date = $a_date;
00113 }
00114 function getCreateDate()
00115 {
00116 return $this->c_date;
00117 }
00118
00119 function __setLastUpdateDate($a_date)
00120 {
00121 $this->m_date = $a_date;
00122 }
00123 function getLastUpdateDate()
00124 {
00125 return $this->m_date;
00126 }
00127 function setLastCheckDate($a_date)
00128 {
00129 $this->last_check = $a_date;
00130 }
00131 function getLastCheckDate()
00132 {
00133 return $this->last_check;
00134 }
00135 function setValidStatus($a_status)
00136 {
00137 $this->valid = (int) $a_status;
00138 }
00139 function getValidStatus()
00140 {
00141 return (bool) $this->valid;
00142 }
00143
00144 function delete($a_item_id,$a_update_history = true)
00145 {
00146 $query = "DELETE FROM webr_items ".
00147 "WHERE webr_id = '".$this->getLinkResourceId()."' ".
00148 "AND link_id = '".$a_item_id."'";
00149
00150 $this->db->query($query);
00151
00152 if($a_update_history)
00153 {
00154 include_once("classes/class.ilHistory.php");
00155 ilHistory::_createEntry($this->getLinkResourceId(), "delete",
00156 $this->getTitle());
00157 }
00158
00159 return true;
00160 }
00161
00162 function update($a_update_history = true)
00163 {
00164 if(!$this->getLinkId())
00165 {
00166 return false;
00167 }
00168
00169 $this->__setLastUpdateDate(time());
00170 $query = "UPDATE webr_items ".
00171 "SET title = '".ilUtil::prepareDBString($this->getTitle())."', ".
00172 "target = '".ilUtil::prepareDBString($this->getTarget())."', ".
00173 "active = '".$this->getActiveStatus()."', ".
00174 "valid = '".$this->getValidStatus()."', ".
00175 "disable_check = '".$this->getDisableCheckStatus()."', ".
00176 "last_update = '".$this->getLastUpdateDate()."', ".
00177 "last_check = '".$this->getLastCheckDate()."' ".
00178 "WHERE link_id = '".$this->getLinkId()."' ".
00179 "AND webr_id = '".$this->getLinkResourceId()."'";
00180
00181 $this->db->query($query);
00182
00183 if($a_update_history)
00184 {
00185 include_once("classes/class.ilHistory.php");
00186 ilHistory::_createEntry($this->getLinkResourceId(), "update",
00187 $this->getTitle());
00188 }
00189
00190 return true;
00191 }
00192
00193 function updateValid($a_status)
00194 {
00195 $query = "UPDATE webr_items ".
00196 "SET valid = '".$a_status."' ".
00197 "WHERE link_id = '".$this->getLinkId()."'";
00198
00199 $this->db->query($query);
00200
00201 return true;
00202 }
00203
00204 function updateActive($a_status)
00205 {
00206 $query = "UPDATE webr_items ".
00207 "SET active = '".$a_status."' ".
00208 "WHERE link_id = '".$this->getLinkId()."'";
00209
00210 $this->db->query($query);
00211
00212 return true;
00213 }
00214 function updateDisableCheck($a_status)
00215 {
00216 $query = "UPDATE webr_items ".
00217 "SET disable_check = '".$a_status."' ".
00218 "WHERE link_id = '".$this->getLinkId()."'";
00219
00220 $this->db->query($query);
00221
00222 return true;
00223 }
00224
00225 function updateLastCheck($a_offset = 0)
00226 {
00227 if($a_offset)
00228 {
00229 $period = $a_offset ? $a_offset : 0;
00230 $time = time() - $period;
00231
00232
00233 $query = "UPDATE webr_items ".
00234 "SET last_check = '".time()."' ".
00235 "WHERE webr_id = '".$this->getLinkResourceId()."' ".
00236 "AND disable_check = '0' ".
00237 "AND last_check < '".$time."'";
00238
00239 $this->db->query($query);
00240 }
00241 else
00242 {
00243 $query = "UPDATE webr_items ".
00244 "SET last_check = '".time()."' ".
00245 "WHERE webr_id = '".$this->getLinkResourceId()."' ".
00246 "AND disable_check = '0' ";
00247
00248 $this->db->query($query);
00249 }
00250 return true;
00251 }
00252
00253 function updateValidByCheck($a_offset = 0)
00254 {
00255 if($a_offset)
00256 {
00257 $period = $a_offset ? $a_offset : 0;
00258 $time = time() - $period;
00259
00260
00261 $query = "UPDATE webr_items ".
00262 "SET valid = '1' ".
00263 "WHERE disable_check = '0' ".
00264 "AND webr_id = '".$this->getLinkResourceId()."' ".
00265 "AND last_check < '".$time."'";
00266
00267 $this->db->query($query);
00268 }
00269 else
00270 {
00271 $query = "UPDATE webr_items ".
00272 "SET valid = '1' ".
00273 "WHERE disable_check = '0' ".
00274 "AND webr_id = '".$this->getLinkResourceId()."'";
00275
00276 $this->db->query($query);
00277 }
00278 return true;
00279 }
00280
00281
00282 function add($a_update_history = true)
00283 {
00284 $this->__setLastUpdateDate(time());
00285 $this->__setCreateDate(time());
00286
00287 $query = "INSERT INTO webr_items ".
00288 "SET title = '".ilUtil::prepareDBString($this->getTitle())."', ".
00289 "target = '".ilUtil::prepareDBString($this->getTarget())."', ".
00290 "active = '".$this->getActiveStatus()."', ".
00291 "disable_check = '".$this->getDisableCheckStatus()."', ".
00292 "last_update = '".$this->getLastUpdateDate()."', ".
00293 "create_date = '".$this->getCreateDate()."', ".
00294 "webr_id = '".$this->getLinkResourceId()."'";
00295
00296 $this->db->query($query);
00297
00298 if($a_update_history)
00299 {
00300 include_once("classes/class.ilHistory.php");
00301 ilHistory::_createEntry($this->getLinkResourceId(), "add",
00302 $this->getTitle());
00303 }
00304
00305 return true;
00306 }
00307 function readItem($a_link_id)
00308 {
00309 $query = "SELECT * FROM webr_items ".
00310 "WHERE link_id = '".$a_link_id."'";
00311
00312 $res = $this->db->query($query);
00313 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00314 {
00315 $this->setTitle($row->title);
00316 $this->setTarget($row->target);
00317 $this->setActiveStatus($row->active);
00318 $this->setDisableCheckStatus($row->disable_check);
00319 $this->__setCreateDate($row->create_date);
00320 $this->__setLastUpdateDate($row->last_update);
00321 $this->setLastCheckDate($row->last_check);
00322 $this->setValidStatus($row->valid);
00323 $this->setLinkId($row->link_id);
00324 }
00325 return true;
00326 }
00327
00328
00329 function getItem($a_link_id)
00330 {
00331
00332 $query = "SELECT * FROM webr_items ".
00333 "WHERE webr_id = '".$this->getLinkResourceId()."' ".
00334 "AND link_id = '".$a_link_id."'";
00335
00336 $res = $this->db->query($query);
00337 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00338 {
00339 $item['title'] = $row->title;
00340 $item['target'] = $row->target;
00341 $item['active'] = (bool) $row->active;
00342 $item['disable_check'] = $row->disable_check;
00343 $item['create_date'] = $row->create_date;
00344 $item['last_update'] = $row->last_update;
00345 $item['last_check'] = $row->last_check;
00346 $item['valid'] = $row->valid;
00347 $item['link_id'] = $row->link_id;
00348 }
00349 return $item ? $item : array();
00350 }
00351
00352
00353 function getAllItems()
00354 {
00355 $query = "SELECT * FROM webr_items ".
00356 "WHERE webr_id = '".$this->getLinkResourceId()."'";
00357
00358 $res = $this->db->query($query);
00359 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00360 {
00361 $items[$row->link_id]['title'] = $row->title;
00362 $items[$row->link_id]['target'] = $row->target;
00363 $items[$row->link_id]['active'] = (bool) $row->active;
00364 $items[$row->link_id]['disable_check'] = $row->disable_check;
00365 $items[$row->link_id]['create_date'] = $row->create_date;
00366 $items[$row->link_id]['last_update'] = $row->last_update;
00367 $items[$row->link_id]['last_check'] = $row->last_check;
00368 $items[$row->link_id]['valid'] = $row->valid;
00369 $items[$row->link_id]['link_id'] = $row->link_id;
00370 }
00371 return $items ? $items : array();
00372 }
00373 function getActivatedItems()
00374 {
00375 foreach($this->getAllItems() as $id => $item_data)
00376 {
00377 if($item_data['active'])
00378 {
00379 $active_items[$id] = $item_data;
00380 }
00381 }
00382 return $active_items ? $active_items : array();
00383 }
00384
00385 function getCheckItems($a_offset = 0)
00386 {
00387 $period = $a_offset ? $a_offset : 0;
00388 $time = time() - $period;
00389
00390 foreach($this->getAllItems() as $id => $item_data)
00391 {
00392 if(!$item_data['disable_check'])
00393 {
00394 if(!$item_data['last_check'] or $item_data['last_check'] < $time)
00395 {
00396 $check_items[$id] = $item_data;
00397 }
00398 }
00399 }
00400 return $check_items ? $check_items : array();
00401 }
00402
00403
00404
00405
00406 function _deleteAll($webr_id)
00407 {
00408 global $ilDB;
00409
00410 $ilDB->query("DELETE FROM webr_items WHERE webr_id = '".$webr_id."'");
00411
00412 return true;
00413 }
00414 }
00415
00416 ?>