diff --git a/Admin/Activate.php b/Admin/Activate.php new file mode 100644 index 0000000..f4ddc92 --- /dev/null +++ b/Admin/Activate.php @@ -0,0 +1,44 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace Modules\Calendar\Admin; + + +use phpOMS\DataStorage\Database\DatabasePool; +use phpOMS\Module\ActivateAbstract; +use phpOMS\Module\InfoManager; + +/** + * Navigation class. + * + * @category Modules + * @package Modules\Admin + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class Activate extends ActivateAbstract +{ + + /** + * {@inheritdoc} + */ + public static function activate(DatabasePool $dbPool, InfoManager $info) + { + parent::activate($dbPool, $info); + } +} diff --git a/Admin/Deactivate.php b/Admin/Deactivate.php new file mode 100644 index 0000000..10dddd5 --- /dev/null +++ b/Admin/Deactivate.php @@ -0,0 +1,44 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace Modules\Calendar\Admin; + + +use phpOMS\DataStorage\Database\DatabasePool; +use phpOMS\Module\DeactivateAbstract; +use phpOMS\Module\InfoManager; + +/** + * Navigation class. + * + * @category Modules + * @package Modules\Admin + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class Deactivate extends DeactivateAbstract +{ + + /** + * {@inheritdoc} + */ + public static function deactivate(DatabasePool $dbPool, InfoManager $info) + { + parent::deactivate($dbPool, $info); + } +} diff --git a/Admin/Install/Navigation.install.json b/Admin/Install/Navigation.install.json new file mode 100644 index 0000000..5f1be5e --- /dev/null +++ b/Admin/Install/Navigation.install.json @@ -0,0 +1,32 @@ +[ + { + "id": 1000901001, + "pid": "754a08ddf8bcb1cf22f310f09206dd783d42f7dd", + "type": 1, + "subtype": 1, + "name": "Calendar", + "uri": "/{/lang}/backend/calendar/dashboard?{?}", + "target": "self", + "icon": "fa fa-calendar", + "order": 10, + "from": "Calendar", + "permission": null, + "parent": 1000201001, + "children": [] + }, + { + "id": 1000901002, + "pid": "754a08ddf8bcb1cf22f310f09206dd783d42f7dd", + "type": 2, + "subtype": 1, + "name": "Calendar", + "uri": "/{/lang}/backend/calendar/dashboard?{?}", + "target": "self", + "icon": null, + "order": 30, + "from": "Calendar", + "permission": null, + "parent": 1000201001, + "children": [] + } +] diff --git a/Admin/Install/Navigation.php b/Admin/Install/Navigation.php new file mode 100644 index 0000000..92a472a --- /dev/null +++ b/Admin/Install/Navigation.php @@ -0,0 +1,40 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace Modules\Calendar\Admin\Install; +use phpOMS\DataStorage\Database\DatabasePool; + +/** + * Navigation class. + * + * @category Modules + * @package Modules\Admin + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class Navigation +{ + public static function install(string $path, DatabasePool $dbPool) + { + $navData = json_decode(file_get_contents(__DIR__ . '/Navigation.install.json'), true); + + $class = '\\Modules\\Navigation\\Admin\\Installer'; + /** @var $class \Modules\Navigation\Admin\Installer */ + $class::installExternal($dbPool, $navData); + } +} diff --git a/Admin/Installer.php b/Admin/Installer.php new file mode 100644 index 0000000..28e8571 --- /dev/null +++ b/Admin/Installer.php @@ -0,0 +1,152 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace Modules\Calendar\Admin; + +use phpOMS\DataStorage\Database\DatabaseType; +use phpOMS\DataStorage\Database\DatabasePool; +use phpOMS\Module\InfoManager; +use phpOMS\Module\InstallerAbstract; + +/** + * Calendar install class. + * + * @category Modules + * @package Modules\Calendar + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class Installer extends InstallerAbstract +{ + + /** + * {@inheritdoc} + */ + public static function install(string $path, DatabasePool $dbPool, InfoManager $info) + { + parent::install($path, $dbPool, $info); + + switch ($dbPool->get('core')->getType()) { + case DatabaseType::MYSQL: + $dbPool->get('core')->con->prepare( + 'CREATE TABLE if NOT EXISTS `' . $dbPool->get('core')->prefix . 'calendar` ( + `calendar_id` int(11) NOT NULL AUTO_INCREMENT, + `calendar_name` varchar(25) NOT NULL, + `calendar_password` varchar(64) DEFAULT NULL, + `calendar_description` varchar(255) NOT NULL, + `calendar_created_by` int(11) NOT NULL, + `calendar_created_at` datetime NOT NULL, + PRIMARY KEY (`calendar_id`), + KEY `calendar_created_by` (`calendar_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_created_by`) REFERENCES `' . $dbPool->get('core')->prefix . 'account` (`account_id`);' + )->execute(); + + $dbPool->get('core')->con->prepare( + 'CREATE TABLE if NOT EXISTS `' . $dbPool->get('core')->prefix . 'calendar_permission` ( + `calendar_permission_id` int(11) NOT NULL AUTO_INCREMENT, + `calendar_permission_type` tinyint(1) NOT NULL, + `calendar_permission_ref` int(11) NOT NULL, + `calendar_permission_calendar` int(11) NOT NULL, + `calendar_permission_permission` tinyint(2) NOT NULL, + PRIMARY KEY (`calendar_permission_id`), + KEY `calendar_permission_calendar` (`calendar_permission_calendar`) + )ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;' + )->execute(); + + $dbPool->get('core')->con->prepare( + 'ALTER TABLE `' . $dbPool->get('core')->prefix . 'calendar_permission` + ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'calendar_permission_ibfk_1` FOREIGN KEY (`calendar_permission_calendar`) REFERENCES `' . $dbPool->get('core')->prefix . 'calendar` (`calendar_id`);' + )->execute(); + + $dbPool->get('core')->con->prepare( + 'CREATE TABLE if NOT EXISTS `' . $dbPool->get('core')->prefix . 'schedule` ( + `schedule_id` int(11) NOT NULL AUTO_INCREMENT, + `schedule_uid` varchar(255) NOT NULL, + `schedule_status` tinyint(1) NOT NULL, + `schedule_freq_type` tinyint(1) NOT NULL, + `schedule_freq_interval` smallint(4) NOT NULL, + `schedule_freq_interval_type` tinyint(1) NOT NULL, + `schedule_freq_relative_interval` tinyint(3) NOT NULL, + `schedule_freq_recurrence_factor` int(11) NOT NULL, + `schedule_start` datetime NOT NULL, + `schedule_duration` int(11) NOT NULL, + `schedule_end` datetime DEFAULT NULL, + `schedule_created_at` datetime NOT NULL, + `schedule_created_by` int(11) NOT NULL, + PRIMARY KEY (`schedule_id`), + KEY `schedule_created_by` (`schedule_created_by`) + )ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;' + )->execute(); + + $dbPool->get('core')->con->prepare( + 'ALTER TABLE `' . $dbPool->get('core')->prefix . 'schedule` + ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'schedule_ibfk_1` FOREIGN KEY (`schedule_created_by`) REFERENCES `' . $dbPool->get('core')->prefix . 'account` (`account_id`);' + )->execute(); + + $dbPool->get('core')->con->prepare( + 'CREATE TABLE if NOT EXISTS `' . $dbPool->get('core')->prefix . 'calendar_event` ( + `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_status` tinyint(1) NOT NULL, + `calendar_event_type` tinyint(1) 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_schedule` int(11) NOT NULL, + `calendar_event_calendar` int(11) DEFAULT NULL, + PRIMARY KEY (`calendar_event_id`), + KEY `calendar_event_created_by` (`calendar_event_created_by`), + KEY `calendar_event_schedule` (`calendar_event_schedule`), + 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_created_by`) REFERENCES `' . $dbPool->get('core')->prefix . 'account` (`account_id`), + ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'calendar_event_ibfk_2` FOREIGN KEY (`calendar_event_schedule`) REFERENCES `' . $dbPool->get('core')->prefix . 'schedule` (`schedule_id`), + ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'calendar_event_ibfk_3` FOREIGN KEY (`calendar_event_calendar`) REFERENCES `' . $dbPool->get('core')->prefix . 'calendar` (`calendar_id`);' + )->execute(); + + $dbPool->get('core')->con->prepare( + 'CREATE TABLE if NOT EXISTS `' . $dbPool->get('core')->prefix . 'calendar_event_participant` ( + `calendar_event_participant_id` int(11) NOT NULL AUTO_INCREMENT, + `calendar_event_participant_event` int(11) NOT NULL, + `calendar_event_participant_person` int(11) NOT NULL, + `calendar_event_participant_status` tinyint(1) NOT NULL, + PRIMARY KEY (`calendar_event_participant_id`), + KEY `calendar_event_participant_event` (`calendar_event_participant_event`), + KEY `calendar_event_participant_person` (`calendar_event_participant_person`) + )ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;' + )->execute(); + + $dbPool->get('core')->con->prepare( + 'ALTER TABLE `' . $dbPool->get('core')->prefix . 'calendar_event_participant` + ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'calendar_event_participant_ibfk_1` FOREIGN KEY (`calendar_event_participant_event`) REFERENCES `' . $dbPool->get('core')->prefix . 'calendar_event` (`calendar_event_id`), + ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'calendar_event_participant_ibfk_2` FOREIGN KEY (`calendar_event_participant_person`) REFERENCES `' . $dbPool->get('core')->prefix . 'account` (`account_id`);' + )->execute(); + break; + } + } +} diff --git a/Admin/Routes/Web/Backend.php b/Admin/Routes/Web/Backend.php new file mode 100644 index 0000000..b2e3738 --- /dev/null +++ b/Admin/Routes/Web/Backend.php @@ -0,0 +1,12 @@ + [ + [ + 'dest' => '\Modules\Calendar\Controller:viewCalendarDashboard', + 'verb' => RouteVerb::GET, + ], + ], +]; diff --git a/Admin/Routes/console.php b/Admin/Routes/console.php new file mode 100644 index 0000000..1ecbfac --- /dev/null +++ b/Admin/Routes/console.php @@ -0,0 +1,3 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace Modules\Calendar\Admin; + + +use phpOMS\DataStorage\Database\DatabasePool; +use phpOMS\DataStorage\Database\Schema\Builder; +use phpOMS\Module\UninstallAbstract; + +/** + * Navigation class. + * + * @category Modules + * @package Modules\Admin + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class Uninstall extends UninstallAbstract +{ + + /** + * {@inheritdoc} + */ + public static function uninstall(DatabasePool $dbPool, InfoManager $info) + { + parent::uninstall($dbPool, $info); + + $query = new Builder($dbPool->get()); + + $query->prefix($dbPool->get('core')->getPrefix())->drop( + 'calendar_event_participant', + 'calendar_event', + 'schedule', + 'calendar_permission', + 'calendar' + ); + + $dbPool->get()->con->prepare($query->toSql())->execute(); + } +} diff --git a/Admin/Update.php b/Admin/Update.php new file mode 100644 index 0000000..ab7048d --- /dev/null +++ b/Admin/Update.php @@ -0,0 +1,46 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace Modules\Calendar\Admin; + + +use phpOMS\DataStorage\Database\DatabasePool; +use phpOMS\Module\UpdateAbstract; +use phpOMS\System\File\Directory; + +/** + * Navigation class. + * + * @category Modules + * @package Modules\Admin + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class Update extends UpdateAbstract +{ + + /** + * {@inheritdoc} + */ + public static function update(DatabasePool $dbPool, array $info) + { + Directory::deletePath(__DIR__ . '/Update'); + mkdir('Update'); + parent::update($dbPool, $info); + } +} diff --git a/Controller.php b/Controller.php new file mode 100644 index 0000000..0c35341 --- /dev/null +++ b/Controller.php @@ -0,0 +1,108 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace Modules\Calendar; + +use Modules\Calendar\Models\CalendarMapper; +use Modules\Navigation\Models\Navigation; +use Modules\Navigation\Views\NavigationView; +use phpOMS\Contract\RenderableInterface; +use phpOMS\Datatypes\SmartDateTime; +use phpOMS\Message\RequestAbstract; +use phpOMS\Message\ResponseAbstract; +use phpOMS\Module\ModuleAbstract; +use phpOMS\Module\WebInterface; +use phpOMS\Views\View; +use phpOMS\Views\ViewLayout; + +/** + * Calendar controller class. + * + * @category Modules + * @package Modules\Calendar + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class Controller extends ModuleAbstract implements WebInterface +{ + + /** + * Module path. + * + * @var string + * @since 1.0.0 + */ + /* public */ const MODULE_PATH = __DIR__; + + /** + * Module version. + * + * @var string + * @since 1.0.0 + */ + /* public */ const MODULE_VERSION = '1.0.0'; + + /** + * Module name. + * + * @var string + * @since 1.0.0 + */ + /* public */ const MODULE_NAME = 'Calendar'; + + /** + * Providing. + * + * @var string + * @since 1.0.0 + */ + protected static $providing = []; + + /** + * Dependencies. + * + * @var string + * @since 1.0.0 + */ + protected static $dependencies = [ + ]; + + /** + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param mixed $data Generic data + * + * @return \Serializable + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function viewCalendarDashboard(RequestAbstract $request, ResponseAbstract $response, $data = null) : \Serializable + { + $view = new View($this->app, $request, $response); + $view->setTemplate('/Modules/Calendar/Theme/Backend/calendar-dashboard'); + $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1001201001, $request, $response)); + + $calendar = CalendarMapper::get(1); + $calendar->setDate(new SmartDateTime($request->getData('date') ?? 'now')); + $view->addData('calendar', $calendar); + + return $view; + } + +} diff --git a/Models/AcceptStatus.php b/Models/AcceptStatus.php new file mode 100644 index 0000000..d0cca10 --- /dev/null +++ b/Models/AcceptStatus.php @@ -0,0 +1,36 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace Modules\Calendar\Models; + +use phpOMS\Datatypes\Enum; + +/** + * Accept status 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 AcceptStatus extends Enum +{ + /* public */ const ACCEPTED = 0; + + /* public */ const DENIED = 1; +} diff --git a/Models/AvailableStatus.php b/Models/AvailableStatus.php new file mode 100644 index 0000000..e6a753a --- /dev/null +++ b/Models/AvailableStatus.php @@ -0,0 +1,38 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace Modules\Calendar\Models; + +use phpOMS\Datatypes\Enum; + +/** + * Available status 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 AvailableStatus extends Enum +{ + /* public */ const AVAILABLE = 0; + + /* public */ const BUSY = 1; + + /* public */ const AWAY = 2; +} diff --git a/Models/Calendar.php b/Models/Calendar.php new file mode 100644 index 0000000..57c30bb --- /dev/null +++ b/Models/Calendar.php @@ -0,0 +1,340 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace Modules\Calendar\Models; + +use phpOMS\Datatypes\SmartDateTime; + +/** + * 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 Calendar +{ + + /** + * Calendar ID. + * + * @var int + * @since 1.0.0 + */ + private $id = 0; + + /** + * Name. + * + * @var string + * @since 1.0.0 + */ + private $name = ''; + + /** + * Description. + * + * @var string + * @since 1.0.0 + */ + private $description = ''; + + /** + * Created at. + * + * @var \Datetime + * @since 1.0.0 + */ + private $createdAt = null; + + /** + * Created by. + * + * @var int + * @since 1.0.0 + */ + private $createdBy = 0; + + /** + * Current date of the calendar. + * + * @var SmartDateTime + * @since 1.0.0 + */ + private $date = null; + + /** + * Password + * + * @var string + * @since 1.0.0 + */ + private $password = null; + + /** + * Events. + * + * @var \Modules\Calendar\Models\Event[] + * @since 1.0.0 + */ + private $events = []; + + /** + * Constructor. + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function __construct() + { + $this->createdAt = new \DateTime('now'); + $this->date = new SmartDateTime('now'); + } + + /** + * @return int + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getId() : int + { + return $this->id; + } + + /** + * @return string + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getName() : string + { + return $this->name; + } + + /** + * @param string $name Calendar name/title + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setName(string $name) + { + $this->name = $name; + } + + /** + * @return string + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getPassword() + { + return $this->password; + } + + /** + * @param string $password Calendar password/title + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setPassword($password) + { + $this->password = $password; + } + + /** + * @return string + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getDescription() : string + { + return $this->description; + } + + /** + * @param string $desc Calendar description + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setDescription(string $desc) + { + $this->description = $desc; + } + + /** + * @param Event $event Calendar event + * + * @return int + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function addEvent(Event $event) : int + { + $this->events[] = $event; + + end($this->events); + $key = key($this->events); + reset($this->events); + + return $key; + } + + /** + * @return Event[] + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getEvents() : array + { + return $this->events; + } + + /** + * @param int $id Event id + * + * @return bool + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function removeEvent(int $id) : bool + { + if (isset($this->events[$id])) { + unset($this->events[$id]); + + return true; + } + + return false; + } + + /** + * @param int $id Event id + * + * @return Event + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getEvent(int $id) : Event + { + return $this->events[$id] ?? new NullEvent(); + } + + /** + * @return \DateTime + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getCreatedAt() : \DateTime + { + return $this->createdAt; + } + + /** + * @param \DateTime $createdAt Calendar created at + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setCreatedAt(\DateTime $createdAt) + { + $this->createdAt = $createdAt; + } + + /** + * @return int + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getCreatedBy() : int + { + return $this->createdBy; + } + + /** + * @param int $createdBy Creator + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setCreatedBy(int $createdBy) + { + $this->createdBy = $createdBy; + } + + /** + * Get current date + * + * @return \DateTime + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getDate() : \DateTime + { + return $this->date; + } + + /** + * Set current date + * + * @param \DateTime $date Current date + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setDate(\DateTime $date) + { + $this->date = $date; + } + + /** + * Get event by date + * + * @param \DateTime $date Date of the event + * + * @return Event[] + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getEventByDate(\DateTime $date) : array + { + $events = []; + foreach ($this->events as $event) { + if ($event->getCreatedAt()->format('Y-m-d') === $date->format('Y-m-d')) { + $events[] = $event; + } + } + + return $events; + } +} diff --git a/Models/CalendarMapper.php b/Models/CalendarMapper.php new file mode 100644 index 0000000..dcb685f --- /dev/null +++ b/Models/CalendarMapper.php @@ -0,0 +1,156 @@ + + * @author Dennis Eichhorn + * @copyright 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; +use phpOMS\DataStorage\Database\RelationType; + +/** + * 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 CalendarMapper extends DataMapperAbstract +{ + /** + * Class name. + * + * @var string + * @since 1.0.0 + */ + protected static $CLASS = __CLASS__; + + /** + * 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' => 'string', 'internal' => 'description'], + 'calendar_created_by' => ['name' => 'calendar_created_by', 'type' => 'int', 'internal' => 'createdBy'], + 'calendar_created_at' => ['name' => 'calendar_created_at', 'type' => 'DateTime', 'internal' => 'createdAt'], + ]; + + /** + * Has many relation. + * + * @var array + * @since 1.0.0 + */ + protected static $hasMany = [ + 'events' => [ + 'mapper' => EventMapper::class, + 'table' => 'calendar_event', + 'dst' => 'calendar_event_calendar', + 'src' => null, + ], + ]; + + /** + * Primary table. + * + * @var string + * @since 1.0.0 + */ + protected static $table = 'calendar'; + + /** + * Created at. + * + * @var string + * @since 1.0.0 + */ + protected static $createdAt = 'calendar_created_at'; + + /** + * Primary field name. + * + * @var string + * @since 1.0.0 + */ + protected static $primaryField = 'calendar_id'; + + /** + * Create object. + * + * @param mixed $obj Object + * @param int $relations Behavior for relations creation + * + * @return mixed + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public static function create($obj, int $relations = RelationType::ALL) + { + try { + $objId = parent::create($obj, $relations); + $query = new Builder(self::$db); + $query->prefix(self::$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); + + self::$db->con->prepare($query->toSql())->execute(); + } catch (\Exception $e) { + return false; + } + + return $objId; + } + + /** + * Find. + * + * @param array $columns Columns to select + * + * @return Builder + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public static function find(...$columns) : Builder + { + return parent::find(...$columns)->from('account_permission') + ->where('account_permission.account_permission_for', '=', 'calendar') + ->where('account_permission.account_permission_id1', '=', 1) + ->where('calendar.calendar_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 new file mode 100644 index 0000000..da69ceb --- /dev/null +++ b/Models/Event.php @@ -0,0 +1,381 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace Modules\Calendar\Models; + +use phpOMS\Account\Account; +use phpOMS\Account\NullAccount; +use phpOMS\Datatypes\Location; + +/** + * Event 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 Event +{ + + /** + * Calendar ID. + * + * @var int + * @since 1.0.0 + */ + private $id = 0; + + /** + * Name. + * + * @var string + * @since 1.0.0 + */ + private $name = ''; + + /** + * Description. + * + * @var string + * @since 1.0.0 + */ + private $description = ''; + + /** + * Created. + * + * @var \Datetime + * @since 1.0.0 + */ + private $createdAt = null; + + /** + * Creator. + * + * @var int + * @since 1.0.0 + */ + private $createdBy = 0; + + /** + * Event type. + * + * Single event or a template (templates have a repeating) + * + * @var int + * @since 1.0.0 + */ + private $type = EventType::SINGLE; + + /** + * Event status. + * + * Active, inactive etc. + * + * @var int + * @since 1.0.0 + */ + private $status = EventStatus::ACTIVE; + + /** + * Schedule + * + * @var Schedule + * @since 1.0.0 + */ + private $schedule = null; + + /** + * Location of the event. + * + * @var Location + * @since 1.0.0 + */ + private $location = null; + + /** + * Calendar + * + * @var int + * @since 1.0.0 + */ + private $calendar = null; + + /** + * People. + * + * @var array + * @since 1.0.0 + */ + private $people = []; + + /** + * Constructor. + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function __construct() + { + $this->createdAt = new \DateTime('now'); + $this->location = new Location(); + $this->schedule = new Schedule(); + } + + /** + * @return int + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getId() : int + { + return $this->id; + } + + /** + * @return string + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getName() : string + { + return $this->name; + } + + /** + * @return Account[] + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getPeople() : array + { + return $this->people; + } + + /** + * @param int $id Account id + * + * @return Account + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getPerson(int $id) : Account + { + return $this->people[$id] ?? new NullAccount(); + } + + /** + * @param Account $person Person to add + * + * @return int Account id/position + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + 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; + } + + /** + * @param string $name Event name/title + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setName(string $name) + { + $this->name = $name; + } + + /** + * @return string + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getDescription() : string + { + return $this->description; + } + + /** + * @param string $desc Event description + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setDescription(string $desc) + { + $this->description = $desc; + } + + /** + * @return \DateTime + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getCreatedAt() : \DateTime + { + return $this->createdAt; + } + + /** + * @param \DateTime $createdAt Event created at + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setCreatedAt(\DateTime $createdAt) + { + $this->createdAt = $createdAt; + } + + /** + * @return int + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getCreatedBy() : int + { + return $this->createdBy; + } + + /** + * @param int $createdBy Creator + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setCreatedBy(int $createdBy) + { + $this->createdBy = $createdBy; + $this->schedule->setCreatedBy($this->createdBy); + } + + /** + * @param Location $location Event location + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setLocation(Location $location) + { + $this->location = $location; + } + + /** + * @return Location + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getLocation() : Location + { + return $this->location; + } + + /** + * @return int + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getCalendar() : int + { + return $this->calendar; + } + + /** + * @return int + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getType() : int + { + return $this->type; + } + + /** + * @return int + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getStatus() : int + { + return $this->status; + } + + /** + * @param int $calendar Calendar + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setCalendar(int $calendar) + { + $this->calendar = $calendar; + } + + /** + * @return Schedule + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getSchedule() : Schedule + { + return $this->schedule; + } +} diff --git a/Models/EventMapper.php b/Models/EventMapper.php new file mode 100644 index 0000000..4b63357 --- /dev/null +++ b/Models/EventMapper.php @@ -0,0 +1,154 @@ + + * @author Dennis Eichhorn + * @copyright 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; +use phpOMS\DataStorage\Database\RelationType; + +/** + * 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 = [ + '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_type' => ['name' => 'calendar_event_type', 'type' => 'int', 'internal' => 'type'], + 'calendar_event_status' => ['name' => 'calendar_event_status', 'type' => 'int', 'internal' => 'status'], + 'calendar_event_schedule' => ['name' => 'calendar_event_schedule', 'type' => 'int', 'internal' => 'schedule'], + 'calendar_event_calendar' => ['name' => 'calendar_event_calendar', 'type' => 'int', 'internal' => 'calendar'], + 'calendar_event_created_by' => ['name' => 'calendar_event_created_by', 'type' => 'int', 'internal' => 'createdBy'], + 'calendar_event_created_at' => ['name' => 'calendar_event_created_at', 'type' => 'DateTime', 'internal' => 'createdAt'], + ]; + + /** + * Has one relation. + * + * @var array + * @since 1.0.0 + */ + protected static $ownsOne = [ + 'schedule' => [ + 'mapper' => ScheduleMapper::class, + 'src' => 'calendar_event_schedule', + ], + ]; + + /** + * Primary table. + * + * @var string + * @since 1.0.0 + */ + protected static $table = 'calendar_event'; + + /** + * Created at. + * + * @var string + * @since 1.0.0 + */ + protected static $createdAt = 'calendar_event_created_at'; + + /** + * Primary field name. + * + * @var string + * @since 1.0.0 + */ + protected static $primaryField = 'calendar_event_id'; + + /** + * Create object. + * + * @param mixed $obj Object + * @param int $relations Behavior for relations creation + * + * @return mixed + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public static function create($obj, int $relations = RelationType::ALL) + { + try { + $objId = parent::create($obj, $relations); + $query = new Builder(self::$db); + + $query->prefix(self::$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); + + self::$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 static 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/EventStatus.php b/Models/EventStatus.php new file mode 100644 index 0000000..772c65d --- /dev/null +++ b/Models/EventStatus.php @@ -0,0 +1,34 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace Modules\Calendar\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 EventStatus extends Enum +{ + /* public */ const ACTIVE = 1; +} diff --git a/Models/EventTemplate.php b/Models/EventTemplate.php new file mode 100644 index 0000000..a3e7911 --- /dev/null +++ b/Models/EventTemplate.php @@ -0,0 +1,38 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace Modules\Calendar\Models; + +/** + * Event template 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 EventTemplate extends Event +{ + /** + * Type. + * + * @var EventType + * @since 1.0.0 + */ + private $type = EventType::TEMPLATE; +} diff --git a/Models/EventType.php b/Models/EventType.php new file mode 100644 index 0000000..ee70765 --- /dev/null +++ b/Models/EventType.php @@ -0,0 +1,36 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace Modules\Calendar\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 +{ + /* public */ const TEMPLATE = 1; + + /* public */ const SINGLE = 2; +} diff --git a/Models/FrequencyInterval.php b/Models/FrequencyInterval.php new file mode 100644 index 0000000..95a0826 --- /dev/null +++ b/Models/FrequencyInterval.php @@ -0,0 +1,43 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace Modules\Calendar\Models; + +use phpOMS\Datatypes\Enum; + +/** + * Frequency interval 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 FrequencyInterval extends Enum +{ + /* public */ const SUNDAY = 1; + /* public */ const MONDAY = 2; + /* public */ const TUESDAY = 4; + /* public */ const WEDNESDAY = 8; + /* public */ const THURSDAY = 16; + /* public */ const FRIDAY = 32; + /* public */ const SATURDAY = 64; + /* public */ const DAY = 128; + /* public */ const WEEKDAY = 256; + /* public */ const WEEKENDDAY = 512; +} diff --git a/Models/FrequencyRelative.php b/Models/FrequencyRelative.php new file mode 100644 index 0000000..a1a5bf1 --- /dev/null +++ b/Models/FrequencyRelative.php @@ -0,0 +1,42 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace Modules\Calendar\Models; + +use phpOMS\Datatypes\Enum; + +/** + * Frequency relative 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 FrequencyRelative extends Enum +{ + /* public */ const FIRST = 1; + + /* public */ const SECOND = 2; + + /* public */ const THIRD = 4; + + /* public */ const FOURTH = 8; + + /* public */ const LAST = 64; +} diff --git a/Models/FrequencyType.php b/Models/FrequencyType.php new file mode 100644 index 0000000..6cb1fc3 --- /dev/null +++ b/Models/FrequencyType.php @@ -0,0 +1,42 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace Modules\Calendar\Models; + +use phpOMS\Datatypes\Enum; + +/** + * Frequency 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 FrequencyType extends Enum +{ + /* public */ const ONCE = 1; + + /* public */ const DAILY = 2; + + /* public */ const WEEKLY = 4; + + /* public */ const MONTHLY = 8; + + /* public */ const YEARLY = 16; +} diff --git a/Models/IntervalType.php b/Models/IntervalType.php new file mode 100644 index 0000000..6fa0930 --- /dev/null +++ b/Models/IntervalType.php @@ -0,0 +1,36 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace Modules\Calendar\Models; + +use phpOMS\Datatypes\Enum; + +/** + * Interval type 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 IntervalType extends Enum +{ + /* public */ const ABSOLUTE = 1; + + /* public */ const RELATIVE = 2; +} diff --git a/Models/NullCalendar.php b/Models/NullCalendar.php new file mode 100644 index 0000000..2904231 --- /dev/null +++ b/Models/NullCalendar.php @@ -0,0 +1,32 @@ + + * @author Dennis Eichhorn + * @copyright 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 NullCalendar extends Calendar +{ + +} diff --git a/Models/NullEvent.php b/Models/NullEvent.php new file mode 100644 index 0000000..abc5248 --- /dev/null +++ b/Models/NullEvent.php @@ -0,0 +1,32 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace Modules\Calendar\Models; + +/** + * Null event 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 NullEvent extends Event +{ + +} diff --git a/Models/NullSchedule.php b/Models/NullSchedule.php new file mode 100644 index 0000000..3bf1d01 --- /dev/null +++ b/Models/NullSchedule.php @@ -0,0 +1,31 @@ + + * @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; + +/** + * Schedule 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 NullSchedule extends Schedule +{ +} diff --git a/Models/Schedule.php b/Models/Schedule.php new file mode 100644 index 0000000..67bc070 --- /dev/null +++ b/Models/Schedule.php @@ -0,0 +1,445 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace Modules\Calendar\Models; + +use phpOMS\Datatypes\Exception\InvalidEnumValue; + +/** + * Schedule 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 Schedule +{ + /** + * Schedule ID. + * + * @var int + * @since 1.0.0 + */ + private $id = 0; + + /** + * Calendar uid. + * + * @var string + * @since 1.0.0 + */ + private $uid = ''; + + /** + * Schedule status. + * + * @var int + * @since 1.0.0 + */ + private $status = ScheduleStatus::ACTIVE; + + /** + * Frequency type. + * + * @var int + * @since 1.0.0 + */ + private $freqType = FrequencyType::ONCE; + + /** + * Frequency interval. + * + * @var int + * @since 1.0.0 + */ + private $freqInterval = FrequencyInterval::DAY; + + /** + * Frequency relative. + * + * @var int + * @since 1.0.0 + */ + private $relativeInternal = FrequencyRelative::FIRST; + + /** + * Interval type. + * + * @var int + * @since 1.0.0 + */ + private $intervalType = IntervalType::ABSOLUTE; + + /** + * Recurrence factor. + * + * @var int + * @since 1.0.0 + */ + private $recurrenceFactor = 0; + + /** + * Start. + * + * @var \DateTime + * @since 1.0.0 + */ + private $start = null; + + /** + * Duration. + * + * @var int + * @since 1.0.0 + */ + private $duration = 3600; + + /** + * End. + * + * @var \DateTime + * @since 1.0.0 + */ + private $end = null; + + /** + * Created at. + * + * @var \DateTime + * @since 1.0.0 + */ + private $createdAt = null; + + /** + * Created by. + * + * @var int + * @since 1.0.0 + */ + private $createdBy = 0; + + /** + * Constructor. + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function __construct() + { + $this->createdAt = new \DateTime('now'); + $this->start = new \DateTime('now'); + $this->end = new \DateTime('now'); + $this->end->setTimestamp($this->end->getTimestamp() + $this->duration); + } + + /** + * @return int + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getId() : int + { + return $this->id; + } + + /** + * @return int + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getStatus() : int + { + return $this->status; + } + + /** + * @param int $status Schedule status + * + * @return $this + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setStatus(int $status) + { + if (!ScheduleStatus::isValidValue($status)) { + throw new InvalidEnumValue($status); + } + + $this->status = $status; + + return $this; + } + + /** + * @return int + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getFreqType() : int + { + return $this->freqType; + } + + /** + * @param int $freqType Frequency type + * + * @return $this + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setFreqType(int $freqType) + { + if (!FrequencyType::isValidValue($freqType)) { + throw new InvalidEnumValue($freqType); + } + + $this->freqType = $freqType; + + return $this; + } + + /** + * @return int + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getIntervalType() : int + { + return $this->intervalType; + } + + /** + * @param int $intervalType Interval type + * + * @return $this + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setIntervalType(int $intervalType) + { + if (!IntervalType::isValidValue($intervalType)) { + throw new InvalidEnumValue($intervalType); + } + + $this->intervalType = $intervalType; + + return $this; + } + + /** + * @return int + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getFrequencyRelative() : int + { + return $this->relativeInternal; + } + + /** + * @param int $relativeInterval Relative interval + * + * @return $this + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setFrequencyRelative(int $relativeInterval) + { + if (!FrequencyRelative::isValidValue($relativeInterval)) { + throw new InvalidEnumValue($relativeInterval); + } + + $this->relativeInternal = $relativeInterval; + + return $this; + } + + /** + * @param int $freqInterval Frequency interval + * + * @return $this + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setFreqInterval(int $freqInterval) + { + if (!FrequencyInterval::isValidValue($freqInterval)) { + throw new InvalidEnumValue($freqInterval); + } + + $this->freqInterval = $freqInterval; + + return $this; + } + + /** + * @return int + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getFreqInterval() : int + { + return $this->freqInterval; + } + + /** + * @return int + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getRecurrenceFactor() : int + { + return $this->recurrenceFactor; + } + + /** + * @param int $recurrence Recurrence + * + * @return $this + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setRecurrenceFactor(int $recurrence) + { + $this->recurrenceFactor = $recurrence; + + return $this; + } + + /** + * @return \DateTime + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getStart() : \DateTime + { + return $this->start; + } + + /** + * @param \DateTime $start Schedule start + * + * @return $this + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setStart(\DateTime $start) + { + $this->start = $start; + + return $this; + } + + /** + * @return int + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getDuration() : int + { + return $this->duration; + } + + /** + * @param int $duration Duration + * + * @return $this + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setDuration(int $duration) + { + if ($duration < 1) { + throw new \InvalidArgumentException($duration); + } + + $this->duration = $duration; + + return $this; + } + + /** + * @return \DateTime + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getEnd() : \DateTime + { + return $this->end; + } + + /** + * @param \DateTime $end Schedule end + * + * @return $this + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setEnd(\DateTime $end) + { + $this->end = $end; + + return $this; + } + + /** + * @param int $creator Creator + * + * @return $this + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setCreatedBy(int $creator) + { + $this->createdBy = $creator; + + return $this; + } + + /** + * @return int + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getCreatedBy() : int + { + return $this->createdBy; + } +} diff --git a/Models/ScheduleMapper.php b/Models/ScheduleMapper.php new file mode 100644 index 0000000..993178d --- /dev/null +++ b/Models/ScheduleMapper.php @@ -0,0 +1,143 @@ + + * @author Dennis Eichhorn + * @copyright 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; +use phpOMS\DataStorage\Database\RelationType; + +/** + * 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 ScheduleMapper extends DataMapperAbstract +{ + + /** + * Columns. + * + * @var array + * @since 1.0.0 + */ + protected static $columns = [ + 'schedule_id' => ['name' => 'schedule_id', 'type' => 'int', 'internal' => 'id'], + 'schedule_uid' => ['name' => 'schedule_uid', 'type' => 'string', 'internal' => 'uid'], + 'schedule_status' => ['name' => 'schedule_status', 'type' => 'int', 'internal' => 'status'], + 'schedule_freq_type' => ['name' => 'schedule_freq_type', 'type' => 'int', 'internal' => 'freqType'], + 'schedule_freq_interval' => ['name' => 'schedule_freq_interval', 'type' => 'int', 'internal' => 'freqInterval'], + 'schedule_freq_interval_type' => ['name' => 'schedule_freq_interval_type', 'type' => 'int', 'internal' => 'intervalType'], + 'schedule_freq_relative_interval' => ['name' => 'schedule_freq_relative_interval', 'type' => 'int', 'internal' => 'relativeInternal'], + 'schedule_freq_recurrence_factor' => ['name' => 'schedule_freq_recurrence_factor', 'type' => 'int', 'internal' => 'recurrenceFactor'], + 'schedule_start' => ['name' => 'schedule_start', 'type' => 'DateTime', 'internal' => 'start'], + 'schedule_duration' => ['name' => 'schedule_duration', 'type' => 'int', 'internal' => 'duration'], + 'schedule_end' => ['name' => 'schedule_end', 'type' => 'DateTime', 'internal' => 'end'], + 'schedule_created_at' => ['name' => 'schedule_created_at', 'type' => 'DateTime', 'internal' => 'createdAt'], + 'schedule_created_by' => ['name' => 'schedule_created_by', 'type' => 'int', 'internal' => 'createdBy'], + ]; + + /** + * Primary table. + * + * @var string + * @since 1.0.0 + */ + protected static $table = 'schedule'; + + /** + * Created at. + * + * @var string + * @since 1.0.0 + */ + protected static $createdAt = 'schedule_created_at'; + + /** + * Primary field name. + * + * @var string + * @since 1.0.0 + */ + protected static $primaryField = 'schedule_id'; + + /** + * Create object. + * + * @param mixed $obj Object + * @param int $relations Behavior for relations creation + * + * @return mixed + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public static function create($obj, int $relations = RelationType::ALL) + { + try { + $objId = parent::create($obj, $relations); + $query = new Builder(self::$db); + $query->prefix(self::$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(), 'schedule', 'schedule', 1, $objId, 1, 1, 1, 1, 1); + + self::$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 static function find(...$columns) : Builder + { + return parent::find(...$columns)->from('account_permission') + ->where('account_permission.account_permission_for', '=', 'calendar') + ->where('account_permission.account_permission_id1', '=', 1) + ->where('calendar.calendar_id', '=', new Column('account_permission.account_permission_id2')) + ->where('account_permission.account_permission_r', '=', 1); + } +} diff --git a/Models/ScheduleStatus.php b/Models/ScheduleStatus.php new file mode 100644 index 0000000..9734714 --- /dev/null +++ b/Models/ScheduleStatus.php @@ -0,0 +1,35 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +namespace Modules\Calendar\Models; + +use phpOMS\Datatypes\Enum; + +/** + * Schedule status 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 ScheduleStatus extends Enum +{ + /* public */ const ACTIVE = 1; + /* public */ const INACTIVE = 1; +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..cad79ea --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# Calendar # diff --git a/Theme/Backend/Lang/Navigation.en.lang.php b/Theme/Backend/Lang/Navigation.en.lang.php new file mode 100644 index 0000000..17b9e61 --- /dev/null +++ b/Theme/Backend/Lang/Navigation.en.lang.php @@ -0,0 +1,18 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +return ['Navigation' => [ + 'Calendar' => 'Calendar', +]]; diff --git a/Theme/Backend/Lang/api.en.lang.php b/Theme/Backend/Lang/api.en.lang.php new file mode 100644 index 0000000..afe845f --- /dev/null +++ b/Theme/Backend/Lang/api.en.lang.php @@ -0,0 +1,17 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +$MODLANG[1] = [ +]; diff --git a/Theme/Backend/Lang/en.lang.php b/Theme/Backend/Lang/en.lang.php new file mode 100644 index 0000000..b69a962 --- /dev/null +++ b/Theme/Backend/Lang/en.lang.php @@ -0,0 +1,28 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +return ['Calendar' => [ + 'Blocks' => 'Blocks', + 'Day' => 'Day', + 'Interval' => 'Interval', + 'Layout' => 'Layout', + 'List' => 'List', + 'Month' => 'Month', + 'NewEvent' => 'New Event', + 'Settings' => 'Settings', + 'Timeline' => 'Timeline', + 'Week' => 'Week', + 'Year' => 'Year', +]]; diff --git a/Theme/Backend/calendar-create.tpl.php b/Theme/Backend/calendar-create.tpl.php new file mode 100644 index 0000000..e69de29 diff --git a/Theme/Backend/calendar-dashboard.tpl.php b/Theme/Backend/calendar-dashboard.tpl.php new file mode 100644 index 0000000..3f4ad3b --- /dev/null +++ b/Theme/Backend/calendar-dashboard.tpl.php @@ -0,0 +1,104 @@ +getData('calendar'); +?> +
+ +
+
+ getDate()->format('Y') . '-' . $calendar->getDate()->format('m') . '-' . '01'); for($i = 0; $i < 6; $i++) : ?> +
+ +
+ getDate()->getFirstDayOfMonth() <= $i*7+$j+1 && $calendar->getDate()->getDaysOfMonth() >= $i*7+$j+1) { + echo ($i*7+$j+1) . ' ' . jddayofweek($j, 1); + } else { + echo $current->createModify(0, 0, -2)->format('d') . ' ' . jddayofweek($j, 1); + } ?> +
    + getEventByDate($current); + $current->smartModify(0, 0, 1); + foreach($events as $event) : ?> +
  • getName(); ?> + +
