commit 2e02cf1c5c9b70bf498d06e4b3bbeebfcf615d73
parent 3946fd0f297c260653f16150f7e607318f403638
Author: Jan Dankert <develop@jandankert.de>
Date: Sat, 9 Nov 2019 01:59:47 +0100
Refactoring: All model classes must implement #getName()
Diffstat:
15 files changed, 157 insertions(+), 54 deletions(-)
diff --git a/modules/cms-core/ModelFactory.class.php b/modules/cms-core/ModelFactory.class.php
@@ -0,0 +1,26 @@
+<?php
+
+namespace cms\model;
+
+class ModelFactory
+{
+ /**
+ * @param $type
+ * @param $id
+ * @return ModelBase
+ */
+ public static function create($type, $id) {
+
+ // 'aBc' => 'Abc'
+ $className = ucfirst(strtolower($type));
+
+ $filename = __DIR__.'/model/'.$className.'.class.php';
+ if ( is_file($filename))
+ require_once ($filename);
+ else
+ return null;
+
+ $nsClassName = '\cms\model\\'.$className;
+ return new $nsClassName( $id );
+ }
+}+
\ No newline at end of file
diff --git a/modules/cms-core/action/TreeAction.class.php b/modules/cms-core/action/TreeAction.class.php
@@ -6,6 +6,7 @@ use cms\model\BaseObject;
use cms\model\Element;
use cms\model\Folder;
use cms\model\Group;
+use cms\model\ModelFactory;
use cms\model\Page;
use cms\model\Project;
use cms\model\Template;
@@ -125,61 +126,18 @@ class TreeAction extends BaseAction
$type = $this->getRequestVar('type');
$id = $this->getRequestVar('id',OR_FILTER_ALPHANUM);
- $name = '';
- switch( $type) {
- case 'user':
- $user = new User($id);
- $user->load();
- $name = $user->name;
- break;
- case 'group':
- $group = new Group($id);
- $group->load();
- $name = $group->name;
- break;
- case 'project':
- $p = new Project($id);
- $p->load();
- $name = $p->name;
- break;
- case 'element':
- $e = new Element($id);
- $e->load();
- $name = $e->label;
- break;
- case 'template':
- $t = new Template($id);
- $t->load();
- $name = $t->name;
- break;
- case 'folder':
- case 'file':
- case 'link':
- case 'url':
- case 'text':
- case 'image':
- case 'page':
- $o = new BaseObject($id);
- $o->load();
- $name = $o->filename;
- break;
- case 'pageelement':
- $ids = explode('_',$this->getRequestVar('id',OR_FILTER_ALPHANUM));
- if ( count($ids) > 1 )
- {
- list( $pageid, $elementid ) = $ids;
- }
- $e = new Element($elementid);
- $e->load();
- $name = $e->label;
-
- default:
- }
-
$result = $this->calculatePath( $type, $id );
$this->setTemplateVar('path' ,$result );
+ $name = '';
+ $o = ModelFactory::create($type,$id);
+
+ if ( $o ) {
+ $o->load();
+ $name = $o->getName();
+ }
+
$this->setTemplateVar('actual',$this->pathItem($type,$id,$name) );
}
diff --git a/modules/cms-core/model/Acl.class.php b/modules/cms-core/model/Acl.class.php
@@ -520,4 +520,9 @@ SQL
}
+ public function getName()
+ {
+ return '';
+ }
+
}
\ No newline at end of file
diff --git a/modules/cms-core/model/Element.class.php b/modules/cms-core/model/Element.class.php
@@ -578,6 +578,12 @@ SQL
return Element::getAvailableTypes()[ $this->typeid ]; // name of type
}
+
+ public function getName()
+ {
+ return $this->name;
+ }
+
}
?>
\ No newline at end of file
diff --git a/modules/cms-core/model/Group.class.php b/modules/cms-core/model/Group.class.php
@@ -379,6 +379,12 @@ class Group extends ModelBase
// Datenbankabfrage ausf?hren
$sql->query( $sql );
}
+
+ public function getName()
+ {
+ return $this->name;
+ }
+
}
?>
\ No newline at end of file
diff --git a/modules/cms-core/model/Language.class.php b/modules/cms-core/model/Language.class.php
@@ -234,6 +234,12 @@ class Language extends ModelBase
{
self::setLocale( $this->isoCode );
}
+
+ public function getName()
+ {
+ return $this->name;
+ }
+
}
?>
\ No newline at end of file
diff --git a/modules/cms-core/model/Model.class.php b/modules/cms-core/model/Model.class.php
@@ -212,6 +212,11 @@ SQL
$sql->query();
}
}
+
+ public function getName()
+ {
+ return $this->name;
+ }
}
?>
\ No newline at end of file
diff --git a/modules/cms-core/model/ModelBase.class.php b/modules/cms-core/model/ModelBase.class.php
@@ -1,7 +1,7 @@
<?php
namespace cms\model;
-class ModelBase
+abstract class ModelBase
{
/*
protected function setDatabaseRow( $row )
@@ -10,6 +10,9 @@ class ModelBase
}
*/
+ public function __construct()
+ {
+ }
/**
* All public properties of this object.
@@ -19,4 +22,6 @@ class ModelBase
{
return get_object_vars( $this );
}
+
+ public abstract function getName();
}
diff --git a/modules/cms-core/model/Name.class.php b/modules/cms-core/model/Name.class.php
@@ -149,6 +149,10 @@ SQL
}
+ public function getName()
+ {
+ return $this->name;
+ }
}
diff --git a/modules/cms-core/model/Pageelement.class.php b/modules/cms-core/model/Pageelement.class.php
@@ -0,0 +1,58 @@
+<?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.
+use cms\mustache\Mustache;
+use cms\publish\PublishPreview;use cms\publish\PublishPublic;
+use Logger;
+use util\FileCache;
+
+
+/**
+ * Pageelement.
+ *
+ * @author Jan Dankert
+ */
+
+class Pageelement extends ModelBase
+{
+ private $pageid;
+ private $elementid;
+
+ function __construct($objectid='' )
+ {
+ parent::__construct();
+
+ $ids = explode('_',$objectid);
+ if ( count($ids) > 1 )
+ list( $this->pageid, $this->elementid ) = $ids;
+ }
+
+
+ function load() {
+
+ }
+
+
+ public function getName()
+ {
+ $e = new Element( $this->elementid );
+ $e->load();
+ return $e->getName();
+ }
+}
+
diff --git a/modules/cms-core/model/Project.class.php b/modules/cms-core/model/Project.class.php
@@ -1057,6 +1057,10 @@ SQL
return $folders;
}
+ public function getName()
+ {
+ return $this->name;
+ }
}
?>
\ No newline at end of file
diff --git a/modules/cms-core/model/Template.class.php b/modules/cms-core/model/Template.class.php
@@ -385,7 +385,12 @@ SQL
return( $this->mime_type );
}
-
+
+ public function getName()
+ {
+ return $this->name;
+ }
+
}
?>
\ No newline at end of file
diff --git a/modules/cms-core/model/TemplateModel.class.php b/modules/cms-core/model/TemplateModel.class.php
@@ -171,6 +171,12 @@ class TemplateModel extends ModelBase
return( $this->mime_type );
}
-
+
+
+ public function getName()
+ {
+ return '';
+ }
+
}
diff --git a/modules/cms-core/model/Value.class.php b/modules/cms-core/model/Value.class.php
@@ -1730,4 +1730,11 @@ SQL
return $this->text;
}
}
+
+
+ public function getName()
+ {
+ return '';
+ }
+
}
\ No newline at end of file
diff --git a/modules/cms-core/require.php b/modules/cms-core/require.php
@@ -34,5 +34,6 @@ require_once(__DIR__ . "/functions/request.inc.php");
require_once(__DIR__ . '/init.php');
require_once(__DIR__ . "/Dispatcher.class.php");
+require_once(__DIR__ . "/ModelFactory.class.php");
?>
\ No newline at end of file