File modules/cms/model/Link.class.php

Last commit: Sun Mar 7 00:10:20 2021 +0100	Jan Dankert	Refactoring: Hopefully more performance while accessing the database resultsets.
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
Download modules/cms/model/Link.class.php
History Sun, 7 Mar 2021 00:10:20 +0100 Jan Dankert Refactoring: Hopefully more performance while accessing the database resultsets. Sat, 6 Mar 2021 01:27:59 +0100 Jan Dankert Fix: Adding links was broken. Wed, 18 Nov 2020 01:46:36 +0100 Jan Dankert Refactoring of model classes: New method persist() and some other cleanups. Tue, 29 Sep 2020 22:17:11 +0200 Jan Dankert Refactoring: Do not use global constants. Sat, 26 Sep 2020 02:26:39 +0200 Jan Dankert Refactoring: No global functions any more, the database object is read from the Db class. Sun, 23 Feb 2020 04:01:30 +0100 Jan Dankert Refactoring with Namespaces for the cms modules, part 1: moving.