Implementing new schedule class/table. Schedule can be used for many other modules and objects.

This commit is contained in:
Dennis Eichhorn 2016-02-11 21:09:52 +01:00
parent 92ea2775e9
commit 9a27c8bfba
15 changed files with 684 additions and 14 deletions

View File

@ -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(

View File

@ -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'];
}
}

View File

@ -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;
}
}

View File

@ -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
*

32
Models/EventTemplate.php Normal file
View File

@ -0,0 +1,32 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @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 <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class EventTemplate extends Event
{
private $type = EventType::TEMPLATE;
}

36
Models/EventType.php Normal file
View File

@ -0,0 +1,36 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @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 <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @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;
}

View File

@ -0,0 +1,43 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @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 <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @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;
}

View File

@ -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;
}

42
Models/FrequencyType.php Normal file
View File

@ -0,0 +1,42 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @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 <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @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;
}

36
Models/IntervalType.php Normal file
View File

@ -0,0 +1,36 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @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 <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @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;
}

215
Models/Schedule.php Normal file
View File

@ -0,0 +1,215 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @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 <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @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;
}
}

127
Models/ScheduleMapper.php Normal file
View File

@ -0,0 +1,127 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @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<string, 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 <d.eichhorn@oms.com>
*/
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 <d.eichhorn@oms.com>
*/
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);
}
}

35
Models/ScheduleStatus.php Normal file
View File

@ -0,0 +1,35 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @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 <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @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;
}

View File

@ -20,6 +20,7 @@ $MODLANG['Calendar'] = [
'Layout' => 'Layout',
'List' => 'List',
'Month' => 'Month',
'NewEvent' => 'New Event',
'Settings' => 'Settings',
'Timeline' => 'Timeline',
'Week' => 'Week',

View File

@ -1,3 +1,6 @@
<?php
$calendar = new \Modules\Calendar\Models\Calendar();
?>
<section class="wf-75 floatLeft">
<section class="box w-100">
<ul class="btns floatLeft">
@ -14,9 +17,17 @@
<section class="box w-100">
<div class="m-calendar-month">
<?php for($i = 0; $i < 6; $i++) : ?>
<div class="wf-100">
<?php for($j = 0; $j < 7; $j++) : ?><div style="display: inline-block; box-sizing: border-box; width: 14.28%; height: 100px; border: 1px solid #000; margin: 0; padding: 3px;"><?= $this->l11n->lang[0][jddayofweek($j, 1)]; ?></div><?php endfor; ?>
</div>
<div class="wf-100">
<?php for($j = 0; $j < 7; $j++) : ?>
<div contextmenu="calendar-day-menu" style="display: inline-block; box-sizing: border-box; width: 13.0%; height: 100px; border: 1px solid #000; margin: 0; padding: 3px;">
<?php if($calendar->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());
} ?>
</div>
<?php endfor; ?>
</div>
<?php endfor;?>
</div>
</section>
@ -45,10 +56,41 @@
<div class="inner">
<ul class="boxed">
<li><i class="fa fa-times warning"></i> <span class="check"><input type="checkbox" id="iDefault" checked><label for="iDefault">Default</label></span>
<li><i class="fa fa-times warning"></i> <span class="check"><input type="checkbox" id="iDefault" checked><label for="iDefault">Default</label></span><i class="fa fa-cogs floatRight"></i>
</ul>
<div class="spacer"></div>
<button><i class="fa fa-calendar-plus-o"></i> <?= $this->l11n->lang[0]['Add'] ?></button> <button><i class="fa fa-calendar-check-o"></i> <?= $this->l11n->lang[0]['Create'] ?></button>
</div>
</section>
</section>
<menu type="context" id="calendar-day-menu">
<menuitem label="<?= $this->l11n->lang['Calendar']['NewEvent'] ?>"></menuitem>
</menu>
<menu type="context" id="calendar-event-menu">
<menuitem label="Edit"></menuitem>
<menuitem label="Accept" disabled></menuitem>
<menuitem label="Re-Schedule"></menuitem>
<menuitem label="Decline"></menuitem>
<menuitem label="Delete"></menuitem>
</menu>
<div class="hidden">
<section class="box">
<div class="inner">
<form>
<table class="layout">
<tr><td><label for="iTitle">Title</label>
<tr><td><input type="text" id="">
<tr><td><label for="iTitle">Description</label>
<tr><td><textarea></textarea>
<tr><td><label for="iTitle">To</label>
<tr><td><input type="text" id="">
<tr><td><label for="iTitle">Files</label>
<tr><td><input type="text" id="">
</table>
</form>
</div>
</section>
</div>