From 7d02549bccf50d95b3e9971c41845c2424b68a7f Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 30 Jan 2016 22:13:15 +0100 Subject: [PATCH] Cleanup and function pull out --- Controller.php | 23 +------- Models/Calendar.php | 128 +++++++++++++++---------------------------- Models/Event.php | 17 +----- Models/NullEvent.php | 32 +++++++++++ 4 files changed, 78 insertions(+), 122 deletions(-) create mode 100644 Models/NullEvent.php diff --git a/Controller.php b/Controller.php index 2a377dc..dd9dab0 100644 --- a/Controller.php +++ b/Controller.php @@ -115,30 +115,9 @@ class Controller extends ModuleAbstract implements WebInterface { $view = new View($this->app, $request, $response); $view->setTemplate('/Modules/Calendar/Theme/Backend/calendar-dashboard'); - $view->addData('nav', $this->createNavigation(1001201001, $request, $response)); + $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1001201001, $request, $response)); return $view; } - /** - * @param int $pageId Page/parent Id for navigation - * @param RequestAbstract $request Request - * @param ResponseAbstract $response Response - * - * @return RenderableInterface - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - private function createNavigation(int $pageId, RequestAbstract $request, ResponseAbstract $response) - { - $nav = Navigation::getInstance($request, $this->app->dbPool); - $navView = new NavigationView($this->app, $request, $response); - $navView->setTemplate('/Modules/Navigation/Theme/Backend/mid'); - $navView->setNav($nav->getNav()); - $navView->setLanguage($request->getL11n()->getLanguage()); - $navView->setParent($pageId); - - return $navView; - } } diff --git a/Models/Calendar.php b/Models/Calendar.php index 8b2f60d..2b07aef 100644 --- a/Models/Calendar.php +++ b/Models/Calendar.php @@ -15,8 +15,6 @@ */ namespace Modules\Calendar\Models; -use phpOMS\Pattern\Multition; - /** * Calendar class. * @@ -28,7 +26,7 @@ use phpOMS\Pattern\Multition; * @link http://orange-management.com * @since 1.0.0 */ -class Calendar implements Multition +class Calendar { /** @@ -37,7 +35,7 @@ class Calendar implements Multition * @var int * @since 1.0.0 */ - private $id = null; + private $id = 0; /** * Name. @@ -56,20 +54,20 @@ class Calendar implements Multition private $description = ''; /** - * Created. + * Created at. * * @var \Datetime * @since 1.0.0 */ - private $created = null; + private $createdAt = null; /** - * Creator. + * Created by. * * @var int * @since 1.0.0 */ - private $creator = null; + private $createdBy = 0; /** * Events. @@ -79,125 +77,85 @@ class Calendar implements Multition */ private $events = []; - private static $instances = []; - - public function __construct($id) + public function __construct() { + $this->createdAt = new \DateTime('now'); } - public function getInstance($id) - { - if (!isset(self::$instances[$id])) { - self::$instances[$id] = new self($id); - } - - return self::$instances[$id]; - } - - /** - * {@inheritdoc} - */ - public function init($id) - { - } - - /** - * {@inheritdoc} - */ - public function __clone() - { - } - - public function getId() + public function getId() : int { return $this->id; } - public function getName() + public function getName() : string { return $this->name; } - public function setName($name) + public function setName(string $name) { $this->name = $name; } - public function getDescription() + public function getDescription() : string { return $this->description; } - public function setDescription($desc) + public function setDescription(string $desc) { $this->description = $desc; } - public function getEvents() + public function addEvent(Event $event) : int + { + $this->events[] = $event; + + end($this->events); + $key = key($this->events); + reset($this->events); + + return $key; + } + + public function getEvents() : array { return $this->events; } - public function removeEvent() + public function removeEvent($id) : bool { + if (isset($this->events[$id])) { + unset($this->events[$id]); + + return true; + } + + return false; } - public function getEvent($id) + public function getEvent($id) : Event { + return $this->events[$id] ?? new NullEvent(); } - public function getCreated() + public function getCreatedAt() : \DateTime { - return $this->created; + return $this->createdAt; } - public function setCreated($created) + public function setCreatedAt(\DateTime $createdAt) { - $this->created = $created; + $this->createdAt = $createdAt; } - public function getCreator() + public function getCreatedBy() : int { - return $this->creator; + return $this->createdBy; } - public function setCreator($creator) - { - $this->creator = $creator; - } - - /** - * {@inheritdoc} - */ - public function delete() - { - } - - /** - * {@inheritdoc} - */ - public function create() - { - } - - /** - * {@inheritdoc} - */ - public function update() - { - } - - /** - * {@inheritdoc} - */ - public function serialize() - { - } - - /** - * {@inheritdoc} - */ - public function unserialize($data) + public function setCreatedBy(int $createdBy) { + $this->createdBy = $createdBy; } } diff --git a/Models/Event.php b/Models/Event.php index d93533a..339403a 100644 --- a/Models/Event.php +++ b/Models/Event.php @@ -15,8 +15,6 @@ */ namespace Modules\Calendar\Models; -use phpOMS\Pattern\Multition; - /** * Calendar class. * @@ -28,7 +26,7 @@ use phpOMS\Pattern\Multition; * @link http://orange-management.com * @since 1.0.0 */ -class Event implements Multition +class Event { /** @@ -119,21 +117,10 @@ class Event implements Multition */ private $occurence = null; - private static $instances = []; - - public function __construct($id) + public function __construct() { } - public function getInstance($id) - { - if (!isset(self::$instances[$id])) { - self::$instances[$id] = new self($id); - } - - return self::$instances[$id]; - } - /** * {@inheritdoc} */ diff --git a/Models/NullEvent.php b/Models/NullEvent.php new file mode 100644 index 0000000..1414484 --- /dev/null +++ b/Models/NullEvent.php @@ -0,0 +1,32 @@ + + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace Modules\Calendar\Models; + +/** + * Calendar class. + * + * @category Calendar + * @package Framework + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class NullEvent extends Event +{ + +}