diff --git a/Admin/Installer.php b/Admin/Installer.php index ecc2f3d..fd3e42b 100644 --- a/Admin/Installer.php +++ b/Admin/Installer.php @@ -77,6 +77,25 @@ class Installer extends InstallerAbstract ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'calendar_permission_ibfk_2` 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, + `scheule_created_at` datetime NOT NULL, + `scheule_created_by` int(11) NOT NULL, + PRIMARY KEY (`schedule_id`) + )ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;' + )->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, @@ -86,6 +105,7 @@ class Installer extends InstallerAbstract `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) NOT NULL, PRIMARY KEY (`calendar_event_id`), KEY `calendar_event_created_by` (`calendar_event_created_by`), @@ -96,7 +116,8 @@ class Installer extends InstallerAbstract $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_calendar`) REFERENCES `' . $dbPool->get('core')->prefix . 'calendar` (`calendar_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( diff --git a/Models/Calendar.php b/Models/Calendar.php index 2b07aef..e3840ac 100644 --- a/Models/Calendar.php +++ b/Models/Calendar.php @@ -69,6 +69,8 @@ class Calendar */ private $createdBy = 0; + private $date = null; + /** * Events. * @@ -80,6 +82,7 @@ class Calendar public function __construct() { $this->createdAt = new \DateTime('now'); + $this->date = new \DateTime('now'); } public function getId() : int @@ -158,4 +161,20 @@ class Calendar { $this->createdBy = $createdBy; } + + public function getDate() : \DateTime { + return $this->date; + } + + public function setDate(\DateTime $date) { + $this->date = $date; + } + + public function getDaysOfMonth() : int { + return cal_days_in_month(CAL_GREGORIAN, $this->date->format('m'), $this->date->format('Y')); + } + + public function getFirstDay() { + return getdate(mktime(null, null, null, $this->date->format('m'), 1, $this->date->format('Y')))['wday']; + } } diff --git a/Models/Event.php b/Models/Event.php index f876e80..d33e29b 100644 --- a/Models/Event.php +++ b/Models/Event.php @@ -73,6 +73,10 @@ class Event */ private $createdBy = 0; + private $type = EventType::SINGLE; + + private $schedule = null; + /** * People. * @@ -95,6 +99,7 @@ class Event { $this->createdAt = new \DateTime('now'); $this->location = new Location(); + $this->schedule = new Schedule(); } public function getId() : int @@ -199,8 +204,17 @@ class Event return $this->calendar; } + public function getType() : int + { + return $this->type; + } + public function setCalendar(int $calendar) { $this->calendar = $calendar; } + + public function getSchedule() : Schedule { + return $this->schedule; + } } diff --git a/Models/EventMapper.php b/Models/EventMapper.php index cc06b39..b3eb068 100644 --- a/Models/EventMapper.php +++ b/Models/EventMapper.php @@ -33,12 +33,21 @@ class EventMapper extends DataMapperAbstract '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'], ]; + protected static $hasOne = [ + 'schedule' => [ + 'mapper' => '\Modules\Calendar\Models\ScheduleMapper', + 'src' => 'calendar_event_schedule', + ], + ]; + /** * Primary table. * @@ -60,7 +69,7 @@ class EventMapper extends DataMapperAbstract /** * Create media. * - * @param Calendar $obj Media + * @param Event $obj Media * * @return bool * diff --git a/Models/EventTemplate.php b/Models/EventTemplate.php new file mode 100644 index 0000000..27b20d0 --- /dev/null +++ b/Models/EventTemplate.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 EventTemplate extends Event +{ + private $type = EventType::TEMPLATE; +} diff --git a/Models/EventType.php b/Models/EventType.php new file mode 100644 index 0000000..8315021 --- /dev/null +++ b/Models/EventType.php @@ -0,0 +1,36 @@ + + * @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\Datatypes\Enum; + +/** + * Occurrence type enum. + * + * @category OccurrenceType + * @package Framework + * @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 TEMPLATE = 1; + + const SINGLE = 2; +} diff --git a/Models/FrequencyInterval.php b/Models/FrequencyInterval.php new file mode 100644 index 0000000..55564c1 --- /dev/null +++ b/Models/FrequencyInterval.php @@ -0,0 +1,43 @@ + + * @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\Datatypes\Enum; + +/** + * Occurrence type enum. + * + * @category OccurrenceType + * @package Framework + * @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 +{ + const SUNDAY = 1; + const MONDAY = 2; + const TUESDAY = 4; + const WEDNESDAY = 8; + const THURSDAY = 16; + const FRIDAY = 32; + const SATURDAY = 64; + const DAY = 128; + const WEEKDAY = 256; + const WEEKENDDAY = 512; +} diff --git a/Models/OccurrenceType.php b/Models/FrequencyRelative.php similarity index 79% rename from Models/OccurrenceType.php rename to Models/FrequencyRelative.php index 2a3671c..5dd5718 100644 --- a/Models/OccurrenceType.php +++ b/Models/FrequencyRelative.php @@ -28,17 +28,15 @@ use phpOMS\Datatypes\Enum; * @link http://orange-management.com * @since 1.0.0 */ -abstract class OccurrenceType extends Enum +abstract class FrequencyRelative extends Enum { - const SINGLE = 0; + const FIRST = 1; - const DAILY = 1; + const SECOND = 2; - const WEEKLY = 2; + const THIRD = 4; - const MONTHLY = 3; + const FOURTH = 8; - const QUARTERLY = 4; - - const YEARLY = 5; + const LAST = 64; } diff --git a/Models/FrequencyType.php b/Models/FrequencyType.php new file mode 100644 index 0000000..95370f9 --- /dev/null +++ b/Models/FrequencyType.php @@ -0,0 +1,42 @@ + + * @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\Datatypes\Enum; + +/** + * Occurrence type enum. + * + * @category OccurrenceType + * @package Framework + * @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 +{ + const ONCE = 1; + + const DAILY = 2; + + const WEEKLY = 4; + + const MONTHLY = 8; + + const YEARLY = 16; +} diff --git a/Models/IntervalType.php b/Models/IntervalType.php new file mode 100644 index 0000000..c6c52ad --- /dev/null +++ b/Models/IntervalType.php @@ -0,0 +1,36 @@ + + * @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\Datatypes\Enum; + +/** + * Occurrence type enum. + * + * @category OccurrenceType + * @package Framework + * @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 +{ + const ABSOLUTE = 1; + + const RELATIVE = 2; +} diff --git a/Models/Schedule.php b/Models/Schedule.php new file mode 100644 index 0000000..b7de80f --- /dev/null +++ b/Models/Schedule.php @@ -0,0 +1,215 @@ + + * @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\Datatypes\Exception\InvalidEnumValue; + +/** + * Schedule 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 Schedule +{ + private $id = 0; + + private $uid = ''; + + private $status = ScheduleStatus::ACTIVE; + + private $freqType = FrequencyType::ONCE; + + private $freqInterval = FrequencyInterval::DAY; + + private $relativeInternal = FrequencyRelative::FIRST; + + private $intervalType = IntervalType::ABSOLUTE; + + private $recurrenceFactor = 0; + + private $start = null; + + private $duration = 3600; + + private $end = null; + + private $createdAt = null; + + private $createdBy = 0; + + 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); + } + + public function getId() : int + { + return $this->id; + } + + public function getStatus() : int + { + return $this->status; + } + + public function setStatus(int $status) + { + if (!ScheduleStatus::isValidValue($status)) { + throw new InvalidEnumValue($status); + } + + $this->status = $status; + + return $this; + } + + public function getFreqType() : int + { + return $this->freqType; + } + + public function setFreqType(int $freqType) + { + if (!FrequencyType::isValidValue($freqType)) { + throw new InvalidEnumValue($freqType); + } + + $this->freqType = $freqType; + + return $this; + } + + public function getIntervalType() : int + { + return $this->intervalType; + } + + public function setIntervalType(int $intervalType) + { + if (!IntervalType::isValidValue($intervalType)) { + throw new InvalidEnumValue($intervalType); + } + + $this->intervalType = $intervalType; + + return $this; + } + + public function getFrequencyRelative() : int + { + return $this->relativeInternal; + } + + public function setFrequencyRelative(int $relativeInternal) + { + if (!FrequencyRelative::isValidValue($relativeInternal)) { + throw new InvalidEnumValue($relativeInternal); + } + + $this->relativeInternal = $relativeInternal; + + return $this; + } + + public function setFreqInterval(int $freqInterval) + { + if (!FrequencyInterval::isValidValue($freqInterval)) { + throw new InvalidEnumValue($freqInterval); + } + + $this->freqInterval = $freqInterval; + + return $this; + } + + public function getFreqInterval() : int + { + return $this->freqInterval; + } + + public function getRecurrenceFactor() : int + { + return $this->recurrenceFactor; + } + + public function setRecurrenceFactor(int $recurrence) + { + $this->recurrenceFactor = $recurrence; + + return $this; + } + + public function getStart() : \DateTime + { + return $this->start; + } + + public function setStart(\DateTime $start) + { + $this->start = $start; + + return $this; + } + + public function getDuration() : int + { + return $this->duration; + } + + public function setDuration(int $duration) + { + if($duration < 1) { + throw new \InvalidArgumentException($duration); + } + + $this->duration = $duration; + + return $this; + } + + public function getEnd() : \DateTime + { + return $this->end; + } + + public function setEnd(\DateTime $end) + { + $this->end = $end; + + return $this; + } + + public function setCreatedBy(int $creator) + { + $this->createdBy = $creator; + + return $this; + } + + public function getCreatedBy() : int + { + return $this->createdBy; + } +} diff --git a/Models/ScheduleMapper.php b/Models/ScheduleMapper.php new file mode 100644 index 0000000..c5676f7 --- /dev/null +++ b/Models/ScheduleMapper.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 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'], + 'scheule_created_at' => ['name' => 'scheule_created_at', 'type' => 'DateTime', 'internal' => 'createdAt'], + 'scheule_created_by' => ['name' => 'scheule_created_by', 'type' => 'int', 'internal' => 'createdBy'], + ]; + + protected static $hasMany = [ + ]; + + /** + * Primary table. + * + * @var string + * @since 1.0.0 + */ + protected static $table = 'schedule'; + + protected static $createdAt = 'schedule_created_at'; + + /** + * Primary field name. + * + * @var string + * @since 1.0.0 + */ + protected static $primaryField = 'schedule_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); + + 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') + ->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..b754887 --- /dev/null +++ b/Models/ScheduleStatus.php @@ -0,0 +1,35 @@ + + * @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\Datatypes\Enum; + +/** + * Occurrence type enum. + * + * @category OccurrenceType + * @package Framework + * @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 +{ + const ACTIVE = 1; + const INACTIVE = 1; +} diff --git a/Theme/backend/Lang/en.lang.php b/Theme/backend/Lang/en.lang.php index 9f9c9fc..5823ee1 100644 --- a/Theme/backend/Lang/en.lang.php +++ b/Theme/backend/Lang/en.lang.php @@ -20,6 +20,7 @@ $MODLANG['Calendar'] = [ 'Layout' => 'Layout', 'List' => 'List', 'Month' => 'Month', + 'NewEvent' => 'New Event', 'Settings' => 'Settings', 'Timeline' => 'Timeline', 'Week' => 'Week', diff --git a/Theme/backend/calendar-dashboard.tpl.php b/Theme/backend/calendar-dashboard.tpl.php index 11fc5a4..05386fb 100644 --- a/Theme/backend/calendar-dashboard.tpl.php +++ b/Theme/backend/calendar-dashboard.tpl.php @@ -1,3 +1,6 @@ +
    @@ -14,9 +17,17 @@
    -
    -
    l11n->lang[0][jddayofweek($j, 1)]; ?>
    -
    +
    + +
    + getFirstDay() <= $i*7+$j+1 && $calendar->getDaysOfMonth() >= $i*7+$j+1) { + echo ($i*7+$j+1) . ' ' . $this->l11n->lang[0][jddayofweek($j, 1)]; + } else { + echo (($i*7+$j+1)-$calendar->getDaysOfMonth()); + } ?> +
    + +
    @@ -45,10 +56,41 @@
      -
    • +
+ + + + + + + + + + + + + +