• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

link/classes/class.ilLinkResourceItems.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
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         // SET GET
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 setDescription($a_description)
00086         {
00087                 $this->description = $a_description;
00088         }
00089         function getDescription()
00090         {
00091                 return $this->description;
00092         }
00093         function setTarget($a_target)
00094         {
00095                 $this->target = $a_target;
00096         }
00097         function getTarget()
00098         {
00099                 return $this->target;
00100         }
00101         function setActiveStatus($a_status)
00102         {
00103                 $this->status = (int) $a_status;
00104         }
00105         function getActiveStatus()
00106         {
00107                 return (bool) $this->status;
00108         }
00109         function setDisableCheckStatus($a_status)
00110         {
00111                 $this->check = (int) $a_status;
00112         }
00113         function getDisableCheckStatus()
00114         {
00115                 return (bool) $this->check;
00116         }
00117         // PRIVATE
00118         function __setCreateDate($a_date)
00119         {
00120                 $this->c_date = $a_date;
00121         }
00122         function getCreateDate()
00123         {
00124                 return $this->c_date;
00125         }
00126         // PRIVATE
00127         function __setLastUpdateDate($a_date)
00128         {
00129                 $this->m_date = $a_date;
00130         }
00131         function getLastUpdateDate()
00132         {
00133                 return $this->m_date;
00134         }
00135         function setLastCheckDate($a_date)
00136         {
00137                 $this->last_check = $a_date;
00138         }
00139         function getLastCheckDate()
00140         {
00141                 return $this->last_check;
00142         }
00143         function setValidStatus($a_status)
00144         {
00145                 $this->valid = (int) $a_status;
00146         }
00147         function getValidStatus()
00148         {
00149                 return (bool) $this->valid;
00150         }
00151 
00152         function delete($a_item_id,$a_update_history = true)
00153         {
00154                 $query = "DELETE FROM webr_items ".
00155                         "WHERE webr_id = '".$this->getLinkResourceId()."' ".
00156                         "AND link_id = '".$a_item_id."'";
00157 
00158                 $this->db->query($query);
00159 
00160                 if($a_update_history)
00161                 {
00162                         include_once("classes/class.ilHistory.php");
00163                         ilHistory::_createEntry($this->getLinkResourceId(), "delete",
00164                                                                         $this->getTitle());
00165                 }
00166 
00167                 return true;
00168         }
00169 
00170         function update($a_update_history = true)
00171         {
00172                 if(!$this->getLinkId())
00173                 {
00174                         return false;
00175                 }
00176 
00177                 $this->__setLastUpdateDate(time());
00178                 $query = "UPDATE webr_items ".
00179                         "SET title = '".ilUtil::prepareDBString($this->getTitle())."', ".
00180                         "description = '".ilUtil::prepareDBString($this->getDescription())."', ".
00181                         "target = '".ilUtil::prepareDBString($this->getTarget())."', ".
00182                         "active = '".$this->getActiveStatus()."', ".
00183                         "valid = '".$this->getValidStatus()."', ".
00184                         "disable_check = '".$this->getDisableCheckStatus()."', ".
00185                         "last_update = '".$this->getLastUpdateDate()."', ".
00186                         "last_check = '".$this->getLastCheckDate()."' ".
00187                         "WHERE link_id = '".$this->getLinkId()."' ".
00188                         "AND webr_id = '".$this->getLinkResourceId()."'";
00189 
00190                 $this->db->query($query);
00191 
00192                 if($a_update_history)
00193                 {
00194                         include_once("classes/class.ilHistory.php");
00195                         ilHistory::_createEntry($this->getLinkResourceId(), "update",
00196                                                                         $this->getTitle());
00197                 }
00198 
00199                 return true;
00200         }
00201 
00202         function updateValid($a_status)
00203         {
00204                 $query = "UPDATE webr_items ".
00205                         "SET valid = '".$a_status."' ".
00206                         "WHERE link_id = '".$this->getLinkId()."'";
00207 
00208                 $this->db->query($query);
00209 
00210                 return true;
00211         }
00212 
00213         function updateActive($a_status)
00214         {
00215                 $query = "UPDATE webr_items ".
00216                         "SET active = '".$a_status."' ".
00217                         "WHERE link_id = '".$this->getLinkId()."'";
00218 
00219                 $this->db->query($query);
00220 
00221                 return true;
00222         }
00223         function updateDisableCheck($a_status)
00224         {
00225                 $query = "UPDATE webr_items ".
00226                         "SET disable_check = '".$a_status."' ".
00227                         "WHERE link_id = '".$this->getLinkId()."'";
00228 
00229                 $this->db->query($query);
00230 
00231                 return true;
00232         }
00233 
00234         function updateLastCheck($a_offset = 0)
00235         {
00236                 if($a_offset)
00237                 {
00238                         $period = $a_offset ? $a_offset : 0;
00239                         $time = time() - $period;
00240                         
00241                         
00242                         $query = "UPDATE webr_items ".
00243                                 "SET last_check = '".time()."' ".
00244                                 "WHERE webr_id = '".$this->getLinkResourceId()."' ".
00245                                 "AND disable_check = '0' ".
00246                                 "AND last_check < '".$time."'";
00247                         
00248                         $this->db->query($query);
00249                 }
00250                 else
00251                 {
00252                         $query = "UPDATE webr_items ".
00253                                 "SET last_check = '".time()."' ".
00254                                 "WHERE webr_id = '".$this->getLinkResourceId()."' ".
00255                                 "AND disable_check = '0' ";
00256                         
00257                         $this->db->query($query);
00258                 }
00259                 return true;
00260         }
00261 
00262         function updateValidByCheck($a_offset = 0)
00263         {
00264                 if($a_offset)
00265                 {
00266                         $period = $a_offset ? $a_offset : 0;
00267                         $time = time() - $period;
00268                         
00269                         
00270                         $query = "UPDATE webr_items ".
00271                                 "SET valid = '1' ".
00272                                 "WHERE disable_check = '0' ".
00273                                 "AND webr_id = '".$this->getLinkResourceId()."' ".
00274                                 "AND last_check < '".$time."'";
00275                         
00276                         $this->db->query($query);
00277                 }
00278                 else
00279                 {
00280                         $query = "UPDATE webr_items ".
00281                                 "SET valid = '1' ".
00282                                 "WHERE disable_check = '0' ".
00283                                 "AND webr_id = '".$this->getLinkResourceId()."'";
00284 
00285                         $this->db->query($query);
00286                 }
00287                 return true;
00288         }
00289 
00290 
00291         function add($a_update_history = true)
00292         {
00293                 $this->__setLastUpdateDate(time());
00294                 $this->__setCreateDate(time());
00295 
00296                 $query = "INSERT INTO webr_items ".
00297                         "SET title = '".ilUtil::prepareDBString($this->getTitle())."', ".
00298                         "description = '".ilUtil::prepareDBString($this->getDescription())."', ".
00299                         "target = '".ilUtil::prepareDBString($this->getTarget())."', ".
00300                         "active = '".$this->getActiveStatus()."', ".
00301                         "disable_check = '".$this->getDisableCheckStatus()."', ".
00302                         "last_update = '".$this->getLastUpdateDate()."', ".
00303                         "create_date = '".$this->getCreateDate()."', ".
00304                         "webr_id = '".$this->getLinkResourceId()."'";
00305 
00306                 $this->db->query($query);
00307 
00308                 $link_id = $this->db->getLastInsertId();
00309 
00310                 if($a_update_history)
00311                 {
00312                         include_once("classes/class.ilHistory.php");
00313                         ilHistory::_createEntry($this->getLinkResourceId(), "add",
00314                                                                         $this->getTitle());
00315                 }
00316 
00317                 return $link_id;
00318         }
00319         function readItem($a_link_id)
00320         {
00321                 $query = "SELECT * FROM webr_items ".
00322                         "WHERE link_id = '".$a_link_id."'";
00323 
00324                 $res = $this->db->query($query);
00325                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00326                 {
00327                         $this->setTitle($row->title);
00328                         $this->setDescription($row->description);
00329                         $this->setTarget($row->target);
00330                         $this->setActiveStatus($row->active);
00331                         $this->setDisableCheckStatus($row->disable_check);
00332                         $this->__setCreateDate($row->create_date);
00333                         $this->__setLastUpdateDate($row->last_update);
00334                         $this->setLastCheckDate($row->last_check);
00335                         $this->setValidStatus($row->valid);
00336                         $this->setLinkId($row->link_id);
00337                 }
00338                 return true;
00339         }
00340 
00341 
00342         function getItem($a_link_id)
00343         {
00344 
00345                 $query = "SELECT * FROM webr_items ".
00346                         "WHERE webr_id = '".$this->getLinkResourceId()."' ".
00347                         "AND link_id = '".$a_link_id."'";
00348 
00349                 $res = $this->db->query($query);
00350                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00351                 {
00352                         $item['title']                          = $row->title;
00353                         $item['description']            = $row->description;
00354                         $item['target']                         = $row->target;
00355                         $item['active']                         = (bool) $row->active;
00356                         $item['disable_check']          = $row->disable_check;
00357                         $item['create_date']            = $row->create_date;
00358                         $item['last_update']            = $row->last_update;
00359                         $item['last_check']                     = $row->last_check;
00360                         $item['valid']                          = $row->valid;
00361                         $item['link_id']                        = $row->link_id;
00362                 }
00363                 return $item ? $item : array();
00364         }
00365                 
00366                 
00367         function getAllItems()
00368         {
00369                 $query = "SELECT * FROM webr_items ".
00370                         "WHERE webr_id = '".$this->getLinkResourceId()."'";
00371 
00372                 $res = $this->db->query($query);
00373                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00374                 {
00375                         $items[$row->link_id]['title']                          = $row->title;
00376                         $items[$row->link_id]['description']            = $row->description;
00377                         $items[$row->link_id]['target']                         = $row->target;
00378                         $items[$row->link_id]['active']                         = (bool) $row->active;
00379                         $items[$row->link_id]['disable_check']          = $row->disable_check;
00380                         $items[$row->link_id]['create_date']            = $row->create_date;
00381                         $items[$row->link_id]['last_update']            = $row->last_update;
00382                         $items[$row->link_id]['last_check']                     = $row->last_check;
00383                         $items[$row->link_id]['valid']                          = $row->valid;
00384                         $items[$row->link_id]['link_id']                        = $row->link_id;
00385                 }
00386                 return $items ? $items : array();
00387         }
00388         function getActivatedItems()
00389         {
00390                 foreach($this->getAllItems() as $id => $item_data)
00391                 {
00392                         if($item_data['active'])
00393                         {
00394                                 $active_items[$id] = $item_data;
00395                         }
00396                 }
00397                 return $active_items ? $active_items : array();
00398         }
00399 
00400         function getCheckItems($a_offset = 0)
00401         {
00402                 $period = $a_offset ? $a_offset : 0;
00403                 $time = time() - $period;
00404 
00405                 foreach($this->getAllItems() as $id => $item_data)
00406                 {
00407                         if(!$item_data['disable_check'])
00408                         {
00409                                 if(!$item_data['last_check'] or $item_data['last_check'] < $time)
00410                                 {
00411                                         $check_items[$id] = $item_data;
00412                                 }
00413                         }
00414                 }
00415                 return $check_items ? $check_items : array();
00416         }
00417                 
00418 
00419 
00420         // STATIC
00421         function _deleteAll($webr_id)
00422         {
00423                 global $ilDB;
00424                 
00425                 $ilDB->query("DELETE FROM webr_items WHERE webr_id = '".$webr_id."'");
00426 
00427                 return true;
00428         }
00429 
00438         function _isSingular($a_webr_id)
00439         {
00440                 global $ilDB;
00441 
00442                 $res = $ilDB->query("SELECT * FROM webr_items WHERE webr_id = '".$a_webr_id."' AND active = '1'");
00443 
00444                 return $res->numRows() == 1 ? true : false;
00445         }
00446 
00455         function _getFirstLink($a_webr_id)
00456         {
00457                 global $ilDB;
00458 
00459                 $res = $ilDB->query("SELECT * FROM webr_items WHERE webr_id = '".$a_webr_id."' AND active = '1'");
00460                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00461                 {
00462                         $item['title']                          = $row->title;
00463                         $item['description']            = $row->description;
00464                         $item['target']                         = $row->target;
00465                         $item['active']                         = (bool) $row->active;
00466                         $item['disable_check']          = $row->disable_check;
00467                         $item['create_date']            = $row->create_date;
00468                         $item['last_update']            = $row->last_update;
00469                         $item['last_check']                     = $row->last_check;
00470                         $item['valid']                          = $row->valid;
00471                         $item['link_id']                        = $row->link_id;
00472                 }
00473                 return $item ? $item : array();
00474         }
00475 
00476                         
00477                 
00478 
00479 }
00480                 
00481 ?>

Generated on Fri Dec 13 2013 13:52:11 for ILIAS Release_3_7_x_branch .rev 46817 by  doxygen 1.7.1