Link.class.php

gehe zur Dokumentation dieser Datei
00001 <?php
00002 // ---------------------------------------------------------------------------
00003 // $Id$
00004 // ---------------------------------------------------------------------------
00005 // OpenRat Content Management System
00006 // Copyright (C) 2002-2004 Jan Dankert, jandankert@jandankert.de
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 // $Log$
00023 // Revision 1.2  2004-05-02 14:41:31  dankert
00024 // Einfügen package-name (@package)
00025 //
00026 // Revision 1.1  2004/04/24 15:15:12  dankert
00027 // Initiale Version
00028 //
00029 // Revision 1.1  2003/10/27 23:21:55  dankert
00030 // Methode(n) hinzugefügt: savevalue(), save()
00031 //
00032 // ---------------------------------------------------------------------------
00033 
00042 class Link extends Object
00043 {
00044      var $linkid;
00045      var $linkedObjectId = 0;
00046      var $url            = '';
00047      var $isLinkToUrl    = false;
00048      var $isLinkToObject = false;
00049 
00050      function Link( $objectid='' )
00051      {
00052           $this->Object( $objectid );
00053           $this->isLink = true;
00054           $this->isLinkToObject = false;
00055      }
00056      
00057 
00058      // Lesen der Verknüpfung aus der Datenbank
00059      function load()
00060      {
00061           $db = db_connection();
00062 
00063           $sql = new Sql( 'SELECT *'.
00064                           ' FROM {t_link}'.
00065                           ' WHERE objectid={objectid}' );
00066           $sql->setInt( 'objectid',$this->objectid );
00067           $row = $db->getRow( $sql->query );
00068 
00069           $this->url            = $row['url'];
00070           $this->linkedObjectId = $row['link_objectid'];
00071           
00072           if   ( is_numeric( $this->linkedObjectId ) )
00073           {
00074                $this->isLinkToUrl    = false;
00075                $this->isLinkToObject = true;
00076           }
00077           else
00078           {
00079                $this->isLinkToUrl    = true;
00080                $this->isLinkToObject = false;
00081           }
00082           
00083           $this->objectLoad();
00084      }
00085 
00086 
00087 
00088      function delete()
00089      {
00090           $db = db_connection();
00091 
00092           // Verknüpfung löschen
00093           $sql = new Sql( 'DELETE FROM {t_link} '.
00094                           ' WHERE objectid={objectid}' );
00095           $sql->setInt( 'objectid',$this->objectid );
00096           
00097           $db->query( $sql->query );
00098 
00099           $this->objectDelete();
00100      }
00101 
00102 
00103 
00104      function save()
00105      {
00106           global $SESS;
00107           $db = db_connection();
00108           
00109           $sql = new Sql('UPDATE {t_link} SET '.
00110                          '  url           = {url},'.
00111                          '  link_objectid = {linkobjectid}'.
00112                           ' WHERE objectid={objectid}' );
00113           $sql->setInt   ('objectid'    ,$this->objectid );
00114           
00115           if   ( $this->isLinkToObject )
00116           {
00117                $sql->setInt ('linkobjectid',$this->linkedObjectId );
00118                $sql->setNull('url' );
00119           }
00120           else
00121           {
00122                $sql->setNull  ('linkobjectid');
00123                $sql->setString('url',$this->url );
00124           }
00125           
00126           $db->query( $sql->query );
00127 
00128           $this->objectSave();
00129      }
00130 
00131 
00132      function getProperties()
00133      {
00134           return array_merge( parent::getProperties(),
00135                               Array( 'objectid'       =>$this->objectid,
00136                                      'linkobjectid'   =>$this->linkedObjectId,
00137                                      'url'            =>$this->url,
00138                                      'isLinkToUrl'    =>$this->isLinkToUrl,
00139                                      'isLinkToObject' =>$this->isLinkToObject) );
00140      }
00141 
00142 
00143      function getType()
00144      {
00145           if   ( $this->isLinkToObject )
00146                return 'link';
00147           else return 'url';
00148      }
00149 
00150 
00151      function add()
00152      {
00153           $this->objectAdd();
00154 
00155           $db = db_connection();
00156 
00157           $sql = new Sql('SELECT MAX(id) FROM {t_link}');
00158           $this->linkid = intval($db->getOne($sql->query))+1;
00159 
00160           $sql = new Sql('INSERT INTO {t_link}'.
00161                          ' (id,objectid,url,link_objectid)'.
00162                          ' VALUES( {linkid},{objectid},{url},{linkobjectid} )' );
00163           $sql->setInt   ('linkid'      ,$this->linkid         );
00164           $sql->setInt   ('objectid'    ,$this->objectid       );
00165 
00166           if   ( $this->isLinkToObject )
00167           {
00168                $sql->setInt ('linkobjectid',$this->linkedObjectId );
00169                $sql->setNull('url' );
00170           }
00171           else
00172           {
00173                $sql->setNull  ('linkobjectid');
00174                $sql->setString('url',$this->url );
00175           }
00176           
00177           $db->query( $sql->query );
00178      }    
00179 }
00180 
00181 ?>

Erzeugt am Thu May 14 00:55:48 2009 für OpenRat von  doxygen 1.5.8