# HG changeset patch # User Markus Bröker # Date 1447381441 -3600 # Node ID 3ed6f90e97d98049fed899212bc137fbe793c93f # Parent 6c23ee543e0e2ab9302eea3d3d08237ce6798f85 Überarbeitete MVC-Struktur, die ich jetzt auch nachvollziehen kann. diff --git a/.idea/TicketSystem.iml b/.idea/TicketSystem.iml --- a/.idea/TicketSystem.iml +++ b/.idea/TicketSystem.iml @@ -1,7 +1,9 @@ - + + + diff --git a/.idea/encodings.xml b/.idea/encodings.xml --- a/.idea/encodings.xml +++ b/.idea/encodings.xml @@ -1,19 +1,19 @@ + + + + + - - - - - - - - - - - + + + + + + \ No newline at end of file diff --git a/classes/bfw/Dispatcher.php b/classes/bfw/Dispatcher.php --- a/classes/bfw/Dispatcher.php +++ b/classes/bfw/Dispatcher.php @@ -1,15 +1,16 @@ * */ -use bfw\mvc\common\Controller; -use bfw\mvc\common\View; +namespace bfw; + +use bfw\core\Controller; +use bfw\core\View; use ReflectionClass; +use ReflectionException; class Dispatcher { private $request; @@ -45,40 +46,33 @@ * */ public function getView() { - $controllerName = $this->request->get('controller'); - $action = $this->request->get('action'); - $this->request->keepRequestData(); - if ($controllerName == '') { - $controllerName = 'home'; - } + $controllerName = $this->request->get('controller', 'home'); + $action = $this->request->get('action', 'index'); + + $class = Controller::mapControllerName($controllerName); + + try { + $reflection = new ReflectionClass($class); + $controller = $reflection->newInstance(); - if ($action == '') { + // Mapping vom GET-Parameter 'action' auf Controller::$action() + if (!$reflection->hasMethod($action)) { + $action = 'index'; + } + } catch (ReflectionException $e) { + $controller = new mvc\controller\ErrorController(new TView('NON_EXISTENT')); + + $controllerName = 'error'; $action = 'index'; } - try { - $class = Controller::mapControllerName($controllerName); - - $reflection = new ReflectionClass($class); - $controller = $reflection->newInstance(); - - $prefix = str_replace('bfw\mvc\controller\\', '', strtolower($class)); - $controller->setPrefix(str_replace('controller', '', $prefix)); - - // Mapping vom GET-Parameter 'action' auf Controller::$action() - if ($reflection->hasMethod($action)) { - $controller->$action(); - } else { - $controller->index(); - } - } catch (Exception $e) { - $controller = new ErrorController(new TView('NON_EXISTENT'), $this->request); - } + $controller->$action(); $view = new View($controller, $controller->getModel()); - $view->assign('action', sprintf('%s/%s', $controller->getPrefix(), $action)); + $view->assign('controller', $controllerName); + $view->assign('action', $action); return $view; } diff --git a/classes/bfw/Request.php b/classes/bfw/Request.php --- a/classes/bfw/Request.php +++ b/classes/bfw/Request.php @@ -1,19 +1,22 @@ + * + */ + namespace bfw; -use bfw\mvc\model\TGroup; -use bfw\mvc\model\TUser; use Logger; /** * Class Request */ class Request { - private static $logger = null; + protected $logger = null; public function __construct() { - self::$logger = Logger::getLogger('__CLASS__'); + $this->logger = Logger::getLogger('__CLASS__'); $this->initSession(); } @@ -29,10 +32,10 @@ 'get' => array(), 'session' => array(), 'isLoggedIn' => false, - 'user_id' => TUser::SYSTEM, - 'group_id' => TGroup::GUEST, - 'fehler' => 'Tickets for Free!', - 'msg' => 'Tickets for Free!', + 'user_id' => 1, + 'group_id' => 1, + 'error' => '', + 'msg' => '', 'lastpage' => 'home', ); } @@ -53,17 +56,14 @@ * @return string */ public static function getBaseUrl() { - return sprintf("%s://%s", - isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https' : 'http', - $_SERVER['SERVER_NAME'] - ); + return sprintf("%s://%s", isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https' : 'http', $_SERVER['SERVER_NAME']); } /** * Liefert einen gefilterten 'session' Wert * * Hierbei handelt es sich um einen zuvor gespeicherten POST-Wert, - * der in ['prefix']['session'] geladet ist... + * der in ['prefix']['session'] gelandet ist... * * @param $param * @param string $default @@ -197,16 +197,6 @@ } /** - * Liefert einen gefilterten POST-Wert - * - * @param $param - * @return mixed|string - */ - public function post($param) { - return filter_input(INPUT_POST, $param); - } - - /** * Setzt einen neuen Session Wert ins jeweilige Prefix * * @param $key @@ -228,7 +218,7 @@ * @return string */ public function printSession() { - self::$logger->info(sprintf('SESSION: %s', print_r($_SESSION['prefix'], true))); + $this->logger->info(sprintf('SESSION: %s', print_r($_SESSION['prefix'], true))); if ($this->get('debug') == '') { return ''; @@ -243,7 +233,29 @@ * @param $param * @return string */ - public function get($param) { - return filter_input(INPUT_GET, $param); + public function get($param, $default = '') { + $value = filter_input(INPUT_GET, $param); + + if ($value == '') { + return $default; + } + + return $value; + } + + /** + * Liefert einen gefilterten POST-Wert + * + * @param $param + * @return string + */ + public function post($param, $default = '') { + $value = filter_input(INPUT_POST, $param); + + if ($value == '') { + return $default; + } + + return $value; } } \ No newline at end of file diff --git a/classes/bfw/Response.php b/classes/bfw/Response.php --- a/classes/bfw/Response.php +++ b/classes/bfw/Response.php @@ -1,10 +1,12 @@ + * + */ + namespace bfw; -/** - * Response Headers sind kompliziert - * - */ + class Response { private $headers; private $statusCode; diff --git a/classes/bfw/mvc/common/Controller.php b/classes/bfw/core/Controller.php rename from classes/bfw/mvc/common/Controller.php rename to classes/bfw/core/Controller.php --- a/classes/bfw/mvc/common/Controller.php +++ b/classes/bfw/core/Controller.php @@ -1,58 +1,52 @@ * */ +namespace bfw\core; + use bfw\Request; use bfw\Response; +use Logger; /** * */ abstract class Controller { + protected $logger = null; /** * @var Model */ private $model; - /** * @var Request */ private $request; - /** * @var Response */ private $response; - /** * @var View */ private $view; /** - * @var - */ - private $prefix; - - /** * Controller constructor. * * @param Model $model * @param Request $request */ - public function __construct(Model $model) { + public function __construct(Model $model = null) { $this->request = new Request(); $this->response = new Response(); $this->model = $model; $this->view = new View($this, $model); - $this->prefix = ''; + $this->logger = Logger::getLogger(__CLASS__); } /** @@ -108,28 +102,14 @@ } /** - * @return string - */ - public function getPage() { - if ($this->getPrefix() != '') { - return sprintf('%s/%s', $this->prefix, $this->request->get('action')); - } - - return $this->request->get('action'); - } - - public function getPrefix() { - return $this->prefix; - } - - public function setPrefix($prefix) { - $this->prefix = $prefix; - - return $this; - } - - /** * */ abstract public function index(); + + protected function getModelName() { + $modelName = str_replace('controller', 'model', get_class($this)); + $modelName = strtolower($modelName); + + return str_replace('controller', '\Model', $modelName); + } } \ No newline at end of file diff --git a/classes/bfw/core/Entity.php b/classes/bfw/core/Entity.php new file mode 100644 --- /dev/null +++ b/classes/bfw/core/Entity.php @@ -0,0 +1,230 @@ + + * + */ + +namespace bfw\core; + +use bfw\database\Database; +use Logger; + +/** + * Class Entity + * + * Entity besitzt einen State in $data + * + * + * @method string getId() + * @method setId($param) + */ +class Entity { + protected $logger = null; + + protected $table; + protected $db; + + protected $data; + + /** + * @param $table + */ + public function __construct($table) { + $this->logger = Logger::getLogger('__CLASS__'); + + $this->db = Database::getInstance(); + + $this->table = $table; + $this->data = array(); + } + + /** + * Herzstück des Persistence-Frameworks + * + * Dynamische Erzeugung von Getttern- und Settern + * + * Anstatt diese explizit zu pflegen und zu warten, + * werden Diese dynamisch, on, the fly, erzeugt. + * + * Der Vorteil: Nicht Konfigurieren, nicht Erzeugen. Einfach Nutzen... + * + * @param $methodName + * @param null $params + * @return $this + */ + public function __call($methodName, $params = null) { + $prefix = substr($methodName, 0, 3); + $key = strtolower(substr($methodName, 3)); + + if ($prefix == 'set') { + $value = $params[0]; + + // no data, no state, null + if (!is_array($this->data)) { + return null; + } + + $this->data[$key] = $value; + + // fluent please! + return $this; + + } else if ($prefix == 'get') { + + // no data, no state, null + if (!is_array($this->data)) { + return null; + } + + if (array_key_exists($key, $this->data)) { + return $this->data[$key]; + } + } + + exit(sprintf('Unbekannte Methode %s::%s(%s, %s) wurde aufgerufen.', get_class($this), $methodName, $key, $prefix)); + } + + /** + * Vereinfachte Find Methode bezogen auf die jeweilige Instanz + * + * @param $id + * @return Model + */ + public function find($id) { + $this->logger->info(sprintf('%s(%d) ', __METHOD__, $id)); + + if (($this->data = $this->db->find($this->table, $id)) == null) { + return null; + } + + return $this; + } + + /** + * Die Findall Methode erzeugt typsicher den Supertyp + * + * @param bool|false $sys + * @return Model[] + */ + public function findAll($sys = false) { + $this->logger->info(sprintf('%s() ', __METHOD__)); + + $initial_id = ($sys) ? 0 : 1; + $rows = $this->db->findAll($this->table, $initial_id); + + if (count($rows) == 0) { + return array(); + } + + $list = array(); + foreach ($rows as $row) { + $item = new static(); + $item->data = $row; + + $list[] = $item; + } + + $this->logger->info(sprintf('%s(): %d', __METHOD__, count($list))); + + return $list; + } + + /** + * Vereinfachte FindByField Methode + * + * @param $field + * @param $value + * @return Model + */ + public function findByField($field, $value) { + $this->logger->info(sprintf('%s(%s, %s) ', __METHOD__, $field, $value)); + + $this->data = $this->db->findByField($this->table, $field, $value); + + // Keine Daten, keine Instanz + if ($this->data == null) { + return null; + } + + return $this; + } + + /** + * Vereinfachte FindAllByField Methode + * + * Erzeugt on the fly ein array mit dem Supertyp der Klasseninstanz + * @param $field + * @param $value + * @return Model[] + */ + public function findAllByField($field, $value) { + $this->logger->info(sprintf('%s(%s, %s) ', __METHOD__, $field, $value)); + + $rows = $this->db->findAllByField($this->table, $field, $value); + + if ($rows == null) { + return null; + } + + $list = array(); + foreach ($rows as $row) { + $item = new static(); + $item->data = $row; + + $list[] = $item; + } + + return $list; + } + + /** + * Vereinfachte persist Methode + * + * Der Logger loggt nur die Nutzdaten, deswegen sieht das im Log identisch aus. + * + * Es handelt sich allerdings einmal um ein Objekt und einmal nur um ein Array. + * + * @return bool + */ + public function persist() { + $this->logger->info(sprintf('%s(%s)', __METHOD__, print_r($this->getData(), true))); + + return $this->db->persist($this->table, $this->getData()); + } + + public function getData() { + return $this->data; + } + + /** + * Vereinfachte store Methode + * + * @return bool + */ + public function store() { + $this->logger->info(sprintf('%s(%d, %s)', __METHOD__, $this->getId(), print_r($this->getData(), true))); + + if ($this->getId() > 1) { + return $this->db->store($this->table, $this->getId(), $this->getData()); + } + + return false; + } + + /** + * Vereinfachte delete Methode + * + * @return bool + */ + public function delete() { + $this->logger->info(sprintf('%s(%d) ', __METHOD__, $this->getId())); + + if ($this->getId() > 1) { + return $this->db->delete($this->table, $this->getId()); + } + + return false; + } + +} \ No newline at end of file diff --git a/classes/bfw/mvc/common/Model.php b/classes/bfw/core/Model.php rename from classes/bfw/mvc/common/Model.php rename to classes/bfw/core/Model.php --- a/classes/bfw/mvc/common/Model.php +++ b/classes/bfw/core/Model.php @@ -1,226 +1,22 @@ + * + */ -use bfw\database\Database; +namespace bfw\core; + use Logger; /** * Class Model * - * Model besitzt einen State in $data - * - * - * @method string getId() - * @method setId($param) */ class Model { - private static $logger = null; - - protected $table; - protected $db; - - protected $data; - - /** - * @param $table - */ - public function __construct($table) { - self::$logger = Logger::getLogger('__CLASS__'); - - $this->db = Database::getInstance(); - - $this->table = $table; - $this->data = array(); - } - - /** - * Herzstück des Persistence-Frameworks - * - * Dynamische Erzeugung von Getttern- und Settern - * - * Anstatt diese explizit zu pflegen und zu warten, - * werden Diese dynamisch, on, the fly, erzeugt. - * - * Der Vorteil: Nicht Konfigurieren, nicht Erzeugen. Einfach Nutzen... - * - * @param $methodName - * @param null $params - * @return $this - */ - public function __call($methodName, $params = null) { - $prefix = substr($methodName, 0, 3); - $key = strtolower(substr($methodName, 3)); - - if ($prefix == 'set') { - $value = $params[0]; - - // no data, no state, null - if (!is_array($this->data)) { - return null; - } - - $this->data[$key] = $value; - - // fluent please! - return $this; - - } else if ($prefix == 'get') { - - // no data, no state, null - if (!is_array($this->data)) { - return null; - } - - if (array_key_exists($key, $this->data)) { - return $this->data[$key]; - } - } - - exit(sprintf('Unbekannte Methode %s::%s(%s, %s) wurde aufgerufen.', get_class($this), $methodName, $key, $prefix)); - } - - /** - * Vereinfachte Find Methode bezogen auf die jeweilige Instanz - * - * @param $id - * @return Model - */ - public function find($id) { - self::$logger->info(sprintf('%s(%d) ', __METHOD__, $id)); - - if (($this->data = $this->db->find($this->table, $id)) == null) { - return null; - } - - return $this; - } - - /** - * Die Findall Methode erzeugt typsicher den Supertyp - * - * @param bool|false $sys - * @return Model[] - */ - public function findAll($sys = false) { - self::$logger->info(sprintf('%s() ', __METHOD__)); - - $initial_id = ($sys) ? 0 : 1; - $rows = $this->db->findAll($this->table, $initial_id); - - if (count($rows) == 0) { - return array(); - } - - $list = array(); - foreach ($rows as $row) { - $item = new static(); - $item->data = $row; - - $list[] = $item; - } + protected $logger = null; - self::$logger->info(sprintf('%s(): %d', __METHOD__, count($list))); - - return $list; - } - - /** - * Vereinfachte FindByField Methode - * - * @param $field - * @param $value - * @return Model - */ - public function findByField($field, $value) { - self::$logger->info(sprintf('%s(%s, %s) ', __METHOD__, $field, $value)); - - $this->data = $this->db->findByField($this->table, $field, $value); - - // Keine Daten, keine Instanz - if ($this->data == null) { - return null; - } - - return $this; - } - - /** - * Vereinfachte FindAllByField Methode - * - * Erzeugt on the fly ein array mit dem Supertyp der Klasseninstanz - * @param $field - * @param $value - * @return Model[] - */ - public function findAllByField($field, $value) { - self::$logger->info(sprintf('%s(%s, %s) ', __METHOD__, $field, $value)); - - $rows = $this->db->findAllByField($this->table, $field, $value); - - if ($rows == null) { - return null; - } - - $list = array(); - foreach ($rows as $row) { - $item = new static(); - $item->data = $row; - - $list[] = $item; - } - - return $list; + public function __construct() { + $this->logger = Logger::getLogger(__CLASS__); } - - /** - * Vereinfachte persist Methode - * - * Der Logger loggt nur die Nutzdaten, deswegen sieht das im Log identisch aus. - * - * Es handelt sich allerdings einmal um ein Objekt und einmal nur um ein Array. - * - * @return bool - */ - public function persist() { - self::$logger->info(sprintf('%s(%s)', __METHOD__, print_r($this->getData(), true))); - - return $this->db->persist($this->table, $this->getData()); - } - - public function getData() { - return $this->data; - } - - /** - * Vereinfachte store Methode - * - * @return bool - */ - public function store() { - self::$logger->info(sprintf('%s(%d, %s)', __METHOD__, $this->getId(), print_r($this->getData(), true))); - - if ($this->getId() > 1) { - return $this->db->store($this->table, $this->getId(), $this->getData()); - } - - return false; - } - - /** - * Vereinfachte delete Methode - * - * @param $id - * @return bool - */ - public function delete() { - self::$logger->info(sprintf('%s(%d) ', __METHOD__, $this->getId())); - - if ($this->getId() > 1) { - return $this->db->delete($this->table, $this->getId()); - } - - return false; - } - } \ No newline at end of file diff --git a/classes/bfw/mvc/common/View.php b/classes/bfw/core/View.php rename from classes/bfw/mvc/common/View.php rename to classes/bfw/core/View.php --- a/classes/bfw/mvc/common/View.php +++ b/classes/bfw/core/View.php @@ -1,10 +1,14 @@ + * + */ -use bfw\mvc\model\TGroup; -use bfw\mvc\model\TStatus; -use bfw\mvc\model\TUser; +namespace bfw\core; + +use bfw\entities\TGroup; +use bfw\entities\TUser; use Smarty; require_once 'library/smarty/libs/Smarty.class.php'; @@ -54,7 +58,7 @@ $tpl = self::$tpl; $tpl->setCompileDir('./data/templates_c/'); - $tpl->setTemplateDir('./templates/'); + $tpl->setTemplateDir('./classes/bfw/mvc/view/'); } return self::$tpl; @@ -66,14 +70,13 @@ * TODO: Namensschema festlegen, damit dieser Effekt nicht auftritt */ public function display() { - $tUser = new TUser(); - $tGroup = new TGroup(); - $tStatus = new TStatus(); + $user = new TUser(); + $group = new TGroup(); $request = $this->controller->getRequest(); if ($request->getKey('isLoggedIn')) { - $tUser->find($request->getKey('user_id')); + $user->find($request->getKey('user_id')); } $controller = $this->controller; @@ -81,9 +84,9 @@ $response = $controller->getResponse(); $this->assign('response', $response); - $this->assign('tUser', $tUser); - $this->assign('tGroup', $tGroup); - $this->assign('tStatus', $tStatus); + $this->assign('user', $user); + $this->assign('group', $group); + $this->assign('request', $request); try { diff --git a/classes/bfw/database/DBInterface.php b/classes/bfw/database/DBInterface.php --- a/classes/bfw/database/DBInterface.php +++ b/classes/bfw/database/DBInterface.php @@ -1,5 +1,10 @@ + * + */ + namespace bfw\database; interface DBInterface { diff --git a/classes/bfw/database/Database.php b/classes/bfw/database/Database.php --- a/classes/bfw/database/Database.php +++ b/classes/bfw/database/Database.php @@ -1,15 +1,16 @@ + * + */ + namespace bfw\database; use Logger; use PDO; use PDOException; -/** - * Copyright(C) 2015 Markus Bröker - * - */ class Database implements DBInterface { private static $logger = null; private static $handle = null; @@ -254,7 +255,7 @@ } public function persist($table, $array) { - self::$logger->info(sprintf('%s(%s, %s) ', __METHOD__, $table, print_r($array, true))); + $this->logger->info(sprintf('%s(%s, %s) ', __METHOD__, $table, print_r($array, true))); $keys = array(); foreach (array_keys($array) as $key) { @@ -283,7 +284,7 @@ } public function store($table, $id, $array) { - self::$logger->info(sprintf('%s(%s, %d, %s) ', __METHOD__, $table, $id, print_r($array, true))); + $this->logger->info(sprintf('%s(%s, %d, %s) ', __METHOD__, $table, $id, print_r($array, true))); $list = array(); foreach ($array as $key => $value) { @@ -304,7 +305,7 @@ } public function delete($table, $id) { - self::$logger->info(sprintf('%s(%s, %s) ', __METHOD__, $table, $id)); + $this->logger->info(sprintf('%s(%s, %s) ', __METHOD__, $table, $id)); $sql = sprintf(" DELETE FROM `%s` diff --git a/classes/bfw/mvc/model/TGroup.php b/classes/bfw/entities/TGroup.php rename from classes/bfw/mvc/model/TGroup.php rename to classes/bfw/entities/TGroup.php --- a/classes/bfw/mvc/model/TGroup.php +++ b/classes/bfw/entities/TGroup.php @@ -1,8 +1,13 @@ + * + */ -use bfw\mvc\common\Model; +namespace bfw\entities; + +use bfw\core\Entity; /** * Class TGroup @@ -10,12 +15,9 @@ * @method string getName() * @mthod setName($param) */ -class TGroup extends Model { - const GUEST = 5; - const SUPPORTER = 4; - const MANAGER = 3; +class TGroup extends Entity { + const SYSTEM = 1; const ADMIN = 2; - const SYSTEM = 1; public function __construct() { parent::__construct('t_group'); @@ -34,28 +36,4 @@ return $this->db->findByField('t_group', 'name', $name); } - /** - * Besorgt ein Array mit der Liste der Manager und Darunter - * - * @return array|null - */ - public function findAllManagersAndBelow() { - /** - * SYSTEM = 1 - * ADMIN = 2 - * [MANAGER = 3, SUPPORTER = 4] - * GUEST = 5 - */ - $groups = $this->db->fetchAll($this->table, 'id > 2 and id < 5'); - - $list = array(); - foreach ($groups as $group) { - $item = new static(); - $item->data = $group; - - $list[] = $item; - } - - return $list; - } } \ No newline at end of file diff --git a/classes/bfw/mvc/model/TUser.php b/classes/bfw/entities/TUser.php rename from classes/bfw/mvc/model/TUser.php rename to classes/bfw/entities/TUser.php --- a/classes/bfw/mvc/model/TUser.php +++ b/classes/bfw/entities/TUser.php @@ -1,9 +1,13 @@ + * + */ -use bfw\mvc\common\Model; -use Logger; +namespace bfw\entities; + +use bfw\core\Entity; /** * Class TUser @@ -19,15 +23,12 @@ * @method setFirstname() * @method setLastname() */ -class TUser extends Model { +class TUser extends Entity { const SYSTEM = 1; - private static $logger = null; public function __construct() { parent::__construct('t_user'); - self::$logger = Logger::getLogger('__CLASS__'); - $this->data = array( 'id' => NULL, 'group_id' => TGroup::SYSTEM, @@ -64,92 +65,10 @@ $user = $this->find($user_id); if (!is_object($user)) { - return 'Unbekannt, Unbekannt'; + return null; } return sprintf("%s, %s", $user->getLastname(), $user->getFirstname()); } - /** - * FindMethode für alle Manager und Darunter - * - * @return array|null - */ - public function findAllManagersAndBelow() { - $managers = $this->db->query(sprintf(" - SELECT - * - FROM - `%s` - WHERE - `group_id` in (3,4,5)", - $this->table)); - - $list = array(); - foreach ($managers as $manager) { - $item = new static(); - $item->data = $manager; - - $list[] = $item; - } - - return $list; - } - - /** - * liefert den PK des nächst freien Supporters oder - * im Falle von nicht vorhandenen Supportern den System-Datensatz - * - * @return int - */ - public function getFreeSupporterId() { - - $sql = sprintf(" - SELECT - u.id, - COUNT(t.user_id) AS `count` - FROM - t_user u - LEFT JOIN - t_ticket t ON u.id = t.user_id - WHERE - u.group_id = 4 - GROUP BY - u.id - ORDER BY - `count` ASC - "); - - $data = $this->db->query($sql); - - if ($data == null) { - // Ich will hier definitiv immer eine gültige ID haben, also einen PK - return 1; - } - - self::$logger->info(sprintf("Data: %s", print_r($data, true))); - - return $data[0]['id']; - } - - /** - * Anzahl der Tickets eines Benutzers - * - * @return mixed - */ - public function getTicketCount() { - $sql = sprintf(" - SELECT - count(*) as anzahl - FROM - t_ticket - WHERE - user_id = %d - ", $this->getId()); - - $data = $this->db->query($sql); - - return $data[0]['anzahl']; - } - } \ No newline at end of file diff --git a/classes/bfw/mvc/model/TView.php b/classes/bfw/entities/TView.php rename from classes/bfw/mvc/model/TView.php rename to classes/bfw/entities/TView.php --- a/classes/bfw/mvc/model/TView.php +++ b/classes/bfw/entities/TView.php @@ -1,15 +1,18 @@ + * + */ -use bfw\mvc\common\Model; +namespace bfw\entities; /** * Class TView * * @method string getId() */ -class TView extends Model { +class TView extends Entity { /** * Nur Get-Methoden im View diff --git a/classes/bfw/mvc/controller/BenutzerverwaltungController.php b/classes/bfw/mvc/controller/BenutzerverwaltungController.php --- a/classes/bfw/mvc/controller/BenutzerverwaltungController.php +++ b/classes/bfw/mvc/controller/BenutzerverwaltungController.php @@ -1,19 +1,16 @@ * */ +namespace bfw\mvc\controller; + +use bfw\core\Controller; use bfw\Dispatcher; -use bfw\mvc\common\Controller; -use bfw\mvc\model\TGroup; -use bfw\mvc\model\TUser; class BenutzerverwaltungController extends Controller { - private static $logger = null; /** * BenutzerverwaltungsController constructor. @@ -21,7 +18,9 @@ */ public function __construct() { - $model = new TUser(); + $modelName = $this->getModelName(); + + $model = new $modelName(); parent::__construct($model); } @@ -30,33 +29,7 @@ */ public function meinProfil() { $request = $this->getRequest(); - $engine = $this->getView(); - - $username = $request->session('username'); - - $tUser = $this->getModel(); - $user = $tUser->find($request->getKey('user_id')); - - if ($request->post('aendern') != '') { - $firstname = $request->session('firstname'); - $lastname = $request->session('lastname'); - - $tUser->setUsername($username); - $tUser->setFirstname($firstname); - $tUser->setLastname($lastname); - - $password = $request->session('password'); - if ($password != '') { - $tUser->setPassword(md5($password)); - } - - if ($tUser->store()) { - $request->setKey('msg', 'Der Nutzer wurde aktualisiert.'); - $tUser->findByField('username', $tUser->getUsername()); - } else { - $request->setKey('fehler', 'Der Nutzer konnte nicht aktualisiert werden.'); - } - } + $view = $this->getView(); } /** @@ -64,13 +37,10 @@ */ public function abmelden() { $request = $this->getRequest(); - $engine = $this->getView(); + $view = $this->getView(); - $request->deleteKey('username'); - $request->deleteKey('group_id'); $request->destroySession(); - - Dispatcher::route('/'); + $request->initSession(); } /** @@ -78,42 +48,30 @@ */ public function anmelden() { $request = $this->getRequest(); - $engine = $this->getView(); - - $username = $request->session('username'); - $password = md5($request->session('password')); + $view = $this->getView(); - $tUser = $this->getModel(); - $user = $tUser->findByUsername($username); - - if ($user == null) { + if (!$request->hasPost()) { + // nothing to do! return; } - if (($username == $user->getUsername()) && ($password == $user->getPassword())) { - $request->setKey('isLoggedIn', true); - $request->setKey('user_id', $user->getId()); - $request->setKey('group_id', $user->getGroup_id()); + $model = $this->getModel()->getUser(); - $tGroup = new TGroup(); - if (($group = $tGroup->find($user->getGroup_Id())) == null) { - $request->setKey('fehler', "DB-Inkonsistenz: Prüfen Sie die exisitierenden Gruppen."); - } + $username = $request->post('username'); + $password = $request->post('password'); + + $lastpage = $request->getKey('lastpage'); - $msg = sprintf('Sie gehören der Gruppe %s an.', $group->getName()); - $request->setKey('msg', $msg); + $model->findByUsername($username); - $lastpage = $request->getKey('lastpage'); - if ($lastpage == 'benutzerverwaltung/anmelden') { - $lastpage = 'tickets/index'; - } + if ($model->getPassword() == md5($password)) { + $request->setKey('user_id', $model->getId()); + $request->setKey('group_id', $model->getGroup_Id()); - $request->setKey('lastpage', $lastpage); + $request->setKey('isLoggedIn', true); - // Routing ist final Dispatcher::route(sprintf('/%s/', $lastpage)); } - } /** @@ -121,192 +79,23 @@ */ public function registrieren() { $request = $this->getRequest(); - $engine = $this->getView(); + $view = $this->getView(); - $currentUser = new TUser(); - if ($request->post('registrieren') != '') { - $currentUser = $this->registrierenFunc($currentUser); - } + $model = $this->getModel(); - $engine->assign('currentUser', $currentUser); + $view->assign('currentUser', $model->getUser()); } - /** - * - * @param $currentUser - * @return mixed - */ - public function registrierenFunc($currentUser) { - $request = $this->getRequest(); - - $password1 = $request->session('password1'); - $password2 = $request->session('password2'); - - if (strlen($password1) == 0) { - return $currentUser; - } - - // Validierung - if ($password1 != $password2) { - $request->setKey('fehler', 'Die Passwörter sind verschieden.'); - return $currentUser; - } - - $username = $request->session('username'); - $firstname = $request->session('firstname'); - $lastname = $request->session('lastname'); - - $currentUser->setUsername($username); - $currentUser->setPassword(md5($password1)); - $currentUser->setFirstname($firstname); - $currentUser->setLastname($lastname); - $currentUser->setGroup_Id(TGroup::SUPPORTER); - - if ($username == '' || $firstname == '' || $lastname == '') { - $request->setKey('fehler', 'Sie müssen die Pflichtfelder ausfüllen.'); - return $currentUser; - } - - if ($currentUser->persist()) { - $request->setKey('msg', 'Der Nutzer wurde angelegt.'); - - if ($currentUser->findByUsername($currentUser->getUsername())) { - $request->setKey('isLoggedIn', true); - $request->setKey('user_id', $currentUser->getId()); - $request->setKey('group_id', $currentUser->getGroup_id()); - - Dispatcher::route('/benutzerverwaltung/meinprofil/'); - } - } else { - $request->setKey('fehler', 'Der Nutzer konnte nicht angelegt werden.'); - } - - return $currentUser; - } - - /** - * - */ public function index() { $request = $this->getRequest(); - $engine = $this->getView(); - - $tUser = $this->getModel(); - $tGroup = new TGroup(); - - if ($request->post('loeschen') != '') { - $this->loeschenFunc(); - } - - if ($request->post('aendern') != '') { - $this->aendernFunc(); - } - - $group_id = $request->getKey('group_id', TGroup::GUEST); - - switch ($group_id) { - case TGroup::ADMIN: - $users = $tUser->findAll(); - $groups = $tGroup->findAll(); - break; - case TGroup::MANAGER: - $users = $tUser->findAllManagersAndBelow(); - $groups = $tGroup->findAllManagersAndBelow(); - break; - default: - Dispatcher::route('/benutzerverwaltung/home/'); - } + $view = $this->getView(); - $engine->assign('users', $users); - $engine->assign('groups', $groups); - } - - /** - * - */ - public function loeschenFunc() { - $tUser = new TUser(); - $request = $this->getRequest(); - - $uid = $request->session('uid'); - - $tUser->find($uid); - if (!$tUser->delete()) { - $request->setKey('fehler', 'Der Benutzer konnte nicht gelöscht werden.'); - Dispatcher::route('/home/'); - } else { - $request->setKey('msg', 'Der Benutzer wurde gelöscht.'); - } - } - - /** - * - */ - public function aendernFunc() { - $request = $this->getRequest(); - - $uid = $request->session('uid'); - $username = $request->session('username'); - $password = $request->session('password'); - $group_id = $request->session('groupbox'); + $model = $this->getModel(); - $tUser = $this->getModel(); - $user = $tUser->find($uid); - - $user->setUsername($username); - if ($password != '') { - $user->setPassword(md5($password)); - } - - if ($group_id != '') { - $user->setGroup_id($group_id); - } - - if ($tUser->store()) { - $request->setKey('msg', 'Der Benutzer wurde erfolgreich aktualisiert.'); - } else { - $request->setKey('fehler', 'Der Benutzer konnte nicht aktualisiert werden.'); - } - } - - /** - * - */ - public function resetpasswort() { - $request = $this->getRequest(); - $engine = $this->getView(); + $users = $model->getUsers(); + $groups = $model->getGroups(); - if ($request->post('pw-reset')) { - if ($this->resetPasswordFunc()) { - Dispatcher::route('/benutzerverwaltung/anmelden/'); - } - } + $view->assign('users', $users); + $view->assign('groups', $groups); } - - /** - * - * @return bool - */ - public function resetPasswordFunc() { - $request = $this->getRequest(); - $engine = $this->getView(); - - $username = $request->session('username'); - - if (!$request->hasPost()) { - return false; - } - - $tUser = $this->getModel(); - - if ($tUser->findByUsername($username)) { - $tUser->setPassword(md5($tUser->getUsername())); - - return $tUser->store(); - } - - $engine->assign('request', $request); - return false; - } - } \ No newline at end of file diff --git a/classes/bfw/mvc/controller/DokumentationController.php b/classes/bfw/mvc/controller/DokumentationController.php new file mode 100644 --- /dev/null +++ b/classes/bfw/mvc/controller/DokumentationController.php @@ -0,0 +1,29 @@ + + * + */ + +namespace bfw\mvc\controller; + +use bfw\core\Controller; +use bfw\mvc\model\TUser; + +/** + * Class DokumentationController + * @package bfw\mvc\controller + */ +class DokumentationController extends Controller { + + public function __construct() { + $modelName = $this->getModelName(); + $model = new $modelName(); + + parent::__construct($model); + } + + public function index() { + + } +} \ No newline at end of file diff --git a/classes/bfw/mvc/controller/ErrorController.php b/classes/bfw/mvc/controller/ErrorController.php --- a/classes/bfw/mvc/controller/ErrorController.php +++ b/classes/bfw/mvc/controller/ErrorController.php @@ -1,8 +1,13 @@ + * + */ + namespace bfw\mvc\controller; -use bfw\mvc\common\Controller; +use bfw\core\Controller; /** * Copyright(C) 2015 Markus Bröker @@ -10,8 +15,8 @@ */ class ErrorController extends Controller { - public function __construct($model, $request) { - parent::__construct($model, $request); + public function __construct($model) { + parent::__construct($model); } public function index() { diff --git a/classes/bfw/mvc/controller/HistoryController.php b/classes/bfw/mvc/controller/HistoryController.php deleted file mode 100644 --- a/classes/bfw/mvc/controller/HistoryController.php +++ /dev/null @@ -1,55 +0,0 @@ - - * - */ - -use bfw\mvc\common\Controller; -use bfw\mvc\model\TGroup; -use bfw\mvc\model\THistory; -use bfw\mvc\model\TTicket; -use bfw\mvc\model\TUser; - -class HistoryController extends Controller { - - private $user_id; - private $group_id; - private $currentTicket; - - public function __construct() { - $model = new THistory(); - parent::__construct($model); - - $this->currentTicket = null; - - $request = $this->getRequest(); - - $this->user_id = $request->getKey('user_id', TUser::SYSTEM); - $this->group_id = $request->getKey('group_id', TGroup::GUEST); - } - - public function index() { - $request = $this->getRequest(); - $engine = $this->getView(); - - $tid = $request->session('tid'); - $ticket = new TTicket(); - - if ($ticket->find($tid) == null) { - $request->setKey('fehler', 'Datensatz nicht gefunden.'); - } - - $history = $this->getModel(); - $histories = $history->findAllByField('ticket_id', $tid); - if ($histories == null) { - $request->setKey('fehler', 'Die Daten sind nicht aktuell.'); - } - - $engine->assign('ticket', $ticket); - $engine->assign('histories', $histories); - } - -} \ No newline at end of file diff --git a/classes/bfw/mvc/controller/HomeController.php b/classes/bfw/mvc/controller/HomeController.php --- a/classes/bfw/mvc/controller/HomeController.php +++ b/classes/bfw/mvc/controller/HomeController.php @@ -1,27 +1,23 @@ * */ + +namespace bfw\mvc\controller; + +use bfw\core\Controller; + class HomeController extends Controller { - const TEXT_ID = 2; - /** * HomeController constructor. * */ public function __construct() { - $model = new TUser(); + $modelName = $this->getModelName(); + $model = new $modelName(); + parent::__construct($model); } @@ -35,88 +31,6 @@ public function index() { $request = $this->getRequest(); $engine = $this->getView(); - - /** - * Reset mit Redirect - */ - if ($request->getParameter('reset') == '1') { - $this->reset($engine, $request); - - return; - } - - /** - * Eintragen mit Redirect - */ - if ($request->get('unit') == '1') { - $this->unit(); - - return; - } - - if ($request->post('eintragen') != '') { - $this->eintragen(); - } - - $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); - } - - /** - * - */ - public function reset() { - $request = $this->getRequest(); - $db = Database::getInstance(); - - if (!$db->cleanup()) { - $request->deleteParameterKey('reset'); - $request->setKey('fehler', 'Fehler beim Aufräumen'); - Dispatcher::route('/'); - } - - $request->deleteParameterKey('reset'); - $request->destroySession(); - - Dispatcher::route('/'); - } - - /** - * - */ - public function unit() { - $request = $this->getRequest(); - - $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('/'); - } - - /** - * - */ - public function eintragen() { - $request = $this->getRequest(); - - $tText = new TText(); - $text = $tText->find(self::TEXT_ID); - - $text->setHeadline($request->session('headline')); - $text->setText($request->session('text')); - - 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 diff --git a/classes/bfw/mvc/controller/TicketsController.php b/classes/bfw/mvc/controller/TicketsController.php deleted file mode 100644 --- a/classes/bfw/mvc/controller/TicketsController.php +++ /dev/null @@ -1,353 +0,0 @@ - - * - */ - -use bfw\Dispatcher; -use bfw\mvc\common\Controller; -use bfw\mvc\common\Model; -use bfw\mvc\model\TGroup; -use bfw\mvc\model\TStatus; -use bfw\mvc\model\TTicket; -use bfw\mvc\model\TUser; -use Logger; - -class TicketsController extends Controller { - private $user_id; - private $group_id; - private $currentTicket; - - /** - * TicketsController constructor. - * - */ - public function __construct() { - $model = new TTicket(); - parent::__construct($model); - - $this->currentTicket = null; - - $request = $this->getRequest(); - - $this->user_id = $request->getKey('user_id', TUser::SYSTEM); - $this->group_id = $request->getKey('group_id', TGroup::GUEST); - } - - /** - * Default Index Action - */ - public function index() { - $request = $this->getRequest(); - $engine = $this->getView(); - - $user_id = $this->user_id; - $group_id = $this->group_id; - - $engine = $this->getView(); - $currentTicket = $this->currentTicket; - - // Umleiten zur Historie - if ($request->post('historie') != '') { - Dispatcher::route("/history/"); - } - - // finde das aktuelle Ticket, welches per GET live angegeben wurde. - if ($request->get('tid') != '') { - $currentTicket = $this->processTickedId($user_id); - $this->handleRequest($currentTicket, $user_id, $group_id); - - return; - } - - // lade das ausgewählte Ticket, Supporter nehmen es automatisch an. - if ($request->post('laden') != '') { - $currentTicket = $this->processLaden($user_id); - $this->handleRequest($currentTicket, $user_id, $group_id); - - return; - } - - // erstelle oder aktualisiere das aktuelle Ticket. - if ($request->post('eintragen') != '') { - $currentTicket = $this->processEintragen($user_id, $group_id); - $this->handleRequest($currentTicket, $user_id, $group_id); - - return; - } - - // lösche das aktuelle Ticket. - if ($request->post('loeschen') != '') { - $this->processLoeschen($user_id); - $this->handleRequest($currentTicket, $user_id, $group_id); - - return; - } - - $this->handleRequest($this->currentTicket, $this->user_id, $this->group_id); - } - - /** - * @param $user_id - * @return null|TTicket - */ - public function processTickedId($user_id) { - $request = $this->getRequest(); - $engine = $this->getView(); - - $tUser = new TUser(); - $user = $tUser->find($user_id); - - if ($user == null) { - $request->setKey('fehler', sprintf('Benutzer(%d) konnte nicht mehr gefunden werden.', $user_id)); - Dispatcher::route('/'); - } - - $tid = $request->get('tid'); - - $tTicket = $this->getModel(); - $currentTicket = $tTicket->find($tid); - - if ($currentTicket == null) { - $request->setKey('fehler', sprintf('Ticket Nr. %d konnte nicht gefunden werden.', $tid)); - - return null; - } - - if (!$currentTicket->hasPrivilege($currentTicket, $user, false)) { - $request->setKey('fehler', sprintf('Ihnen fehlen die Berechtigungen für das Ticket Nr. %d.', $tid)); - - return null; - } - - return $currentTicket; - } - - /** - * Diese Funktion kümmert sich um die Anfragen dieses Ticket-Controllers - * - * @param $currentTicket - * @param $user_id - * @param $group_id - */ - public function handleRequest($currentTicket, $user_id, $group_id) { - $request = $this->getRequest(); - $engine = $this->getView(); - - /** - * @var TTIcket - */ - $tTicket = $this->getModel(); - - $tUser = new TUser(); - $user = $tUser->find($user_id); - - /** - * 'Cron-Job' ohne 'Cron': Alle Tickets werden bei jedem Zugriff geprüft - * - * Gibt es Tickets, die derzeit gesperrt sind? Befreie Sie! Free Tickets!!! - * Falls Tickets frei sind, weise diese korrekt und fair wieder zu. - */ - $tTicket->unlockTickets(); - $tTicket->reassignFreeTickets(); - - switch ($group_id) { - case TGroup::SUPPORTER: - $tickets = $tTicket->findAllTicketsByUserid($user_id); - if ($tickets == null) { - $request->setKey('fehler', 'Es existieren derzeit keine Tickets für Sie!'); - } - - $users = array($tUser->findByUsername($user->getUsername())); - break; - case TGroup::ADMIN: - case TGroup::MANAGER: - $tickets = $tTicket->findAll(); - $users = $tUser->findAll(false); - break; - default: - $tickets = $tTicket->findAll(); - $users = $tUser->findAll(); - } - - $tStatus = new TStatus(); - $statusItems = $tStatus->findAll(); - - // erstelle eine neue Ticket-Instanz, falls es keine instanzierte gibt. - if ($currentTicket == null) { - $currentTicket = new TTicket(); - } - - $engine->assign('users', $users); - $engine->assign('tStatus', $tStatus); - $engine->assign('tickets', $tickets); - $engine->assign('statusItems', $statusItems); - $engine->assign('currentTicket', $currentTicket); - $engine->assign('group_id', $group_id); - } - - /** - * Ticket nach TID laden - * - * @param $user_id - * - * @return null|TTicket - */ - public function processLaden($user_id) { - $request = $this->getRequest(); - $engine = $this->getView(); - - $tid = $request->session('tid'); - - $tTicket = $this->getModel(); - $currentTicket = $tTicket->find($tid); - - if ($currentTicket == null) { - $request->setKey('fehler', sprintf('Ticket Nr. %d konnte nicht gefunden werden.', $tid)); - - return null; - } - - $tUser = new TUser(); - $user = $tUser->find($user_id); - - if ($user == null) { - $request->setKey('fehler', sprintf('Benutzer(%d) konnte nicht mehr gefunden werden.', $user_id)); - - return null; - } - - $tTicket->lockTicket($currentTicket, $user); - - if (!$currentTicket->hasPrivilege($currentTicket, $user, true)) { - $request->setKey('fehler', sprintf('Ihnen fehlen die Berechtigungen für das Ticket Nr. %d.', $tid)); - - return null; - } - - return $currentTicket; - } - - /** - * @param $user_id - * @param $group_id - * @return Model|null - */ - public function processEintragen($user_id, $group_id) { - $request = $this->getRequest(); - $engine = $this->getView(); - - $logger = Logger::getLogger('main'); - - $tid = $request->session('tid'); - $status_id = $request->session('status', TStatus::OFFEN); - - $tTicket = $this->getModel(); - - if ($tid != '') { - $tTicket->find($tid, $user_id); - } - - $tUser = new TUser(); - $user = $tUser->find($user_id); - if ($user == null) { - return null; - } - - $theHolyUserId = $tTicket->getUser_Id(); - if ($group_id == TGroup::ADMIN || $group_id == TGroup::MANAGER) { - $theHolyUserId = $request->session('user_id'); - } - - $subject = $request->session('subject'); - $message = $request->session('message'); - - if (($subject == '') && ($message == '')) { - $request->setKey('fehler', sprintf('Füllen Sie die Pflichtfelder aus.')); - - return null; - } - - $tTicket->setUser_Id($theHolyUserId); - $tTicket->setStatus_Id($status_id); - $tTicket->setSubject($subject); - $tTicket->setMessage($message); - $tTicket->setLast_Access(date("Y-m-d H:i:s")); - - if ($tid == '') { - if ($tTicket->persist()) { - $request->setKey('msg', sprintf('Ein neues Ticket wurde erfolgreich eingetragen.')); - $logger->info(sprintf('Ticket wurde eingetragen: (%s)', print_r($tTicket->getData(), true))); - - return null; - } - } else { - if (!$tTicket->hasPrivilege($tTicket, $user, true)) { - $request->setKey('fehler', sprintf('Ihnen fehlen die Berechtigungen für das Ticket Nr. %d.', $tid)); - - return null; - } - - if ($tTicket->getId() != 1) { - if ($tTicket->store()) { - $request->setKey('msg', 'Das Ticket wurde erfolgreich aktualisiert.'); - $logger->info(sprintf('Ticket wurde aktualisiert: (%s)', print_r($tTicket->getData(), true))); - } - - return $tTicket; - } - } - - return null; - } - - /** - * Löschen von Tickets - * - * @return bool - */ - public function processLoeschen($user_id) { - $request = $this->getRequest(); - $engine = $this->getView(); - - $tid = $request->session('tid'); - - $tTicket = $this->getModel(); - $currentTicket = $tTicket->find($tid); - - if ($currentTicket == null) { - $request->setKey('fehler', sprintf('Nicht existierende Tickets(%d) können nicht gelöscht werden.', $tid)); - - return false; - } - - $tUser = new TUser(); - $user = $tUser->find($user_id); - - if ($user == null) { - $request->setKey('fehler', sprintf('Benutzer(%d) konnte nicht mehr gefunden werden.', $user_id)); - - return false; - } - - if (!$currentTicket->hasPrivilege($currentTicket, $user, true)) { - $request->setKey('fehler', sprintf('Ihnen fehlen die Berechtigungen für das Ticket Nr. %d.', $tid)); - - return false; - } - - if ($currentTicket->delete($tid)) { - $request->setKey('msg', sprintf('Das Ticket mit der Nummer %d wurde gelöscht.', $tid)); - - return true; - } - - $request->setKey('fehler', sprintf('Das Ticket mit der Nummer %d konnte nicht gelöscht werden.', $tid)); - - return false; - } - -} \ No newline at end of file diff --git a/classes/bfw/mvc/model/TAction.php b/classes/bfw/mvc/model/TAction.php deleted file mode 100644 --- a/classes/bfw/mvc/model/TAction.php +++ /dev/null @@ -1,27 +0,0 @@ -data = array( - 'id' => NULL, - 'name' => '', - ); - } - -} \ No newline at end of file diff --git a/classes/bfw/mvc/model/THistory.php b/classes/bfw/mvc/model/THistory.php deleted file mode 100644 --- a/classes/bfw/mvc/model/THistory.php +++ /dev/null @@ -1,85 +0,0 @@ -data = array( - 'id' => NULL, - 'ticked_id' => 1, - 'action_id' => 1, - 'user_id' => 1, - 'status_id' => 1, - 'subject' => '', - 'message' => '', - 'locked' => false, - 'last_access' => 'now()', - ); - } - - /** - * Liefert das Name-Attribut der jeweiligen Action - * - * @return string - */ - public function getActionName() { - $action = new TAction(); - $action->find($this->getAction_Id()); - - return $action->getName(); - } - - /** - * Liefert das Name-Attribut des jeweiligen Status - * - * @return string|null - */ - public function getStatusName() { - $status = new TStatus(); - $status->find($this->getStatus_Id()); - - return $status->getName(); - } - - /** - * Liefert das jeweilige Username Attribut des angebenen Benutzers - * - * @return string - */ - public function getUsername() { - $user = new TUser(); - - return $user->getFormattedUsername($this->getUser_Id()); - } -} \ No newline at end of file diff --git a/classes/bfw/mvc/model/TStatus.php b/classes/bfw/mvc/model/TStatus.php deleted file mode 100644 --- a/classes/bfw/mvc/model/TStatus.php +++ /dev/null @@ -1,37 +0,0 @@ -data = array( - 'id' => NULL, - 'name' => '', - ); - - } - - /** - * Liefert den Bezeichner des angegebenen PKs der Status-Instanz< - * - * @param $id - * @return mixed - */ - public function getFormattedStatus($id) { - $status = $this->find($id); - - return $status->getName(); - } -} \ No newline at end of file diff --git a/classes/bfw/mvc/model/TText.php b/classes/bfw/mvc/model/TText.php deleted file mode 100644 --- a/classes/bfw/mvc/model/TText.php +++ /dev/null @@ -1,29 +0,0 @@ -data = array( - 'id' => NULL, - 'user_id' => 1, - 'headline' => '', - 'text' => '', - ); - - } -} \ No newline at end of file diff --git a/classes/bfw/mvc/model/TTicket.php b/classes/bfw/mvc/model/TTicket.php deleted file mode 100644 --- a/classes/bfw/mvc/model/TTicket.php +++ /dev/null @@ -1,201 +0,0 @@ -data = array( - 'id' => NULL, - 'user_id' => 1, - 'status_id' => 1, - 'subject' => '', - 'message' => '', - 'locked' => 0, - 'last_access' => 'now()', - ); - } - - /** - * Findet alle Tickets des angegebenen Nutzers - * - * - * @param SERIAL $uid - * @return array|null - */ - public function findAllTicketsByUserid($uid) { - return $this->findAllByField('user_id', $uid); - } - - /** - * Weisst frei gewordenen Tickets automatisiert zu. - */ - public function reassignFreeTickets() { - $tickets = $this->findAllByField('user_id', 1); - - if (!is_object($tickets)) { - return; - } - - $tUser = new TUser(); - foreach ($tickets as $ticket) { - $freeSupporterId = $tUser->getFreeSupporterId(); - - /** - * Niemals vergessen: Nur aktualisieren, wenn auch - * aktualisiert werden muss. - * - */ - if ($freeSupporterId > 1) { - $ticket->setUser_Id($freeSupporterId); - if ($ticket->store()) { - self::$logger->info(sprintf("TICKET %d wurde neu zugewiesen.", $ticket->getId())); - } - } - } - } - - public function lockTicket($ticket, $user) { - if ($user->getGroup_id() == TGroup::SUPPORTER) { - if ($ticket->getLocked() == false) { - $ticket->setLocked(1); - $ticket->setLast_Access(date('Y-m-d H:i:s')); - - if ($ticket->store()) { - self::$logger->info(sprintf("TICKET %d wurde gesperrt", $ticket->getId())); - return true; - } - } - } - - return false; - } - - /** - * Das Ticket wird automatisch entsperrt nach 2 Stunden - * - * @return bool - */ - public function unlockTickets() { - $tickets = $this->findAll(false); - $user = new TUser(); - - foreach ($tickets as $ticket) { - if ($ticket->getStatus_Id() == TStatus::GESCHLOSSEN) { - continue; - } - - // Ticketalter - $ticketAge = time() - strtotime($ticket->getLast_Access()); - - // Die Bearbeitungszeit beträgt 2 Stunden pro Supporter - $deadLine = 3600 * 2; - - self::$logger->info('Ticket-Alter: ' . $ticketAge); - self::$logger->info('Deadline: ' . $deadLine); - - if ($ticketAge > $deadLine) { - self::$logger->info('Time is up: Daten werden geändert.'); - $freeSupporterId = $user->getFreeSupporterId(); - - if ($freeSupporterId > 1) { - $ticket->setUser_Id($freeSupporterId); - $ticket->setLocked(0); - - if (!$ticket->store()) { - self::$logger->info(sprintf('Fehler beim Schreiben: %s', print_r($ticket->getData(), true))); - } - } else { - // Es existieren keine Supporter - self::$logger->info(sprintf("%s(): Es existieren keine Supporter!", __METHOD__)); - } - } - } - - return false; - } - - /** - * Überladene find Methode - * - * In früheren Versionen wurde hier das Ticket 'on the fly' modifiziert. - * Da das aber nicht Sinn und Zweck einer 'find' Methode ist, wurde das - * wieder entfernt und die Modifizierung erfolgt außerhalb... - * - * Sinn und Zweck dieser Methode ist: 'Ticket-ID: nnn' ins Log zu schreiben... - * - * @param $id - * - * @return array|null - */ - public function find($id) { - self::$logger->info(sprintf("Ticket-ID: %d", $id)); - - return parent::find($id); - } - - /** - * Prüft, ob der übergebene Nutzer überhaupt die Berechtigung für das übergebene Ticket besitzt. - * - * @param $ticket - * @param $user - * @return bool - */ - public function hasPrivilege($ticket, $user, $write = true) { - - // NULL Tickets: Kein Zugriff - if (!is_object($ticket)) { - self::$logger->warn(sprintf("%s(): Ticket wurde nicht initialisiert!", __METHOD__)); - return false; - } - - // NULL User: Kein Zugriff - if (!is_object($user)) { - self::$logger->warn(sprintf("%s(): Benutzer wurde nicht initialisiert!", __METHOD__)); - return false; - } - - // ADMIN UND MANAGER: Zugriff per Default - switch ($user->getGroup_Id()) { - case TGroup::ADMIN: - case TGroup::MANAGER: - return true; - } - - if ($write == false) { - // System-Datensatz herausfiltern - if ($ticket->getId() > 1) { - return true; - } - } - - // Ticketbasierter Zugriff: Ticket-Owner == Angemeldeter Benutzer? - return ($ticket->getUser_Id() == $user->getId()); - } - -} \ No newline at end of file diff --git a/classes/bfw/mvc/model/benutzerverwaltung/Model.php b/classes/bfw/mvc/model/benutzerverwaltung/Model.php new file mode 100644 --- /dev/null +++ b/classes/bfw/mvc/model/benutzerverwaltung/Model.php @@ -0,0 +1,39 @@ + + * + */ + +namespace bfw\mvc\model\benutzerverwaltung; + +use bfw\entities\TGroup; +use bfw\entities\TUser; + +class Model extends \bfw\core\Model { + + private $user; + private $group; + + public function __construct() { + $this->user = new TUser(); + $this->group = new TGroup(); + } + + public function getUser() { + return $this->user; + } + + public function getGroup() { + return $this->group; + } + + public function getUsers() { + return $this->user->findAll(); + } + + public function getGroups() { + return $this->group->findAll(); + } + +} \ No newline at end of file diff --git a/classes/bfw/mvc/model/dokumentation/Model.php b/classes/bfw/mvc/model/dokumentation/Model.php new file mode 100644 --- /dev/null +++ b/classes/bfw/mvc/model/dokumentation/Model.php @@ -0,0 +1,31 @@ + + * + */ + +namespace bfw\mvc\model\dokumentation; + +use bfw\entities\TGroup; +use bfw\entities\TUser; + +class Model extends \bfw\core\Model { + + private $user; + private $group; + + public function __construct() { + $this->user = new TUser(); + $this->group = new TGroup(); + } + + public function getUsers() { + return $this->user->findAll(); + } + + public function getGroups() { + return $this->group->findAll(); + } + +} \ No newline at end of file diff --git a/classes/bfw/mvc/model/error/Model.php b/classes/bfw/mvc/model/error/Model.php new file mode 100644 --- /dev/null +++ b/classes/bfw/mvc/model/error/Model.php @@ -0,0 +1,31 @@ + + * + */ + +namespace bfw\mvc\model\error; + +use bfw\entities\TGroup; +use bfw\entities\TUser; + +class Model extends \bfw\core\Model { + + private $user; + private $group; + + public function __construct() { + $this->user = new TUser(); + $this->group = new TGroup(); + } + + public function getUsers() { + return $this->user->findAll(); + } + + public function getGroups() { + return $this->group->findAll(); + } + +} \ No newline at end of file diff --git a/classes/bfw/mvc/model/home/Model.php b/classes/bfw/mvc/model/home/Model.php new file mode 100644 --- /dev/null +++ b/classes/bfw/mvc/model/home/Model.php @@ -0,0 +1,32 @@ + + * + */ + +namespace bfw\mvc\model\home; + +use bfw\core\Model as MyModel; +use bfw\entities\TGroup; +use bfw\entities\TUser; + +class Model extends MyModel { + + private $user; + private $group; + + public function __construct() { + $this->user = new TUser(); + $this->group = new TGroup(); + } + + public function getUsers() { + return $this->user->findAll(); + } + + public function getGroups() { + return $this->group->findAll(); + } + +} \ No newline at end of file diff --git a/templates/benutzerverwaltung/abmelden.tpl b/classes/bfw/mvc/view/benutzerverwaltung/abmelden.tpl rename from templates/benutzerverwaltung/abmelden.tpl rename to classes/bfw/mvc/view/benutzerverwaltung/abmelden.tpl diff --git a/templates/benutzerverwaltung/anmelden.tpl b/classes/bfw/mvc/view/benutzerverwaltung/anmelden.tpl rename from templates/benutzerverwaltung/anmelden.tpl rename to classes/bfw/mvc/view/benutzerverwaltung/anmelden.tpl --- a/templates/benutzerverwaltung/anmelden.tpl +++ b/classes/bfw/mvc/view/benutzerverwaltung/anmelden.tpl @@ -1,6 +1,6 @@
-
-
+ +