+
+ +
+ +
+
+
+ +
+
+

Title

+ +
+
+ + + +
+
+
+
+
+
+ +
+

Calendars

+ +
+
    +
  • +
+
+ +
+
+
+ + + + + + + + + + + + + + diff --git a/Theme/Backend/calendar-element-create.tpl.php b/Theme/Backend/calendar-element-create.tpl.php new file mode 100644 index 0000000..e69de29 diff --git a/Theme/Backend/calendar-element-single.tpl.php b/Theme/Backend/calendar-element-single.tpl.php new file mode 100644 index 0000000..e69de29 diff --git a/Theme/Backend/calendar-single.tpl.php b/Theme/Backend/calendar-single.tpl.php new file mode 100644 index 0000000..e69de29 diff --git a/Theme/Backend/dashboard-calendar.tpl.php b/Theme/Backend/dashboard-calendar.tpl.php new file mode 100644 index 0000000..1b4bc6b --- /dev/null +++ b/Theme/Backend/dashboard-calendar.tpl.php @@ -0,0 +1,3 @@ +
+ Calendar +
\ No newline at end of file diff --git a/img/module_teaser_small.png b/img/module_teaser_small.png new file mode 100644 index 0000000..f56e6ff Binary files /dev/null and b/img/module_teaser_small.png differ diff --git a/info.json b/info.json new file mode 100644 index 0000000..6f2b88a --- /dev/null +++ b/info.json @@ -0,0 +1,44 @@ +{ + "name": { + "id": 1000900000, + "internal": "Calendar", + "external": "OMS Calendar" + }, + "version": "1.0.0", + "requirements": { + "phpOMS": "1.0.0", + "phpOMS-db": "1.0.0" + }, + "creator": { + "name": "Orange Management", + "website": "www.spl1nes.com" + }, + "description": "Calendar module.", + "directory": "Calendar", + "dependencies": { + "Admin" : "1.0.0" + }, + "providing": { + "Navigation": "*" + }, + "load": [ + { + "pid": [ + "fb78d7e421e4178d31a384fb394dcf2369fff309" + ], + "type": 4, + "for": "Content", + "from": "Calendar", + "file": "Calendar" + }, + { + "pid": [ + "754a08ddf8bcb1cf22f310f09206dd783d42f7dd" + ], + "type": 5, + "from": "Calendar", + "for": "Navigation", + "file": "Navigation" + } + ] +} diff --git a/js/Calendar.js b/js/Calendar.js new file mode 100644 index 0000000..827c973 --- /dev/null +++ b/js/Calendar.js @@ -0,0 +1,21 @@ +(function (omsModule, undefined) { + omsModule.Calendar = function () { + this.layout = omsModule.Calendar.layout.BLOCKS; + this.interval = null; + this.selectedElement = null; + this.subCalendars = []; + + }; + + omsModule.Calendar.prototype.render = function () { + }; + + omsModule.Calendar.prototype.renderBlocks = function () { + }; + + omsModule.Calendar.prototype.renderList = function () { + }; + + omsModule.Calendar.prototype.renderTimeline = function () { + }; +}(window.omsModule = window.omsModule || {})); \ No newline at end of file diff --git a/js/CalendarPreview.js b/js/CalendarPreview.js new file mode 100644 index 0000000..e69de29 diff --git a/js/CalendarSub.js b/js/CalendarSub.js new file mode 100644 index 0000000..e69de29 diff --git a/js/Controller.js b/js/Controller.js new file mode 100644 index 0000000..e69de29 diff --git a/js/IntervalEnum.js b/js/IntervalEnum.js new file mode 100644 index 0000000..e69de29 diff --git a/js/LayoutEnum.js b/js/LayoutEnum.js new file mode 100644 index 0000000..e69de29