openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

Link.class.php (2549B)


      1 <?php
      2 namespace cms\model;
      3 
      4 
      5 use cms\base\DB as Db;
      6 
      7 /**
      8  * Darstellen einer Verkn�pfung. Eine Verkn�pfung kann auf eine Objekt oder auf
      9  * eine beliebige Url zeigen
     10  *
     11  * @version $Revision$
     12  * @author $Author$
     13  * @package openrat.objects
     14  */
     15 class Link extends BaseObject
     16 {
     17 	var $linkid;
     18 	var $linkedObjectId = 0;
     19 	var $url            = '';
     20 
     21 	public function __construct( $objectid='' )
     22 	{
     23 		parent::__construct( $objectid );
     24 		$this->isLink = true;
     25 		$this->typeid = BaseObject::TYPEID_LINK;
     26 	}
     27 
     28 
     29 
     30     /**
     31      * Lesen der Verknuepfung aus der Datenbank
     32      * @throws \util\exception\ObjectNotFoundException
     33      */
     34     public function load()
     35 	{
     36 		$db = \cms\base\DB::get();
     37 
     38 		$sql = $db->sql( 'SELECT *'.
     39 		                ' FROM {{link}}'.
     40 		                ' WHERE objectid={objectid}' );
     41 		$sql->setInt( 'objectid',$this->objectid );
     42 		$row = $sql->getRow();
     43 
     44 		if	( count($row ) != 0 )
     45 		{
     46 			$this->linkedObjectId = $row['link_objectid'];
     47 		}
     48 
     49 		$this->objectLoad();
     50 	}
     51 
     52 
     53     /**
     54      *
     55      */
     56     public function delete()
     57 	{
     58 		$db = \cms\base\DB::get();
     59 
     60 		// Verkn�pfung l�schen
     61 		$sql = $db->sql( 'DELETE FROM {{link}} '.
     62 		                ' WHERE objectid={objectid}' );
     63 		$sql->setInt( 'objectid',$this->objectid );
     64 
     65 		$sql->execute();
     66 
     67 		parent::delete();
     68 	}
     69 
     70 
     71     /**
     72      *
     73      */
     74     public function save()
     75 	{
     76 		$db = DB::get();
     77 		
     78 		$sql = $db->sql( <<<SQL
     79  		UPDATE {{link}}
     80  		   SET link_objectid = {linkobjectid}
     81 		 WHERE objectid={objectid}
     82 SQL
     83 );
     84 		$sql->setInt   ('objectid'    ,$this->objectid );
     85 
     86 		if ( ! $this->linkedObjectId )
     87 			$sql->setNull('linkobjectid');
     88 		else
     89 			$sql->setInt ('linkobjectid',$this->linkedObjectId );
     90 
     91 		$sql->execute();
     92 
     93 		parent::save();
     94 	}
     95 
     96 
     97 	public function getProperties()
     98 	{
     99 		return array_merge( parent::getProperties(),
    100 		                    array( 'objectid'       =>$this->objectid,
    101 		                           'linkobjectid'   =>$this->linkedObjectId
    102                             ));
    103 	}
    104 
    105 
    106 	public function getType()
    107 	{
    108 		return 'link';
    109 	}
    110 
    111 
    112     /**
    113      * Add a new link.
    114      */
    115     public function add()
    116 	{
    117 		parent::add();
    118 
    119 		$stmt = Db::sql('SELECT MAX(id) FROM {{link}}');
    120 		$this->linkid = intval($stmt->getOne())+1;
    121 
    122 		$stmt = Db::sql('INSERT INTO {{link}}'.
    123 		               ' (id,objectid,link_objectid)'.
    124 		               ' VALUES( {linkid},{objectid},{linkobjectid} )' );
    125 		$stmt->setInt   ('linkid'      ,$this->linkid         );
    126 		$stmt->setInt   ('objectid'    ,$this->objectid       );
    127         $stmt->setNull  ('linkobjectid');
    128 
    129 		$stmt->execute();
    130 	}	
    131 }
    132