diff --git a/Admin/Installer.php b/Admin/Installer.php index 76d4b01..c9c7abd 100644 --- a/Admin/Installer.php +++ b/Admin/Installer.php @@ -48,16 +48,16 @@ class Installer extends InstallerAbstract `calendar_name` varchar(25) NOT NULL, `calendar_password` varchar(64) NOT NULL, `calendar_description` varchar(255) NOT NULL, - `calendar_creator` int(11) NOT NULL, - `calendar_created` datetime NOT NULL, + `task_created_by` int(11) NOT NULL, + `task_created_at` datetime NOT NULL, PRIMARY KEY (`calendar_id`), - KEY `calendar_creator` (`calendar_creator`) + KEY `task_created_by` (`task_created_by`) )ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;' )->execute(); $dbPool->get('core')->con->prepare( 'ALTER TABLE `' . $dbPool->get('core')->prefix . 'calendar` - ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'calendar_ibfk_1` FOREIGN KEY (`calendar_creator`) REFERENCES `' . $dbPool->get('core')->prefix . 'account` (`account_id`);' + ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'calendar_ibfk_1` FOREIGN KEY (`task_created_by`) REFERENCES `' . $dbPool->get('core')->prefix . 'account` (`account_id`);' )->execute(); $dbPool->get('core')->con->prepare( @@ -82,30 +82,20 @@ class Installer extends InstallerAbstract `calendar_event_id` int(11) NOT NULL AUTO_INCREMENT, `calendar_event_name` varchar(25) NOT NULL, `calendar_event_description` varchar(255) NOT NULL, - `calendar_event_start` datetime NOT NULL, - `calendar_event_end` datetime NOT NULL, `calendar_event_status` tinyint(1) NOT NULL, - `calendar_event_repeat` tinyint(1) NOT NULL, - `calendar_event_rep_interval` tinyint(3) NOT NULL, - `calendar_event_rep_monday` tinyint(1) NOT NULL, - `calendar_event_rep_tuesday` tinyint(1) NOT NULL, - `calendar_event_rep_wednesday` tinyint(1) NOT NULL, - `calendar_event_rep_thursday` tinyint(1) NOT NULL, - `calendar_event_rep_friday` tinyint(1) NOT NULL, - `calendar_event_rep_saturday` tinyint(1) NOT NULL, - `calendar_event_rep_sunday` tinyint(1) NOT NULL, - `calendar_event_creator` int(11) NOT NULL, - `calendar_event_created` datetime NOT NULL, + `calendar_event_location` varchar(511) NOT NULL, + `calendar_event_created_by` int(11) NOT NULL, + `calendar_event_created_at` datetime NOT NULL, `calendar_event_calendar` int(11) NOT NULL, PRIMARY KEY (`calendar_event_id`), - KEY `calendar_event_creator` (`calendar_event_creator`), + KEY `calendar_event_created_by` (`calendar_event_created_by`), KEY `calendar_event_calendar` (`calendar_event_calendar`) )ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;' )->execute(); $dbPool->get('core')->con->prepare( 'ALTER TABLE `' . $dbPool->get('core')->prefix . 'calendar_event` - ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'calendar_event_ibfk_1` FOREIGN KEY (`calendar_event_creator`) REFERENCES `' . $dbPool->get('core')->prefix . 'account` (`account_id`), + ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'calendar_event_ibfk_1` FOREIGN KEY (`calendar_event_created_by`) REFERENCES `' . $dbPool->get('core')->prefix . 'account` (`account_id`), ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'calendar_event_ibfk_2` FOREIGN KEY (`calendar_event_calendar`) REFERENCES `' . $dbPool->get('core')->prefix . 'calendar` (`calendar_id`);' )->execute(); diff --git a/Models/CalendarMapper.php b/Models/CalendarMapper.php new file mode 100644 index 0000000..6006280 --- /dev/null +++ b/Models/CalendarMapper.php @@ -0,0 +1,127 @@ + + * @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; + +use phpOMS\DataStorage\Database\DataMapperAbstract; +use phpOMS\DataStorage\Database\Query\Builder; +use phpOMS\DataStorage\Database\Query\Column; + +class CalendarMapper extends DataMapperAbstract +{ + + /** + * Columns. + * + * @var array + * @since 1.0.0 + */ + protected static $columns = [ + 'calendar_id' => ['name' => 'calendar_id', 'type' => 'int', 'internal' => 'id'], + 'calendar_name' => ['name' => 'calendar_name', 'type' => 'string', 'internal' => 'name'], + 'calendar_password' => ['name' => 'calendar_password', 'type' => 'string', 'internal' => 'password'], + 'calendar_description' => ['name' => 'calendar_description', 'type' => 'int', 'internal' => 'description'], + 'calendar_created_by' => ['name' => 'calendar_created_by', 'type' => 'int', 'internal' => 'createdBy'], + 'calendar_created_at' => ['name' => 'calendar_created_at', 'type' => 'DateTime', 'internal' => 'createdAt'], + ]; + + protected static $hasMany = [ + 'taskElements' => [ + 'mapper' => '\Modules\Calendar\Models\EventMapper', + 'relationmapper' => '\Modules\Calendar\Models\EventMapper', + 'table' => 'calendar_event', + 'dst' => 'calendar_event_calendar', + 'src' => null, + ], + ]; + + /** + * Primary table. + * + * @var string + * @since 1.0.0 + */ + protected static $table = 'calendar'; + + protected static $createdAt = 'calendar_created_at'; + + /** + * Primary field name. + * + * @var string + * @since 1.0.0 + */ + protected static $primaryField = 'calendar_id'; + + /** + * Create media. + * + * @param Calendar $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', 'calendar', 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', '=', 'task') + ->where('account_permission.account_permission_id1', '=', 1) + ->where('task.task_id', '=', new Column('account_permission.account_permission_id2')) + ->where('account_permission.account_permission_r', '=', 1); + } +} diff --git a/Models/Event.php b/Models/Event.php index 339403a..3a5fc60 100644 --- a/Models/Event.php +++ b/Models/Event.php @@ -15,6 +15,10 @@ */ namespace Modules\Calendar\Models; +use phpOMS\Account\Account; +use phpOMS\Account\NullAccount; +use phpOMS\Datatypes\Location; + /** * Calendar class. * @@ -59,7 +63,7 @@ class Event * @var \Datetime * @since 1.0.0 */ - private $created = null; + private $createdAt = null; /** * Creator. @@ -67,7 +71,7 @@ class Event * @var int * @since 1.0.0 */ - private $creator = null; + private $createdBy = 0; /** * People. @@ -77,6 +81,8 @@ class Event */ private $location = null; + private $calendar = 0; + /** * People. * @@ -85,133 +91,116 @@ class Event */ private $people = []; - /** - * Start. - * - * @var \Datetime - * @since 1.0.0 - */ - private $start = null; - - /** - * Start. - * - * @var \Datetime - * @since 1.0.0 - */ - private $end = null; - - /** - * Timezone. - * - * @var \Datetime - * @since 1.0.0 - */ - private $timezone = null; - - /** - * Occurence. - * - * @var \Modules\Calendar\Models\OccurrenceType - * @since 1.0.0 - */ - private $occurence = null; - public function __construct() { + $this->createdAt = new \DateTime('now'); + $this->location = new Location(); } - /** - * {@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 getPeople() : array + { + return $this->people; + } + + public function getPerson(int $id) : Account + { + return $this->people[$id] ?? new NullAccount(); + } + + public function addPerson(Account $person) + { + $this->people[] = $person; + + end($this->people); + $key = key($this->people); + reset($this->people); + + return $key; + } + + /** + * Remove Element from list. + * + * @param int $id Task element + * + * @return bool + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function removePerson(int $id) : bool + { + if (isset($this->people[$id])) { + unset($this->people[$id]); + + return true; + } + + return false; + } + + 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 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) + public function setCreatedBy(int $createdBy) { - $this->creator = $creator; + $this->createdBy = $createdBy; } - /** - * {@inheritdoc} - */ - public function delete() + public function setLocation(Location $location) { + $this->location = $location; } - /** - * {@inheritdoc} - */ - public function create() + public function getLocation() : Location { + return $this->location; } - /** - * {@inheritdoc} - */ - public function update() + public function getCalendar() : int { + return $this->calendar; } - /** - * {@inheritdoc} - */ - public function serialize() - { - } - - /** - * {@inheritdoc} - */ - public function unserialize($data) + public function setCalendar(int $calendar) { + $this->calendar = $calendar; } } diff --git a/Models/EventMapper.php b/Models/EventMapper.php new file mode 100644 index 0000000..0d41fba --- /dev/null +++ b/Models/EventMapper.php @@ -0,0 +1,119 @@ + + * @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; + +use phpOMS\DataStorage\Database\DataMapperAbstract; +use phpOMS\DataStorage\Database\Query\Builder; +use phpOMS\DataStorage\Database\Query\Column; + +class EventMapper extends DataMapperAbstract +{ + + /** + * Columns. + * + * @var array + * @since 1.0.0 + */ + protected static $columns = [ + 'calendar_event_id' => ['name' => 'calendar_event_id', 'type' => 'int', 'internal' => 'id'], + 'calendar_event_name' => ['name' => 'calendar_event_name', 'type' => 'string', 'internal' => 'name'], + 'calendar_event_description' => ['name' => 'calendar_event_description', 'type' => 'string', 'internal' => 'description'], + 'calendar_event_location' => ['name' => 'calendar_event_location', 'type' => 'Serializable', 'internal' => 'location'], + 'calendar_event_status' => ['name' => 'calendar_event_status', 'type' => 'int', 'internal' => 'status'], + 'calendar_event_calendar' => ['name' => 'calendar_event_calendar', 'type' => 'int', 'internal' => 'calendar'], + 'calendar_event_created_by' => ['name' => 'task_created_by', 'type' => 'int', 'internal' => 'createdBy'], + 'calendar_event_created_at' => ['name' => 'task_created_at', 'type' => 'DateTime', 'internal' => 'createdAt'], + ]; + + /** + * Primary table. + * + * @var string + * @since 1.0.0 + */ + protected static $table = 'calendar_event'; + + protected static $createdAt = 'calendar_event_created_at'; + + /** + * Primary field name. + * + * @var string + * @since 1.0.0 + */ + protected static $primaryField = 'calendar_event_id'; + + /** + * Create media. + * + * @param Calendar $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(), 'task', 'task', 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', '=', 'task') + ->where('account_permission.account_permission_id1', '=', 1) + ->where('task.task_id', '=', new Column('account_permission.account_permission_id2')) + ->where('account_permission.account_permission_r', '=', 1); + } +}