classes/bfw/mvc/controller/HomeController.php
changeset 1 56e0dbd5c243
parent 0 4869aea77e21
child 7 3ed6f90e97d9
--- a/classes/bfw/mvc/controller/HomeController.php
+++ b/classes/bfw/mvc/controller/HomeController.php
@@ -1,124 +1,122 @@
 <?php
 
-namespace bfw\mvc\controller {
+namespace bfw\mvc\controller;
+
+use bfw\database\Database;
+use bfw\Dispatcher;
+use bfw\mvc\common\Controller;
+use bfw\mvc\model\TGroup;
+use bfw\mvc\model\TText;
+use bfw\mvc\model\TUser;
+
+/**
+ * Copyright(C) 2015 Markus Bröker<broeker.markus@googlemail.com>
+ *
+ */
+class HomeController extends Controller {
+    const TEXT_ID = 2;
 
     /**
-     * Copyright(C) 2015 Markus Bröker<broeker.markus@googlemail.com>
+     * HomeController constructor.
      *
      */
+    public function __construct() {
+        $model = new TUser();
+        parent::__construct($model);
+    }
 
-    use bfw\Database;
-    use bfw\Dispatcher;
-    use bfw\mvc\model\Model;
-    use bfw\mvc\model\TGroup;
-    use bfw\mvc\model\TText;
-
-    class HomeController extends Controller {
-        const TEXT_ID = 2;
+    /**
+     * Default Index Action
+     *
+     * Zu berücksichtigen ist hier:
+     *
+     * Sowohl GET-Actions als auch POST Actions werden berücksichtigt
+     */
+    public function index() {
+        $request = $this->getRequest();
+        $engine = $this->getView();
 
         /**
-         * HomeController constructor.
-         *
-         * @param Model $model
-         * @param Request $request
-         */
-        public function __construct($model, $request) {
-            parent::__construct($model, $request);
-        }
-
-        /**
-         *
+         * Reset mit Redirect
          */
-        public function eintragen() {
-            $request = $this->getRequest();
-
-            $tText = new TText();
-            $text = $tText->find(self::TEXT_ID);
+        if ($request->getParameter('reset') == '1') {
+            $this->reset($engine, $request);
 
-            $text->setHeadline($request->session('headline'));
-            $text->setText($request->session('text'));
-
-            if ($tText->store(self::TEXT_ID, $text)) {
-                $request->setKey('msg', 'Der CMS-Text wurde aktualisiert.');
-            } else {
-                $request->setKey('fehler', 'Der CMS-Text kontne nicht aktualisiert werden.');
-            }
+            return;
         }
 
         /**
-         *
+         * Eintragen mit Redirect
          */
-        public function reset() {
-            $request = $this->getRequest();
-            $db = Database::getInstance();
+        if ($request->get('unit') == '1') {
+            $this->unit();
 
-            if (!$db->cleanup()) {
-                $request->deleteParameterKey('reset');
-                $request->setKey('fehler', 'Fehler beim Aufräumen');
-                Dispatcher::route('/');
-            }
+            return;
+        }
 
-            $request->deleteParameterKey('reset');
-            $request->destroySession();
-
-            Dispatcher::route('/');
+        if ($request->post('eintragen') != '') {
+            $this->eintragen();
         }
 
-        /**
-         *
-         */
-        public function unit() {
-            $request = $this->getRequest();
+        $tText = new TText();
+        $group_id = $request->getKey('group_id', TGroup::GUEST);
+
+        $text = $tText->find(self::TEXT_ID);
+        $engine->assign('text', $text);
+        $engine->assign('group_id', $group_id);
+    }
 
-            $db = Database::getInstance();
-            $db->csvImport('t_user', 'data/import/test_users.csv');
-            $db->csvImport('t_ticket', 'data/import/test_tickets.csv');
+    /**
+     *
+     */
+    public function reset() {
+        $request = $this->getRequest();
+        $db = Database::getInstance();
 
-            $request->deleteParameterKey('unit');
-
+        if (!$db->cleanup()) {
+            $request->deleteParameterKey('reset');
+            $request->setKey('fehler', 'Fehler beim Aufräumen');
             Dispatcher::route('/');
         }
 
-        /**
-         * Default Index Action
-         *
-         * Zu berücksichtigen ist hier:
-         *
-         * Sowohl GET-Actions als auch POST Actions werden berücksichtigt
-         */
-        public function index() {
-            $request = $this->getRequest();
-            $engine = $this->getView();
+        $request->deleteParameterKey('reset');
+        $request->destroySession();
+
+        Dispatcher::route('/');
+    }
 
-            /**
-             * Reset mit Redirect
-             */
-            if ($request->getParameter('reset') == '1') {
-                $this->reset($engine, $request);
+    /**
+     *
+     */
+    public function unit() {
+        $request = $this->getRequest();
 
-                return;
-            }
+        $db = Database::getInstance();
+        $db->csvImport('t_user', 'data/import/test_users.csv');
+        $db->csvImport('t_ticket', 'data/import/test_tickets.csv');
+
+        $request->deleteParameterKey('unit');
+
+        Dispatcher::route('/');
+    }
 
-            /**
-             * Eintragen mit Redirect
-             */
-            if ($request->get('unit') == '1') {
-                $this->unit();
+    /**
+     *
+     */
+    public function eintragen() {
+        $request = $this->getRequest();
 
-                return;
-            }
+        $tText = new TText();
+        $text = $tText->find(self::TEXT_ID);
 
-            if ($request->post('eintragen') != '') {
-                $this->eintragen();
-            }
-
-            $tText = new TText();
-            $group_id = $request->getKey('group_id', TGroup::GUEST);
+        $text->setHeadline($request->session('headline'));
+        $text->setText($request->session('text'));
 
-            $text = $tText->find(self::TEXT_ID);
-            $engine->assign('text', $text);
-            $engine->assign('group_id', $group_id);
+        if ($tText->store()) {
+            $request->setKey('msg', 'Der CMS-Text wurde aktualisiert.');
+        } else {
+            $request->setKey('fehler', 'Der CMS-Text kontne nicht aktualisiert werden.');
         }
+    }
 
-    }
 }
\ No newline at end of file