@@ -12,20 +12,21 @@

+
-
-
-
- -
+
+
+ -
- -
+
+
- -
+
+ +
- {$request->printSession()} +{$request->printSession()}
\ No newline at end of file diff --git a/templates/benutzerverwaltung/index.tpl b/classes/bfw/mvc/view/benutzerverwaltung/index.tpl rename from templates/benutzerverwaltung/index.tpl rename to classes/bfw/mvc/view/benutzerverwaltung/index.tpl --- a/templates/benutzerverwaltung/index.tpl +++ b/classes/bfw/mvc/view/benutzerverwaltung/index.tpl @@ -8,22 +8,22 @@

- - + +

-
+

- - + +

-
+

- - {foreach $groups as $group} {if $group->getId() == $user->getGroup_id()} @@ -35,20 +35,9 @@

-
- - -
- -
- - -
-
-
@@ -69,6 +58,5 @@
- diff --git a/templates/benutzerverwaltung/meinprofil.tpl b/classes/bfw/mvc/view/benutzerverwaltung/meinprofil.tpl rename from templates/benutzerverwaltung/meinprofil.tpl rename to classes/bfw/mvc/view/benutzerverwaltung/meinprofil.tpl diff --git a/templates/benutzerverwaltung/registrieren.tpl b/classes/bfw/mvc/view/benutzerverwaltung/registrieren.tpl rename from templates/benutzerverwaltung/registrieren.tpl rename to classes/bfw/mvc/view/benutzerverwaltung/registrieren.tpl --- a/templates/benutzerverwaltung/registrieren.tpl +++ b/classes/bfw/mvc/view/benutzerverwaltung/registrieren.tpl @@ -1,7 +1,7 @@

