File modules/cms/model/Alias.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 * Alias. Ein Alias kann auf alle anderen Objekte zeigen. 9 * 10 * @author Jan Dankert 11 */ 12 class Alias extends BaseObject 13 { 14 public $aliasid; 15 public $languageid; 16 public $linkedObjectId; 17 18 public function __construct( $objectid='' ) 19 { 20 $this->isAlias = true; 21 parent::__construct( $objectid ); 22 } 23 24 25 26 /** 27 * Lesen der Verknuepfung aus der Datenbank 28 * @throws \util\exception\ObjectNotFoundException 29 */ 30 public function load() 31 { 32 if ( $this->objectid != null ) 33 { 34 $sql = Db::sql( 'SELECT *'. 35 ' FROM {{alias}}'. 36 ' WHERE objectid={objectid}' ); 37 $sql->setInt( 'objectid',$this->objectid ); 38 } 39 elseif ( $this->linkedObjectId != null && intval($this->languageid) != 0 ) 40 { 41 $sql = Db::sql( 'SELECT *'. 42 ' FROM {{alias}}'. 43 ' WHERE link_objectid={objectid}'. 44 ' AND languageid={languageid}' ); 45 $sql->setInt( 'objectid' ,$this->linkedObjectId ); 46 $sql->setInt( 'languageid',$this->languageid ); 47 } 48 elseif ( $this->linkedObjectId != null ) 49 { 50 $sql = Db::sql( 'SELECT *'. 51 ' FROM {{alias}}'. 52 ' WHERE link_objectid={objectid}'. 53 ' AND languageid IS NULL' ); 54 $sql->setInt( 'objectid' ,$this->linkedObjectId ); 55 } 56 else{ 57 return; 58 } 59 60 $row = $sql->getRow(); 61 62 if ( count($row ) != 0 ) 63 { 64 $this->aliasid = $row['id' ]; 65 $this->objectid = $row['objectid' ]; 66 $this->linkedObjectId = $row['link_objectid']; 67 $this->languageid = $row['languageid' ]; 68 69 $this->objectLoad(); 70 } 71 } 72 73 74 /** 75 * Delete. 76 */ 77 public function delete() 78 { 79 $sql = Db::sql( 'DELETE FROM {{alias}} '. 80 ' WHERE id={aliasid}' ); 81 $sql->setInt( 'aliasid',$this->aliasid ); 82 83 $sql->execute(); 84 85 parent::delete(); 86 } 87 88 89 /** 90 * 91 */ 92 public function save() 93 { 94 $sql = Db::sql('UPDATE {{alias}} SET '. 95 ' link_objectid = {linkobjectid},'. 96 ' languageid = {languageid}'. 97 ' WHERE objectid={objectid}' ); 98 $sql->setInt ('objectid' ,$this->objectid ); 99 $sql->setInt ('linkobjectid',$this->linkedObjectId ); 100 $sql->setIntOrNull('languageid' ,$this->languageid ); 101 102 $sql->execute(); 103 104 parent::save(); 105 } 106 107 108 public function getProperties() 109 { 110 return array_merge( parent::getProperties(), 111 get_object_vars($this) ); 112 } 113 114 115 /** 116 * Add a new link. 117 */ 118 public function add() 119 { 120 parent::add(); 121 122 $stmt = Db::sql('SELECT MAX(id) FROM {{alias}}'); 123 $this->aliasid = intval($stmt->getOne())+1; 124 125 $stmt = Db::sql( <<<SQL 126 INSERT INTO {{alias}} 127 (id,objectid,link_objectid,languageid) 128 VALUES( {linkid},{objectid},{linkobjectid},{languageid} ) 129 SQL 130 ); 131 $stmt->setInt ('linkid' ,$this->aliasid ); 132 $stmt->setInt ('objectid' ,$this->objectid ); 133 134 $stmt->setInt ('linkobjectid',$this->linkedObjectId ); 135 $stmt->setIntOrNull('languageid' ,$this->languageid ); 136 137 $stmt->execute(); 138 } 139 }
Downloadmodules/cms/model/Alias.class.php
History Sun, 7 Mar 2021 00:10:20 +0100 Jan Dankert Refactoring: Hopefully more performance while accessing the database resultsets. 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.