commit e35db8839734018f7e098e5e715e7ef1a70d6902
parent 0ecbd81c039ad6c2b760dcbad9c1c14e3c175ba7
Author: Jan Dankert <devnull@localhost>
Date: Wed, 14 Nov 2018 22:22:05 +0100
Den Template-Inhalt über die neue Klasse TemplateModel abbilden, damit das nicht alles in der Templateklasse vermatscht ist.
Diffstat:
5 files changed, 191 insertions(+), 19 deletions(-)
diff --git a/modules/cms-core/action/TemplateAction.class.php b/modules/cms-core/action/TemplateAction.class.php
@@ -43,6 +43,10 @@ class TemplateAction extends Action
public $security = SECURITY_USER;
var $defaultSubAction = 'show';
+
+ /**
+ * @var Template
+ */
var $template;
var $element;
diff --git a/modules/cms-core/model/Page.class.php b/modules/cms-core/model/Page.class.php
@@ -62,7 +62,10 @@ class Page extends BaseObject
var $log_filenames = array();
var $modelid = 0;
-
+
+ /**
+ * @var \Publish
+ */
var $publish = null;
var $up_path = '';
diff --git a/modules/cms-core/model/Template.class.php b/modules/cms-core/model/Template.class.php
@@ -47,18 +47,21 @@ class Template
/**
* ID der Projektvariante
+ * @deprecated Zugriff über TemplateModel
* @type Integer
*/
var $modelid = 0;
/**
* Dateierweiterung dieses Templates (abh?ngig von der Projektvariante)
+ * @deprecated Zugriff über TemplateModel
* @type String
*/
var $extension='';
/**
* Inhalt des Templates (abh?ngig von der Projektvariante)
+ * @deprecated Zugriff über TemplateModel
* @type String
*/
var $src='';
@@ -89,24 +92,11 @@ class Template
$this->name = $row['name' ];
$this->projectid = $row['projectid'];
- $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();
+ $templateModel = new TemplateModel( $this->templateid, $this->modelid );
+ $templateModel->load();
- if ( isset($row['extension']) )
- {
- $this->extension = $row['extension'];
- $this->src = $row['text'];
- }
- else
- {
- $this->extension = null;
- $this->src = null;
- }
-
+ $this->extension = $templateModel->extension;
+ $this->src = $templateModel->src;
}
@@ -268,7 +258,7 @@ SQL
* Es wird eine Liste mit den Element-Namen zur?ckgegeben
* @return Array
*/
- function getElementNames()
+ public function getElementNames()
{
$db = db_connection();
diff --git a/modules/cms-core/model/TemplateModel.class.php b/modules/cms-core/model/TemplateModel.class.php
@@ -0,0 +1,174 @@
+<?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();
+ }
+
+
+ /**
+ * 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/require.php b/modules/cms-core/model/require.php
@@ -6,6 +6,7 @@ require_once( __DIR__.'/ModelBase.class.php' );
require_once( __DIR__.'/Value.class.php' );
require_once( __DIR__.'/Acl.class.php' );
require_once( __DIR__.'/Template.class.php' );
+require_once( __DIR__.'/TemplateModel.class.php' );
require_once(__DIR__ . '/BaseObject.class.php');
require_once( __DIR__.'/Folder.class.php' );
require_once( __DIR__.'/Link.class.php' );