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

Last commit: Thu Mar 10 10:28:14 2022 +0100	dankert	Fix: Fulltext-Search was broken due to the last Content-Refactoring
1 <?php 2 namespace cms\model; 3 use cms\base\Configuration; 4 use cms\base\DB; 5 use cms\base\Startup; 6 use util\ArrayUtils; 7 use cms\generator\Publish; 8 use cms\macros\MacroRunner; 9 use \util\exception\ObjectNotFoundException; 10 use logger\Logger; 11 use util\exception\GeneratorException; 12 use util\Text; 13 use util\Html; 14 use util\Http; 15 use util\Transformer; 16 use util\Code; 17 use util\cache\FileCache; 18 19 // OpenRat Content Management System 20 // Copyright (C) 2002-2012 Jan Dankert, cms@jandankert.de 21 // 22 // This program is free software; you can redistribute it and/or 23 // modify it under the terms of the GNU General Public License 24 // as published by the Free Software Foundation; either version 2 25 // of the License, or (at your option) any later version. 26 // 27 // This program is distributed in the hope that it will be useful, 28 // but WITHOUT ANY WARRANTY; without even the implied warranty of 29 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 30 // GNU General Public License for more details. 31 // 32 // You should have received a copy of the GNU General Public License 33 // along with this program; if not, write to the Free Software 34 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 35 36 37 38 /** 39 * Darstellen einer Inhaltes 40 * 41 * @version $Revision$ 42 * @author $Author$ 43 * @package openrat.objects 44 */ 45 46 class Content extends ModelBase 47 { 48 /** 49 * Content ID. 50 * @type Integer 51 */ 52 private $id; 53 54 /** 55 * Seiten-Objekt der ?bergeordneten Seite 56 * @type Page 57 */ 58 var $page; 59 60 /** 61 * Seiten-Id der uebergeordneten Seite 62 * @type Integer 63 */ 64 var $pageid; 65 66 /** 67 * Objekt-ID, auf die verlinkt wird 68 * @type Integer 69 */ 70 var $linkToObjectId=0; 71 72 /** 73 * Text-Inhalt 74 * @type String 75 */ 76 var $text=''; 77 78 /** 79 * Zahl. Auch Flie?kommazahlen werden als Ganzzahl gespeichert 80 * @type Integer 81 */ 82 var $number=0; 83 84 85 /** 86 * Datum als Unix-Timestamp 87 * @type Integer 88 */ 89 var $date=0; 90 91 /** 92 * Element-Objekt 93 * @type Element 94 */ 95 var $element; 96 97 /** 98 * Element-Id 99 * @type Integer 100 */ 101 var $elementid; 102 103 /** 104 * Der eigentliche Inhalt des Elementes 105 * @type String 106 */ 107 var $value; 108 109 /** 110 * TimeStamp der letzten Aenderung 111 * @type Integer 112 */ 113 var $lastchangeTimeStamp; 114 115 /** 116 * Benutzer-ID der letzten Aenderung 117 * @type Integer 118 */ 119 var $lastchangeUserId; 120 121 /** 122 * Benutzername der letzten Aenderung 123 * @type Integer 124 */ 125 var $lastchangeUserName; 126 127 /** 128 * Active content. 129 * 130 * Do NOT set this attribute, it should be used readonly. 131 * 132 * @type bool 133 */ 134 public $active; 135 136 /** 137 * @type Publish 138 */ 139 public $publisher; 140 141 /** 142 * @type boolean 143 */ 144 var $publish = false; 145 146 /** 147 * @type Boolean 148 * @deprecated 149 */ 150 public $simple; 151 152 153 /** 154 * Sprach-Id. 155 * @var int 156 */ 157 public $languageid; 158 159 /** 160 * Format 161 * 162 * @var int 163 */ 164 public $format = null; 165 166 /** 167 * constructor 168 */ 169 function __construct( $id = null ) 170 { 171 $this->id = $id; 172 } 173 174 175 public function load() 176 { 177 // TODO: Implement load() method. 178 } 179 180 /** 181 * Gets the IDs of all versions of this content. 182 * @return array 183 */ 184 function getVersionList() 185 { 186 $stmt = DB::sql( <<<SQL 187 SELECT {{value}}.id 188 FROM {{value}} 189 WHERE contentid ={contentid} 190 ORDER BY lastchange_date 191 SQL 192 ); 193 $stmt->setInt( 'contentid' ,$this->id ); 194 195 return $stmt->getCol(); 196 } 197 198 199 /** 200 * returns the count of all versions. 201 * @return integer 202 */ 203 function getCountVersions() 204 { 205 $sql = DB::sql( <<<SQL 206 SELECT COUNT(*) FROM {{value}} 207 WHERE contentid ={contentid} 208 SQL 209 ); 210 $sql->setInt( 'contentid' ,$this->id ); 211 212 return $sql->getOne(); 213 } 214 215 216 /** 217 * @return String|null 218 */ 219 public function getLastChangeTime() 220 { 221 $sql = DB::sql( <<<SQL 222 SELECT lastchange_date FROM {{value}} 223 WHERE contentid ={contentid} 224 ORDER BY id DESC 225 SQL 226 ); 227 $sql->setInt( 'contentid' ,$this->id ); 228 229 return $sql->getOne(); 230 } 231 232 233 /** 234 * Gets the last change date by another user since a specific date. 235 * @param $date 236 * @param $userid 237 * @return String 238 */ 239 public function getLastChangeSinceByAnotherUser( $date, $userid ) 240 { 241 $sql = Db::sql( <<<SQL 242 SELECT lastchange_date 243 FROM {{value}} 244 WHERE contentid = {contentid} 245 AND lastchange_date > {date} 246 AND lastchange_userid != {userid} 247 ORDER BY id DESC 248 SQL 249 ); 250 $sql->setInt( 'contentid' ,$this->id ); 251 $sql->setInt( 'date' ,$date ); 252 $sql->setInt( 'userid' ,$userid ); 253 254 return $sql->getOne(); 255 } 256 257 258 259 /** 260 * Inhalt freigeben 261 */ 262 function release() 263 { 264 $sql = DB::sql( <<<SQL 265 UPDATE {{value}} 266 SET publish = 0 267 WHERE contentid = {contentid} 268 SQL 269 ); 270 $sql->setInt( 'contentid' ,$this->id ); 271 272 $sql->execute(); 273 274 $sql = Db::sql( <<<SQL 275 UPDATE {{value}} 276 SET publish = 1 277 WHERE active = 1 278 AND contentid = {contentid} 279 SQL 280 ); 281 $sql->setInt( 'contentid' ,$this->id ); 282 283 $sql->execute(); 284 } 285 286 287 /** 288 * No function, values are NOT updated, values are only added. 289 * @return name|void 290 */ 291 protected function save() 292 { 293 // not implemented, values are only added ("copy on write") 294 } 295 296 297 protected function add() 298 { 299 // Naechste ID aus Datenbank besorgen 300 $stmt = DB::sql('SELECT MAX(id) FROM {{content}}'); 301 $this->id = intval($stmt->getOne())+1; 302 303 $stmt = DB::sql( <<<SQL 304 INSERT INTO {{content}} 305 (id ) 306 VALUES ({contentid}) 307 SQL 308 ); 309 $stmt->setInt( 'contentid' ,$this->id ); 310 $stmt->execute(); 311 } 312 313 314 /** 315 * Delete this content. 316 * 317 * If a object (page, file, ...) is deleted, then all referenced contents must be deleted too. 318 */ 319 public function delete() 320 { 321 // Delete all values 322 $stmt = DB::sql( <<<SQL 323 DELETE FROM {{value}} 324 WHERE contentid = {contentid} 325 SQL 326 ); 327 $stmt->setInt( 'contentid' ,$this->id ); 328 $stmt->execute(); 329 330 // Delete the content 331 $stmt = DB::sql( <<<SQL 332 DELETE FROM {{content}} 333 WHERE id = {contentid} 334 SQL 335 ); 336 $stmt->setInt( 'contentid' ,$this->id ); 337 $stmt->execute(); 338 } 339 340 341 342 /** 343 * Es werden Objekte mit einem Inhalt gesucht. 344 * @param String Suchbegriff 345 * @return array Liste der gefundenen Objekt-IDs 346 */ 347 public static function getObjectIdsByValue( $text ) 348 { 349 $sql = DB::sql( <<<SQL 350 SELECT {{object}}.id FROM {{object}} 351 LEFT JOIN {{page}} 352 ON {{object}}.id={{page}}.objectid 353 LEFT JOIN {{pagecontent}} 354 ON {{page}}.id={{pagecontent}}.pageid 355 LEFT JOIN {{content}} 356 ON {{pagecontent}}.contentid={{content}}.id 357 LEFT JOIN {{value}} 358 ON {{content}}.id={{value}}.contentid 359 WHERE {{value}}.text LIKE {text} 360 ORDER BY {{object}}.lastchange_date DESC 361 SQL 362 ); 363 364 $sql->setString( 'text' ,'%'.$text.'%' ); 365 366 return $sql->getCol(); 367 } 368 369 370 /** 371 * Es werden Objekte mit einer UserId ermittelt 372 * @param Integer Benutzer-Id der letzten ?nderung 373 * @return array Liste der gefundenen Objekt-IDs 374 */ 375 function getObjectIdsByLastChangeUserId( $userid ) 376 { 377 $sql = DB::sql( <<<SQL 378 SELECT {{object}}.id FROM {{value}} 379 LEFT JOIN {{page}} 380 ON {{page}}.id={{value}}.pageid 381 LEFT JOIN {{object}} 382 ON {{object}}.id={{page}}.objectid 383 WHERE {{value}}.lastchange_userid={userid} 384 ORDER BY {{object}}.lastchange_date DESC 385 SQL 386 ); 387 $sql->setInt ( 'userid' ,$userid ); 388 389 return $sql->getCol(); 390 } 391 392 393 394 /** 395 * Es wird das Objekt ermittelt, welches der Benutzer zuletzt ge�ndert hat. 396 * 397 * @return Integer Objekt-Id 398 */ 399 public static function getLastChangedObjectByUserId( $userid ) 400 { 401 $sql = DB::sql( <<<SQL 402 SELECT {{object}}.id 403 FROM {{value}} 404 LEFT JOIN {{page}} 405 ON {{page}}.id={{value}}.pageid 406 LEFT JOIN {{object}} 407 ON {{object}}.id={{page}}.objectid 408 WHERE {{value}}.lastchange_userid={userid} 409 ORDER BY {{value}}.lastchange_date DESC 410 SQL 411 ); 412 $sql->setInt ( 'userid' ,$userid ); 413 return $sql->getOne(); 414 } 415 416 417 /** 418 * Es wird das Objekt ermittelt, welches der Benutzer zuletzt ge�ndert hat. 419 * 420 * @return Integer Objekt-Id 421 */ 422 public static function getLastChangedObjectInProjectByUserId( $projectid, $userid ) 423 { 424 $sql = DB::sql( <<<SQL 425 SELECT {{object}}.id 426 FROM {{value}} 427 LEFT JOIN {{page}} 428 ON {{page}}.id={{value}}.pageid 429 LEFT JOIN {{object}} 430 ON {{object}}.id={{page}}.objectid 431 WHERE {{value}}.lastchange_userid={userid} 432 AND {{object}}.projectid = {projectid} 433 ORDER BY {{value}}.lastchange_date DESC 434 SQL 435 ); 436 $sql->setInt ( 'userid' ,$userid ); 437 $sql->setInt ( 'projectid' ,$projectid ); 438 return $sql->getOne(); 439 } 440 441 442 443 public function getName() 444 { 445 return 'Content#'.$this->id; 446 } 447 448 449 public function __toString() 450 { 451 return "Content: ".print_r($this,true); 452 } 453 454 455 456 public function getId() 457 { 458 return $this->id; 459 } 460 461 462 }
Download modules/cms/model/Content.class.php
History Thu, 10 Mar 2022 10:28:14 +0100 dankert Fix: Fulltext-Search was broken due to the last Content-Refactoring Mon, 6 Dec 2021 22:33:10 +0100 dankert Some fixes for deleting objects. Sun, 5 Dec 2021 20:33:24 +0100 dankert Cleanup: Removed unusable properties from class 'Value' and 'BaseObject'. Tue, 9 Nov 2021 00:35:42 +0100 Jan Dankert Fixes: Reading and writing template sources with the new content table.