From 0bffa7f0bcaad91019a8112f63f7438edb87a1bc Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 13 Mar 2016 00:14:39 +0100 Subject: [PATCH] Draft ProjectManagement and EventManagement models --- Admin/Installer.php | 33 ++++++ Models/Event.php | 237 ++++++++++++++--------------------------- Models/EventMapper.php | 147 +++++++++++++++++++++++++ Models/EventType.php | 56 ++++++++++ 4 files changed, 314 insertions(+), 159 deletions(-) create mode 100644 Models/EventMapper.php create mode 100644 Models/EventType.php diff --git a/Admin/Installer.php b/Admin/Installer.php index 24b65e4..ae5f611 100644 --- a/Admin/Installer.php +++ b/Admin/Installer.php @@ -42,7 +42,40 @@ class Installer extends InstallerAbstract switch ($dbPool->get('core')->getType()) { case DatabaseType::MYSQL: + $dbPool->get('core')->con->prepare( + 'CREATE TABLE if NOT EXISTS `' . $dbPool->get('core')->prefix . 'eventmanagement_event` ( + `eventmanagement_event_id` int(11) NOT NULL AUTO_INCREMENT, + `eventmanagement_event_type` tinyint(2) NOT NULL, + `eventmanagement_event_event` int(11) NOT NULL, + `eventmanagement_event_costs` int(11) NOT NULL, + `eventmanagement_event_budget` int(11) NOT NULL, + `eventmanagement_event_earnings` int(11) NOT NULL, + PRIMARY KEY (`eventmanagement_event_id`), + KEY `eventmanagement_event_event` (`eventmanagement_event_event`) + )ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;' + )->execute(); + $dbPool->get('core')->con->prepare( + 'ALTER TABLE `' . $dbPool->get('core')->prefix . 'eventmanagement_event` + ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'eventmanagement_event_ibfk_1` FOREIGN KEY (`eventmanagement_event_event`) REFERENCES `' . $dbPool->get('core')->prefix . 'calendar_event` (`calendar_event_id`);' + )->execute(); + + $dbPool->get('core')->con->prepare( + 'CREATE TABLE if NOT EXISTS `' . $dbPool->get('core')->prefix . 'eventmanagement_task_relation` ( + `eventmanagement_task_relation_id` int(11) NOT NULL AUTO_INCREMENT, + `eventmanagement_task_relation_src` int(11) NULL, + `eventmanagement_task_relation_dst` int(11) NULL, + PRIMARY KEY (`eventmanagement_task_relation_id`), + KEY `eventmanagement_task_relation_src` (`eventmanagement_task_relation_src`), + KEY `eventmanagement_task_relation_dst` (`eventmanagement_task_relation_dst`) + )ENGINE=InnoDB DEFAULT CHARSET=utf8;' + )->execute(); + + $dbPool->get('core')->con->prepare( + 'ALTER TABLE `' . $dbPool->get('core')->prefix . 'eventmanagement_task_relation` + ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'eventmanagement_task_relation_ibfk_1` FOREIGN KEY (`eventmanagement_task_relation_src`) REFERENCES `' . $dbPool->get('core')->prefix . 'task` (`task_id`), + ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'eventmanagement_task_relation_ibfk_2` FOREIGN KEY (`eventmanagement_task_relation_dst`) REFERENCES `' . $dbPool->get('core')->prefix . 'eventmanagement_event` (`eventmanagement_event_id`);' + )->execute(); break; } } diff --git a/Models/Event.php b/Models/Event.php index 5fc6993..4b75ebe 100644 --- a/Models/Event.php +++ b/Models/Event.php @@ -13,9 +13,9 @@ * @version 1.0.0 * @link http://orange-management.com */ -namespace Modules\EventManagement; +namespace Modules\EventManagement\Models; -use phpOMS\Pattern\Multition; +use Modules\Calendar\Models\Event as CalendarEvent; /** * Event class. @@ -28,7 +28,7 @@ use phpOMS\Pattern\Multition; * @link http://orange-management.com * @since 1.0.0 */ -class Event implements Multition +class Event { /** @@ -39,208 +39,127 @@ class Event implements Multition */ private $id = null; - /** - * Name. - * - * @var string - * @since 1.0.0 - */ + private $type = EventType::DEFAULT; + private $name = ''; - /** - * Description. - * - * @var string - * @since 1.0.0 - */ - private $description = null; + private $event = null; - /** - * Created. - * - * @var datetime - * @since 1.0.0 - */ - private $created = null; + private $costs = null; - /** - * Creator. - * - * @var int - * @since 1.0.0 - */ - private $creator = null; + private $budget = null; - /** - * Calendar. - * - * @var \Modules\Calender\Models\Calender - * @since 1.0.0 - */ - private $calendar = null; + private $earnings = null; - /** - * People/Users. - * - * @var array - * @since 1.0.0 - */ - private $people = []; + private $tasks = []; - private static $instances = []; - - public function __construct($id) + public function __construct(string $name = '') { + $this->event = new CalendarEvent(); + $this->costs = new Money(); + $this->budget = new Money(); + $this->earnings = new Money(); + + $this->setName($name); } - public function getInstance($id) + public function getEvent() : CalendarEvent { - if (!isset(self::$instances[$id])) { - self::$instances[$id] = new self($id); - } - - return self::$instances[$id]; + return $this->event; } - public function getId() + public function setName(string $name) { - return $this->id; + $this->name = $name; + $this->event->setName($name); } - public function getName() + public function getName() : string { return $this->name; } - public function setName($name) + public function addTask(Task $task) { - $this->name = $name; - } - - public function getDescription() - { - return $this->description; - } - - public function setDescription($desc) - { - $this->descritpion = $desc; - } - - public function getCreated() - { - return $this->created; - } - - public function setCreated($created) - { - $this->created = $created; - } - - public function getCreator() - { - return $this->creator; - } - - public function setCreator($creator) - { - $this->creator = $creator; - } - - public function getCalendar() - { - return $this->calender; - } - - public function setCalender($calender) - { - $this->calender = $calender; - } - - public function getPeople() - { - return $this->people; - } - - public function setPeople($people) - { - $this->people = $people; - } - - public function addPerson($person) - { - if (!isset($this->people[$person['id']])) { - $this->people[$person['id']] = $person; + if($task->getId() !== 0) { + $this->tasks[$task->getId()] = $task; + } else { + $this->tasks[] = $task; } } - public function removePerson($id) + public function removeTask(int $id) : bool { - if (isset($this->people[$id])) { - unset($this->people[$id]); + if(isset($this->tasks[$id])) { + unset($this->tasks[$id]); + + return true; } + + return false; } - /** - * {@inheritdoc} - */ - public function delete() + public function getTask(int $id) : Task { + return $this->tasks[$id] ?? new NullTask(); } - /** - * {@inheritdoc} - */ - public function create() + public function getTasks() : array { + return $this->tasks; } - /** - * {@inheritdoc} - */ - public function update() + public function countTasks() : int { + return count($this->tasks); } - /** - * {@inheritdoc} - */ - public function serialize() + public function getId() : int { + return $this->id; } - /** - * {@inheritdoc} - */ - public function unserialize($data) + public function setType(int $type) { + if(!EventType::isValid($type)) { + throw new InvalidEnumValue($type); + } + + $this->type = $type; } - /** - * Init object by ID. - * - * This usually happens from DB or cache - * - * @param int $id Object ID - * - * @return void - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - public function init($id) + public function getType() : int { - // TODO: Implement init() method. + return $this->type; } - /** - * Overwriting clone in order to maintain singleton pattern. - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - public function __clone() + public function getCosts() : Money { - // TODO: Implement __clone() method. + return $this->costs; + } + + public function getBudget() : Money + { + return $this->budget; + } + + public function getEarnings() : Money + { + return $this->earnings; + } + + public function setCosts(Money $costs) + { + $this->costs = $costs; + } + + public function setBudget(Money $budget) + { + $this->budget = $budget; + } + + public function setEarnings(Money $earnings) + { + $this->earnings = $earnings; } } diff --git a/Models/EventMapper.php b/Models/EventMapper.php new file mode 100644 index 0000000..355e385 --- /dev/null +++ b/Models/EventMapper.php @@ -0,0 +1,147 @@ + + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace Modules\EventManagement\Models; + +use phpOMS\DataStorage\Database\DataMapperAbstract; +use phpOMS\DataStorage\Database\Query\Builder; +use phpOMS\DataStorage\Database\Query\Column; + +/** + * Mapper class. + * + * @category Calendar + * @package Modules + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class EventMapper extends DataMapperAbstract +{ + + /** + * Columns. + * + * @var array + * @since 1.0.0 + */ + protected static $columns = [ + 'eventmanagement_event_id' => ['name' => 'eventmanagement_event_id', 'type' => 'int', 'internal' => 'id'], + 'eventmanagement_event_type' => ['name' => 'eventmanagement_event_type', 'type' => 'int', 'internal' => 'type'], + 'eventmanagement_event_event' => ['name' => 'eventmanagement_event_event', 'type' => 'int', 'internal' => 'event'], + 'eventmanagement_event_costs' => ['name' => 'eventmanagement_event_costs', 'type' => 'Serializable', 'internal' => 'costs'], + 'eventmanagement_event_budget' => ['name' => 'eventmanagement_event_budget', 'type' => 'Serializable', 'internal' => 'budget'], + 'eventmanagement_event_earnings' => ['name' => 'eventmanagement_event_earnings', 'type' => 'Serializable', 'internal' => 'earnings'], + ]; + + /** + * Has one relation. + * + * @var array + * @since 1.0.0 + */ + protected static $hasOne = [ + 'event' => [ + 'mapper' => \Modules\Calendar\Models\EventMapper::class, + 'src' => 'eventmanagement_event_event', + ], + ]; + + /** + * Has many relation. + * + * @var array + * @since 1.0.0 + */ + protected static $hasMany = [ + 'sources' => [ + 'mapper' => \Modules\Tasks\Models\TaskMapper::class, /* mapper of the related object */ + 'relationmapper' => null, /* if the relation itself is a more complex object that has it's own mapper */ + 'table' => 'eventmanager_task_relation', /* table of the related object, null if no relation table is used (many->1) */ + 'dst' => 'eventmanager_task_relation_dst', + 'src' => 'eventmanager_task_relation_src', + ], + ]; + + /** + * Primary table. + * + * @var string + * @since 1.0.0 + */ + protected static $table = 'eventmanagement_event'; + + /** + * Create media. + * + * @param Event $obj Media + * + * @return bool + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function create($obj) + { + try { + $objId = parent::create($obj); + $query = new Builder($this->db); + $query->prefix($this->db->getPrefix()) + ->insert( + 'account_permission_account', + 'account_permission_from', + 'account_permission_for', + 'account_permission_id1', + 'account_permission_id2', + 'account_permission_r', + 'account_permission_w', + 'account_permission_m', + 'account_permission_d', + 'account_permission_p' + ) + ->into('account_permission') + ->values($obj->getCreatedBy(), 'calendar_event', 'calendar_event', 1, $objId, 1, 1, 1, 1, 1); + + $this->db->con->prepare($query->toSql())->execute(); + } catch (\Exception $e) { + var_dump($e->getMessage()); + + return false; + } + + return $objId; + } + + /** + * Find. + * + * @param array $columns Columns to select + * + * @return Builder + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function find(...$columns) : Builder + { + return parent::find(...$columns)->from('account_permission') + ->where('account_permission.account_permission_for', '=', 'calendar_event') + ->where('account_permission.account_permission_id1', '=', 1) + ->where('calendar_event.calendar_event_id', '=', new Column('account_permission.account_permission_id2')) + ->where('account_permission.account_permission_r', '=', 1); + } +} diff --git a/Models/EventType.php b/Models/EventType.php new file mode 100644 index 0000000..14c62f9 --- /dev/null +++ b/Models/EventType.php @@ -0,0 +1,56 @@ + + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace Modules\EventManagement\Models; + +use phpOMS\Datatypes\Enum; + +/** + * Event type enum. + * + * @category Calendar + * @package Modules + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +abstract class EventType extends Enum +{ + const DEFAULT = 0; + + const COURSE = 1; + + const EVENT = 2; + + const FAIR = 3; + + const CONGRESS = 4; + + const DEMO = 5; + + const CONFERENCE = 6; + + const SEMINAR = 7; + + const MEETING = 8; + + const TRADESHOW = 9; + + const LAUNCH = 10; + + const CELEBRATION = 11; +}