openrat-cms

# OpenRat Content Management System
git clone http://git.code.weiherhei.de/openrat-cms.git
Log | Files | Refs

commit 3946fd0f297c260653f16150f7e607318f403638
parent 3f1894f51547aa2b3739e80a722093b17901b0f0
Author: Jan Dankert <develop@jandankert.de>
Date:   Sat,  9 Nov 2019 01:20:03 +0100

Refactoring: New base class for all model classes.

Diffstat:
modules/cms-core/model/Acl.class.php | 2+-
modules/cms-core/model/BaseObject.class.php | 2+-
modules/cms-core/model/Element.class.php | 2+-
modules/cms-core/model/Group.class.php | 2+-
modules/cms-core/model/Language.class.php | 2+-
modules/cms-core/model/Model.class.php | 432++++++++++++++++++++++++++++++++++++++++----------------------------------------
modules/cms-core/model/ModelBase.class.php | 2++
modules/cms-core/model/Name.class.php | 2+-
modules/cms-core/model/Template.class.php | 2+-
modules/cms-core/model/TemplateModel.class.php | 352++++++++++++++++++++++++++++++++++++++++----------------------------------------
modules/cms-core/model/Value.class.php | 2+-
11 files changed, 402 insertions(+), 400 deletions(-)

diff --git a/modules/cms-core/model/Acl.class.php b/modules/cms-core/model/Acl.class.php @@ -39,7 +39,7 @@ namespace cms\model; * * @author Jan Dankert */ -class Acl +class Acl extends ModelBase { // Definition der Berechtigungs-Flags const ACL_READ = 1; diff --git a/modules/cms-core/model/BaseObject.class.php b/modules/cms-core/model/BaseObject.class.php @@ -16,7 +16,7 @@ use template_engine\components\ElseComponent; * * @author Jan Dankert */ -class BaseObject +class BaseObject extends ModelBase { const TYPEID_FOLDER = 1; const TYPEID_FILE = 2; diff --git a/modules/cms-core/model/Element.class.php b/modules/cms-core/model/Element.class.php @@ -11,7 +11,7 @@ namespace cms\model; * @author Jan Dankert * @package openrat.objects */ -class Element +class Element extends ModelBase { const ELEMENT_TYPE_DATE = 1; const ELEMENT_TYPE_NUMBER = 2; diff --git a/modules/cms-core/model/Group.class.php b/modules/cms-core/model/Group.class.php @@ -26,7 +26,7 @@ namespace cms\model; * @author $Author$ * @package openrat.objects */ -class Group +class Group extends ModelBase { var $groupid = 0; var $error = ''; diff --git a/modules/cms-core/model/Language.class.php b/modules/cms-core/model/Language.class.php @@ -25,7 +25,7 @@ namespace cms\model; * @author $Author$ * @package openrat.objects */ -class Language +class Language extends ModelBase { public $languageid; public $projectid; diff --git a/modules/cms-core/model/Model.class.php b/modules/cms-core/model/Model.class.php @@ -1,217 +1,217 @@ -<?php -namespace cms\model; -// OpenRat Content Management System -// Copyright (C) 2002-2012 Jan Dankert, cms@jandankert.de -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - - -/** - * Diese Klasse stellt ein Projektmodell dar. Ein Projektmodell ist eine Darstellungsart - * der Inhalte. Zu jedem Projektmodell gibt es einen anderen Templatequelltext. - * Beispiel: Neben HTML gibt es ein Projektmodell fuer WML oder XML. Die Inhalte sind gleich, - * aber die Art der Ausgabe ist jeweils anders. - * - * @package openrat.objects - * @author $Author$ - * @version $Rev: $ - */ -class Model -{ - var $modelid = 0; - var $error = ''; - var $projectid; - - var $name = ''; - var $isDefault = false; - - - /** - * Konstruktor - */ - function __construct( $modelid='' ) - { - if ( is_numeric($modelid) ) - $this->modelid = $modelid; - } - - - /** - * Stellt fest, ob die angegebene Id existiert. - */ - function available( $id ) - { - $db = db_connection(); - - $sql = $db->sql('SELECT 1 FROM {{projectmodel}} '. - ' WHERE id={id}'); - $sql->setInt('id' ,$id ); - - return intval($sql->getOne()) == 1; - } - - - - - /** - * Lesen aus der Datenbank - */ - function load() - { - $db = db_connection(); - - $sql = $db->sql( 'SELECT * FROM {{projectmodel}}'. - ' WHERE id={modelid}' ); - $sql->setInt( 'modelid',$this->modelid ); - - $row = $sql->getRow(); - - $this->name = $row['name' ]; - $this->projectid = $row['projectid']; - - if ( $row['is_default'] == '1' ) - $this->isDefault = true; - else $this->isDefault = false; - } - - - /** - * Speichern des Projektmodells - */ - function save() - { - $db = db_connection(); - - // Gruppe speichern - $sql = $db->sql( 'UPDATE {{projectmodel}} '. - ' SET name = {name} '. - ' WHERE id={modelid}' ); - $sql->setString( 'name' ,$this->name ); - - $sql->setInt( 'modelid',$this->modelid ); - - // Datenbankabfrage ausfuehren - $sql->query(); - } - - - /** - * Alle notwendigen Eigenschaften dieses Projektmodells - * werden als Array zurueckgegeben - * - * @return Array - */ - function getProperties() - { - return Array( 'modelid' =>$this->modelid, - 'projectid'=>$this->projectid, - 'isDefault'=>$this->isDefault, - 'name' =>$this->name ); - } - - - /** - * Modell hinzufuegen - * @param String Name des Modells (optional) - */ - function add( $name = '' ) - { - if ( $name != '' ) - $this->name = $name; - - $db = db_connection(); - - $sql = $db->sql('SELECT MAX(id) FROM {{projectmodel}}'); - $this->modelid = intval($sql->getOne())+1; - - // Modell hinzuf?gen - $sql = $db->sql( 'INSERT INTO {{projectmodel}} '. - "(id,projectid,name,extension,is_default) VALUES( {modelid},{projectid},{name},'',0 )"); - - $sql->setInt ('modelid' ,$this->modelid ); - $sql->setInt ('projectid',$this->projectid ); - $sql->setString('name' ,$this->name ); - - // Datenbankbefehl ausfuehren - $sql->query(); - } - - - - // Diese Sprache als 'default' markieren. - function setDefault() - { - global $SESS; - $db = db_connection(); - - // Zuerst alle auf nicht-Standard setzen - $sql = $db->sql( 'UPDATE {{projectmodel}} '. - ' SET is_default = 0 '. - ' WHERE projectid={projectid}' ); - $sql->setInt('projectid',$this->projectid ); - $sql->query(); - - // Jetzt die gew?nschte Sprachvariante auf Standard setzen - $sql = $db->sql( 'UPDATE {{projectmodel}} '. - ' SET is_default = 1 '. - ' WHERE id={modelid}' ); - $sql->setInt('modelid',$this->modelid ); - $sql->query(); - } - - - /** - * Entfernen des Projektmodells aus der Datenbank - * Es wird dabei nicht geprueft, ob noch ein anders Projektmodell - * vorhanden ist. - */ - function delete() - { - $db = db_connection(); - - // Vorlagen zu dieseem Modell loeschen - $sql = $db->sql( <<<SQL - DELETE FROM {{templatemodel}} - WHERE projectmodelid = {modelid} -SQL -); - $sql->setInt( 'modelid',$this->modelid ); - $sql->query(); - - // Dieses Modell löschen - $sql = $db->sql( <<<SQL - DELETE FROM {{projectmodel}} - WHERE id={modelid} -SQL -); - $sql->setInt( 'modelid',$this->modelid ); - $sql->query(); - - // Anderes Modell auf "Default" setzen (sofern vorhanden) - if ( $this->isDefault ) - { - $sql = $db->sql( 'SELECT id FROM {{projectmodel}} WHERE projectid={projectid}' ); - $sql->setInt( 'projectid',$this->projectid ); - $new_default_modelid = $sql->getOne(); - - $sql = $db->sql( 'UPDATE {{projectmodel}} SET is_default=1 WHERE id={modelid}' ); - $sql->setInt( 'modelid',$new_default_modelid ); - $sql->query(); - } - } -} - +<?php +namespace cms\model; +// OpenRat Content Management System +// Copyright (C) 2002-2012 Jan Dankert, cms@jandankert.de +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + + +/** + * Diese Klasse stellt ein Projektmodell dar. Ein Projektmodell ist eine Darstellungsart + * der Inhalte. Zu jedem Projektmodell gibt es einen anderen Templatequelltext. + * Beispiel: Neben HTML gibt es ein Projektmodell fuer WML oder XML. Die Inhalte sind gleich, + * aber die Art der Ausgabe ist jeweils anders. + * + * @package openrat.objects + * @author $Author$ + * @version $Rev: $ + */ +class Model extends ModelBase +{ + var $modelid = 0; + var $error = ''; + var $projectid; + + var $name = ''; + var $isDefault = false; + + + /** + * Konstruktor + */ + function __construct( $modelid='' ) + { + if ( is_numeric($modelid) ) + $this->modelid = $modelid; + } + + + /** + * Stellt fest, ob die angegebene Id existiert. + */ + function available( $id ) + { + $db = db_connection(); + + $sql = $db->sql('SELECT 1 FROM {{projectmodel}} '. + ' WHERE id={id}'); + $sql->setInt('id' ,$id ); + + return intval($sql->getOne()) == 1; + } + + + + + /** + * Lesen aus der Datenbank + */ + function load() + { + $db = db_connection(); + + $sql = $db->sql( 'SELECT * FROM {{projectmodel}}'. + ' WHERE id={modelid}' ); + $sql->setInt( 'modelid',$this->modelid ); + + $row = $sql->getRow(); + + $this->name = $row['name' ]; + $this->projectid = $row['projectid']; + + if ( $row['is_default'] == '1' ) + $this->isDefault = true; + else $this->isDefault = false; + } + + + /** + * Speichern des Projektmodells + */ + function save() + { + $db = db_connection(); + + // Gruppe speichern + $sql = $db->sql( 'UPDATE {{projectmodel}} '. + ' SET name = {name} '. + ' WHERE id={modelid}' ); + $sql->setString( 'name' ,$this->name ); + + $sql->setInt( 'modelid',$this->modelid ); + + // Datenbankabfrage ausfuehren + $sql->query(); + } + + + /** + * Alle notwendigen Eigenschaften dieses Projektmodells + * werden als Array zurueckgegeben + * + * @return Array + */ + function getProperties() + { + return Array( 'modelid' =>$this->modelid, + 'projectid'=>$this->projectid, + 'isDefault'=>$this->isDefault, + 'name' =>$this->name ); + } + + + /** + * Modell hinzufuegen + * @param String Name des Modells (optional) + */ + function add( $name = '' ) + { + if ( $name != '' ) + $this->name = $name; + + $db = db_connection(); + + $sql = $db->sql('SELECT MAX(id) FROM {{projectmodel}}'); + $this->modelid = intval($sql->getOne())+1; + + // Modell hinzuf?gen + $sql = $db->sql( 'INSERT INTO {{projectmodel}} '. + "(id,projectid,name,extension,is_default) VALUES( {modelid},{projectid},{name},'',0 )"); + + $sql->setInt ('modelid' ,$this->modelid ); + $sql->setInt ('projectid',$this->projectid ); + $sql->setString('name' ,$this->name ); + + // Datenbankbefehl ausfuehren + $sql->query(); + } + + + + // Diese Sprache als 'default' markieren. + function setDefault() + { + global $SESS; + $db = db_connection(); + + // Zuerst alle auf nicht-Standard setzen + $sql = $db->sql( 'UPDATE {{projectmodel}} '. + ' SET is_default = 0 '. + ' WHERE projectid={projectid}' ); + $sql->setInt('projectid',$this->projectid ); + $sql->query(); + + // Jetzt die gew?nschte Sprachvariante auf Standard setzen + $sql = $db->sql( 'UPDATE {{projectmodel}} '. + ' SET is_default = 1 '. + ' WHERE id={modelid}' ); + $sql->setInt('modelid',$this->modelid ); + $sql->query(); + } + + + /** + * Entfernen des Projektmodells aus der Datenbank + * Es wird dabei nicht geprueft, ob noch ein anders Projektmodell + * vorhanden ist. + */ + function delete() + { + $db = db_connection(); + + // Vorlagen zu dieseem Modell loeschen + $sql = $db->sql( <<<SQL + DELETE FROM {{templatemodel}} + WHERE projectmodelid = {modelid} +SQL +); + $sql->setInt( 'modelid',$this->modelid ); + $sql->query(); + + // Dieses Modell löschen + $sql = $db->sql( <<<SQL + DELETE FROM {{projectmodel}} + WHERE id={modelid} +SQL +); + $sql->setInt( 'modelid',$this->modelid ); + $sql->query(); + + // Anderes Modell auf "Default" setzen (sofern vorhanden) + if ( $this->isDefault ) + { + $sql = $db->sql( 'SELECT id FROM {{projectmodel}} WHERE projectid={projectid}' ); + $sql->setInt( 'projectid',$this->projectid ); + $new_default_modelid = $sql->getOne(); + + $sql = $db->sql( 'UPDATE {{projectmodel}} SET is_default=1 WHERE id={modelid}' ); + $sql->setInt( 'modelid',$new_default_modelid ); + $sql->query(); + } + } +} + ?> \ No newline at end of file diff --git a/modules/cms-core/model/ModelBase.class.php b/modules/cms-core/model/ModelBase.class.php @@ -3,10 +3,12 @@ namespace cms\model; class ModelBase { + /* protected function setDatabaseRow( $row ) { } + */ /** diff --git a/modules/cms-core/model/Name.class.php b/modules/cms-core/model/Name.class.php @@ -9,7 +9,7 @@ namespace cms\model { * @author Jan Dankert * @package openrat.objects */ - class Name + class Name extends ModelBase { /** eindeutige ID dieses Objektes * @type Integer diff --git a/modules/cms-core/model/Template.class.php b/modules/cms-core/model/Template.class.php @@ -25,7 +25,7 @@ namespace cms\model; * @version: $Revision$ * @package openrat.objects */ -class Template +class Template extends ModelBase { /** * ID dieses Templates diff --git a/modules/cms-core/model/TemplateModel.class.php b/modules/cms-core/model/TemplateModel.class.php @@ -1,176 +1,176 @@ -<?php -namespace cms\model; - - -/** - * Templatemodell. Enthält den Template-Sourcecode und die Extension. - * - * @author: Jan Dankert - */ -class TemplateModel -{ - /** - * Primary Key. - * @var - */ - public $templatemodelid; - - - /** - * Dateierweiterung dieses Templates (abh?ngig von der Projektvariante) - * @type String - */ - public $extension=''; - - /** - * Inhalt des Templates (abh?ngig von der Projektvariante) - * @type String - */ - public $src =''; - - public $modelid; - public $templateid; - - - /** - * TemplateModel constructor. - * @param $templateid - * @param $modelid - */ - function __construct( $templateid,$modelid ) - { - $this->templateid = $templateid; - $this->modelid = $modelid; - } - - - /** - * Laden des Templatemodells aus der Datenbank und füllen der Objekteigenschaften. - */ - function load() - { - $db = db_connection(); - - $stmt = $db->sql( 'SELECT * FROM {{templatemodel}}'. - ' WHERE templateid={templateid}'. - ' AND projectmodelid={modelid}' ); - $stmt->setInt( 'templateid',$this->templateid ); - $stmt->setInt( 'modelid' ,$this->modelid ); - $row = $stmt->getRow(); - - if ( isset($row['id']) ) - { - $this->templatemodelid = $row['id']; - $this->extension = $row['extension']; - $this->src = $row['text']; - } - else - { - $this->extension = null; - $this->src = null; - } - } - - - - public function isPersistent() - { - return intval( $this->templatemodelid ) > 0; - } - - - - /** - * Abspeichern des Templates in der Datenbank - */ - function save() - { - $db = db_connection(); - - // Vorlagen-Quelltext existiert für diese Varianten schon. - $stmt = $db->sql( 'UPDATE {{templatemodel}}'. - ' SET extension={extension},'. - ' text={src} '. - ' WHERE id={id}' ); - - $stmt->setInt ( 'id' ,$this->templatemodelid ); - - $stmt->setString( 'extension' ,$this->extension ); - $stmt->setString( 'src' ,$this->src ); - - $stmt->query(); - } - - - /** - * Abspeichern des Templates in der Datenbank - */ - function add() - { - $db = db_connection(); - - // Vorlagen-Quelltext wird neu angelegt. - $stmt = $db->sql('SELECT MAX(id) FROM {{templatemodel}}'); - $nextid = intval($stmt->getOne())+1; - - $stmt = $db->sql( 'INSERT INTO {{templatemodel}}'. - ' (id,templateid,projectmodelid,extension,text) '. - ' VALUES ({id},{templateid},{modelid},{extension},{src}) '); - $stmt->setInt ( 'id',$nextid ); - - $stmt->setString( 'extension' ,$this->extension ); - $stmt->setString( 'src' ,$this->src ); - $stmt->setInt ( 'templateid' ,$this->templateid ); - $stmt->setInt ( 'modelid' ,$this->modelid ); - - $stmt->query(); - - $this->templatemodelid = $nextid; - } - - - /** - * Loeschen des Templates - * - * Entfernen alle Templateinhalte und des Templates selber - */ - public function delete() - { - $db = db_connection(); - - $stmt = $db->sql( 'DELETE FROM {{templatemodel}}'. - ' WHERE id={id}' ); - $stmt->setInt( 'id',$this->templatemodelid ); - $stmt->query(); - } - - - /** - * Ermittelt den Mime-Type zu diesem Templatemodell. - * - * Es wird die Extension des Templates betrachtet und dann mit Hilfe der - * Konfigurationsdatei 'mime-types.ini' der Mime-Type bestimmt. - * - * @return String Mime-Type - */ - public function mimeType() - { - global $conf; - $mime_types = $conf['mime-types']; - - // Nur den letzten Teil der Extension auswerten: - // Aus 'mobile.html' wird nur 'html' verwendet. - $parts = explode('.',$this->extension); - $extension = strtolower(array_pop($parts)); - - if ( !empty($mime_types[$extension]) ) - $this->mime_type = $mime_types[$extension]; - else - // Wenn kein Mime-Type gefunden, dann Standardwert setzen - $this->mime_type = 'application/octet-stream'; - - return( $this->mime_type ); - } - -} - +<?php +namespace cms\model; + + +/** + * Templatemodell. Enthält den Template-Sourcecode und die Extension. + * + * @author: Jan Dankert + */ +class TemplateModel extends ModelBase +{ + /** + * Primary Key. + * @var + */ + public $templatemodelid; + + + /** + * Dateierweiterung dieses Templates (abh?ngig von der Projektvariante) + * @type String + */ + public $extension=''; + + /** + * Inhalt des Templates (abh?ngig von der Projektvariante) + * @type String + */ + public $src =''; + + public $modelid; + public $templateid; + + + /** + * TemplateModel constructor. + * @param $templateid + * @param $modelid + */ + function __construct( $templateid,$modelid ) + { + $this->templateid = $templateid; + $this->modelid = $modelid; + } + + + /** + * Laden des Templatemodells aus der Datenbank und füllen der Objekteigenschaften. + */ + function load() + { + $db = db_connection(); + + $stmt = $db->sql( 'SELECT * FROM {{templatemodel}}'. + ' WHERE templateid={templateid}'. + ' AND projectmodelid={modelid}' ); + $stmt->setInt( 'templateid',$this->templateid ); + $stmt->setInt( 'modelid' ,$this->modelid ); + $row = $stmt->getRow(); + + if ( isset($row['id']) ) + { + $this->templatemodelid = $row['id']; + $this->extension = $row['extension']; + $this->src = $row['text']; + } + else + { + $this->extension = null; + $this->src = null; + } + } + + + + public function isPersistent() + { + return intval( $this->templatemodelid ) > 0; + } + + + + /** + * Abspeichern des Templates in der Datenbank + */ + function save() + { + $db = db_connection(); + + // Vorlagen-Quelltext existiert für diese Varianten schon. + $stmt = $db->sql( 'UPDATE {{templatemodel}}'. + ' SET extension={extension},'. + ' text={src} '. + ' WHERE id={id}' ); + + $stmt->setInt ( 'id' ,$this->templatemodelid ); + + $stmt->setString( 'extension' ,$this->extension ); + $stmt->setString( 'src' ,$this->src ); + + $stmt->query(); + } + + + /** + * Abspeichern des Templates in der Datenbank + */ + function add() + { + $db = db_connection(); + + // Vorlagen-Quelltext wird neu angelegt. + $stmt = $db->sql('SELECT MAX(id) FROM {{templatemodel}}'); + $nextid = intval($stmt->getOne())+1; + + $stmt = $db->sql( 'INSERT INTO {{templatemodel}}'. + ' (id,templateid,projectmodelid,extension,text) '. + ' VALUES ({id},{templateid},{modelid},{extension},{src}) '); + $stmt->setInt ( 'id',$nextid ); + + $stmt->setString( 'extension' ,$this->extension ); + $stmt->setString( 'src' ,$this->src ); + $stmt->setInt ( 'templateid' ,$this->templateid ); + $stmt->setInt ( 'modelid' ,$this->modelid ); + + $stmt->query(); + + $this->templatemodelid = $nextid; + } + + + /** + * Loeschen des Templates + * + * Entfernen alle Templateinhalte und des Templates selber + */ + public function delete() + { + $db = db_connection(); + + $stmt = $db->sql( 'DELETE FROM {{templatemodel}}'. + ' WHERE id={id}' ); + $stmt->setInt( 'id',$this->templatemodelid ); + $stmt->query(); + } + + + /** + * Ermittelt den Mime-Type zu diesem Templatemodell. + * + * Es wird die Extension des Templates betrachtet und dann mit Hilfe der + * Konfigurationsdatei 'mime-types.ini' der Mime-Type bestimmt. + * + * @return String Mime-Type + */ + public function mimeType() + { + global $conf; + $mime_types = $conf['mime-types']; + + // Nur den letzten Teil der Extension auswerten: + // Aus 'mobile.html' wird nur 'html' verwendet. + $parts = explode('.',$this->extension); + $extension = strtolower(array_pop($parts)); + + if ( !empty($mime_types[$extension]) ) + $this->mime_type = $mime_types[$extension]; + else + // Wenn kein Mime-Type gefunden, dann Standardwert setzen + $this->mime_type = 'application/octet-stream'; + + return( $this->mime_type ); + } + +} + diff --git a/modules/cms-core/model/Value.class.php b/modules/cms-core/model/Value.class.php @@ -37,7 +37,7 @@ use util\FileCache; * @package openrat.objects */ -class Value +class Value extends ModelBase { /** * ID dieser Inhaltes