Benutzerregistrierung


-
+
diff --git a/templates/benutzerverwaltung/resetpasswort.tpl b/classes/bfw/mvc/view/benutzerverwaltung/resetpasswort.tpl rename from templates/benutzerverwaltung/resetpasswort.tpl rename to classes/bfw/mvc/view/benutzerverwaltung/resetpasswort.tpl diff --git a/classes/bfw/mvc/view/dokumentation/index.tpl b/classes/bfw/mvc/view/dokumentation/index.tpl new file mode 100644 --- /dev/null +++ b/classes/bfw/mvc/view/dokumentation/index.tpl @@ -0,0 +1,2 @@ +

Dokumentation

+
diff --git a/templates/error/index.tpl b/classes/bfw/mvc/view/error/index.tpl rename from templates/error/index.tpl rename to classes/bfw/mvc/view/error/index.tpl diff --git a/templates/footer.tpl b/classes/bfw/mvc/view/footer.tpl rename from templates/footer.tpl rename to classes/bfw/mvc/view/footer.tpl --- a/templates/footer.tpl +++ b/classes/bfw/mvc/view/footer.tpl @@ -4,11 +4,10 @@
-

Ticket-System V1.0 / UID: {$smarty.session.prefix.user_id} / - GID: {$smarty.session.prefix.group_id} / HTTP-STATUS: {$response->getStatusCode()}

+

BFw V0.1 / UID: {$smarty.session.prefix.user_id} / GID: {$smarty.session.prefix.group_id}

-

{$smarty.session.prefix.fehler}

+

{$smarty.session.prefix.error}

\ No newline at end of file diff --git a/templates/header.tpl b/classes/bfw/mvc/view/header.tpl rename from templates/header.tpl rename to classes/bfw/mvc/view/header.tpl --- a/templates/header.tpl +++ b/classes/bfw/mvc/view/header.tpl @@ -7,24 +7,22 @@ - Ticket-System + Bröker Framework