Calendar doc comments

This commit is contained in:
Dennis Eichhorn 2016-02-11 22:29:33 +01:00
parent 9a27c8bfba
commit a6ef9561af
14 changed files with 590 additions and 48 deletions

View File

@ -14,6 +14,7 @@
* @link http://orange-management.com
*/
namespace Modules\Calendar\Models;
use phpOMS\Datatypes\SmartDateTime;
/**
* Calendar class.
@ -69,6 +70,12 @@ class Calendar
*/
private $createdBy = 0;
/**
* Current date of the calendar.
*
* @var \DateTime
* @since 1.0.0
*/
private $date = null;
/**
@ -79,37 +86,81 @@ class Calendar
*/
private $events = [];
/**
* Constructor.
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function __construct()
{
$this->createdAt = new \DateTime('now');
$this->date = new \DateTime('now');
$this->date = new SmartDateTime('now');
}
/**
* @return int
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getId() : int
{
return $this->id;
}
/**
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getName() : string
{
return $this->name;
}
/**
* @param string $name Calendar name/title
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setName(string $name)
{
$this->name = $name;
}
/**
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getDescription() : string
{
return $this->description;
}
/**
* @param string $desc Calendar description
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setDescription(string $desc)
{
$this->description = $desc;
}
/**
* @param Event $event Calendar event
*
* @return int
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function addEvent(Event $event) : int
{
$this->events[] = $event;
@ -121,12 +172,26 @@ class Calendar
return $key;
}
/**
* @return Event[]
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getEvents() : array
{
return $this->events;
}
public function removeEvent($id) : bool
/**
* @param int $id Event id
*
* @return bool
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function removeEvent(int $id) : bool
{
if (isset($this->events[$id])) {
unset($this->events[$id]);
@ -137,44 +202,86 @@ class Calendar
return false;
}
public function getEvent($id) : Event
/**
* @param int $id Event id
*
* @return Event
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getEvent(int $id) : Event
{
return $this->events[$id] ?? new NullEvent();
}
/**
* @return \DateTime
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getCreatedAt() : \DateTime
{
return $this->createdAt;
}
/**
* @param \DateTime $createdAt Calendar created at
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setCreatedAt(\DateTime $createdAt)
{
$this->createdAt = $createdAt;
}
/**
* @return int
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getCreatedBy() : int
{
return $this->createdBy;
}
/**
* @param int $createdBy Creator
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setCreatedBy(int $createdBy)
{
$this->createdBy = $createdBy;
}
public function getDate() : \DateTime {
/**
* Get current date
*
* @return \DateTime
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getDate() : \DateTime
{
return $this->date;
}
public function setDate(\DateTime $date) {
/**
* Set current date
*
* @param \DateTime $date Current date
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
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

@ -19,6 +19,17 @@ use phpOMS\DataStorage\Database\DataMapperAbstract;
use phpOMS\DataStorage\Database\Query\Builder;
use phpOMS\DataStorage\Database\Query\Column;
/**
* Mapper class.
*
* @category Calendar
* @package Modules
* @author OMS Development Team <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 CalendarMapper extends DataMapperAbstract
{
@ -37,6 +48,12 @@ class CalendarMapper extends DataMapperAbstract
'calendar_created_at' => ['name' => 'calendar_created_at', 'type' => 'DateTime', 'internal' => 'createdAt'],
];
/**
* Has many relation.
*
* @var array<string, array>
* @since 1.0.0
*/
protected static $hasMany = [
'events' => [
'mapper' => '\Modules\Calendar\Models\EventMapper',
@ -55,6 +72,12 @@ class CalendarMapper extends DataMapperAbstract
*/
protected static $table = 'calendar';
/**
* Created at.
*
* @var string
* @since 1.0.0
*/
protected static $createdAt = 'calendar_created_at';
/**

View File

@ -20,7 +20,7 @@ use phpOMS\Account\NullAccount;
use phpOMS\Datatypes\Location;
/**
* Calendar class.
* Event class.
*
* @category Calendar
* @package Framework
@ -73,18 +73,38 @@ class Event
*/
private $createdBy = 0;
/**
* Event type.
*
* Single event or a template (templates have a repeating)
*
* @var int
* @since 1.0.0
*/
private $type = EventType::SINGLE;
/**
* Schedule
*
* @var Schedule
* @since 1.0.0
*/
private $schedule = null;
/**
* People.
* Location of the event.
*
* @var array
* @since 1.0.0
*/
private $location = null;
/**
* Calendar
*
* @var int
* @since 1.0.0
*/
private $calendar = 0;
/**
@ -95,33 +115,73 @@ class Event
*/
private $people = [];
/**
* Constructor.
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function __construct()
{
$this->createdAt = new \DateTime('now');
$this->location = new Location();
$this->schedule = new Schedule();
$this->schedule = new Schedule();
}
/**
* @return int
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getId() : int
{
return $this->id;
}
/**
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getName() : string
{
return $this->name;
}
/**
* @return Account[]
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getPeople() : array
{
return $this->people;
}
/**
* @param int $id Account id
*
* @return Account
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
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 <d.eichhorn@oms.com>
*/
public function addPerson(Account $person)
{
$this->people[] = $person;
@ -154,67 +214,146 @@ class Event
return false;
}
/**
* @param string $name Event name/title
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setName(string $name)
{
$this->name = $name;
}
/**
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getDescription() : string
{
return $this->description;
}
/**
* @param string $desc Event description
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setDescription(string $desc)
{
$this->description = $desc;
}
/**
* @return \DateTime
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getCreatedAt() : \DateTime
{
return $this->createdAt;
}
/**
* @param \DateTime $createdAt Event created at
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setCreatedAt(\DateTime $createdAt)
{
$this->createdAt = $createdAt;
}
/**
* @return int
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getCreatedBy() : int
{
return $this->createdBy;
}
/**
* @param int $createdBy Creator
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setCreatedBy(int $createdBy)
{
$this->createdBy = $createdBy;
}
/**
* @param Location $location Event location
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setLocation(Location $location)
{
$this->location = $location;
}
/**
* @return Location
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getLocation() : Location
{
return $this->location;
}
/**
* @return int
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getCalendar() : int
{
return $this->calendar;
}
/**
* @return int
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getType() : int
{
return $this->type;
}
/**
* @param int $calendar Calendar
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setCalendar(int $calendar)
{
$this->calendar = $calendar;
}
public function getSchedule() : Schedule {
/**
* @return Schedule
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getSchedule() : Schedule
{
return $this->schedule;
}
}

View File

@ -19,6 +19,17 @@ use phpOMS\DataStorage\Database\DataMapperAbstract;
use phpOMS\DataStorage\Database\Query\Builder;
use phpOMS\DataStorage\Database\Query\Column;
/**
* Mapper class.
*
* @category Calendar
* @package Modules
* @author OMS Development Team <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 EventMapper extends DataMapperAbstract
{
@ -41,6 +52,12 @@ class EventMapper extends DataMapperAbstract
'calendar_event_created_at' => ['name' => 'calendar_event_created_at', 'type' => 'DateTime', 'internal' => 'createdAt'],
];
/**
* Has one relation.
*
* @var array<string, array>
* @since 1.0.0
*/
protected static $hasOne = [
'schedule' => [
'mapper' => '\Modules\Calendar\Models\ScheduleMapper',
@ -56,6 +73,12 @@ class EventMapper extends DataMapperAbstract
*/
protected static $table = 'calendar_event';
/**
* Created at.
*
* @var string
* @since 1.0.0
*/
protected static $createdAt = 'calendar_event_created_at';
/**

View File

@ -16,10 +16,10 @@
namespace Modules\Calendar\Models;
/**
* Calendar class.
* Event template class.
*
* @category Calendar
* @package Framework
* @package Modules
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
@ -28,5 +28,11 @@ namespace Modules\Calendar\Models;
*/
class EventTemplate extends Event
{
/**
* Type.
*
* @var EventType
* @since 1.0.0
*/
private $type = EventType::TEMPLATE;
}

View File

@ -18,10 +18,10 @@ namespace Modules\Calendar\Models;
use phpOMS\Datatypes\Enum;
/**
* Occurrence type enum.
* Event type enum.
*
* @category OccurrenceType
* @package Framework
* @category Calendar
* @package Modules
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0

View File

@ -18,10 +18,10 @@ namespace Modules\Calendar\Models;
use phpOMS\Datatypes\Enum;
/**
* Occurrence type enum.
* Frequency interval type enum.
*
* @category OccurrenceType
* @package Framework
* @category Calendar
* @package Modules
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0

View File

@ -18,10 +18,10 @@ namespace Modules\Calendar\Models;
use phpOMS\Datatypes\Enum;
/**
* Occurrence type enum.
* Frequency relative type enum.
*
* @category OccurrenceType
* @package Framework
* @category Calendar
* @package Modules
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0

View File

@ -18,10 +18,10 @@ namespace Modules\Calendar\Models;
use phpOMS\Datatypes\Enum;
/**
* Occurrence type enum.
* Frequency type enum.
*
* @category OccurrenceType
* @package Framework
* @category Calendar
* @package Modules
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0

View File

@ -18,10 +18,10 @@ namespace Modules\Calendar\Models;
use phpOMS\Datatypes\Enum;
/**
* Occurrence type enum.
* Interval type type enum.
*
* @category OccurrenceType
* @package Framework
* @category Calendar
* @package Modules
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0

View File

@ -16,10 +16,10 @@
namespace Modules\Calendar\Models;
/**
* Calendar class.
* Null event class.
*
* @category Calendar
* @package Framework
* @package Modules
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0

View File

@ -21,7 +21,7 @@ use phpOMS\Datatypes\Exception\InvalidEnumValue;
* Schedule class.
*
* @category Calendar
* @package Framework
* @package Modules
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
@ -30,32 +30,116 @@ use phpOMS\Datatypes\Exception\InvalidEnumValue;
*/
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 <d.eichhorn@oms.com>
*/
public function __construct()
{
$this->createdAt = new \DateTime('now');
@ -64,16 +148,36 @@ class Schedule
$this->end->setTimestamp($this->end->getTimestamp() + $this->duration);
}
/**
* @return int
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getId() : int
{
return $this->id;
}
/**
* @return int
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getStatus() : int
{
return $this->status;
}
/**
* @param int $status Schedule status
*
* @return $this
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setStatus(int $status)
{
if (!ScheduleStatus::isValidValue($status)) {
@ -85,11 +189,25 @@ class Schedule
return $this;
}
/**
* @return int
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getFreqType() : int
{
return $this->freqType;
}
/**
* @param int $freqType Frequency type
*
* @return $this
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setFreqType(int $freqType)
{
if (!FrequencyType::isValidValue($freqType)) {
@ -101,11 +219,25 @@ class Schedule
return $this;
}
/**
* @return int
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getIntervalType() : int
{
return $this->intervalType;
}
/**
* @param int $intervalType Interval type
*
* @return $this
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setIntervalType(int $intervalType)
{
if (!IntervalType::isValidValue($intervalType)) {
@ -117,22 +249,44 @@ class Schedule
return $this;
}
/**
* @return int
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getFrequencyRelative() : int
{
return $this->relativeInternal;
}
public function setFrequencyRelative(int $relativeInternal)
/**
* @param int $relativeInterval Relative interval
*
* @return $this
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setFrequencyRelative(int $relativeInterval)
{
if (!FrequencyRelative::isValidValue($relativeInternal)) {
throw new InvalidEnumValue($relativeInternal);
if (!FrequencyRelative::isValidValue($relativeInterval)) {
throw new InvalidEnumValue($relativeInterval);
}
$this->relativeInternal = $relativeInternal;
$this->relativeInternal = $relativeInterval;
return $this;
}
/**
* @param int $freqInterval Frequency interval
*
* @return $this
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setFreqInterval(int $freqInterval)
{
if (!FrequencyInterval::isValidValue($freqInterval)) {
@ -144,16 +298,36 @@ class Schedule
return $this;
}
/**
* @return int
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getFreqInterval() : int
{
return $this->freqInterval;
}
/**
* @return int
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getRecurrenceFactor() : int
{
return $this->recurrenceFactor;
}
/**
* @param int $recurrence Recurrence
*
* @return $this
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setRecurrenceFactor(int $recurrence)
{
$this->recurrenceFactor = $recurrence;
@ -161,11 +335,25 @@ class Schedule
return $this;
}
/**
* @return \DateTime
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getStart() : \DateTime
{
return $this->start;
}
/**
* @param \DateTime $start Schedule start
*
* @return $this
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setStart(\DateTime $start)
{
$this->start = $start;
@ -173,14 +361,28 @@ class Schedule
return $this;
}
/**
* @return int
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getDuration() : int
{
return $this->duration;
}
/**
* @param int $duration Duration
*
* @return $this
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setDuration(int $duration)
{
if($duration < 1) {
if ($duration < 1) {
throw new \InvalidArgumentException($duration);
}
@ -189,11 +391,25 @@ class Schedule
return $this;
}
/**
* @return \DateTime
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getEnd() : \DateTime
{
return $this->end;
}
/**
* @param \DateTime $end Schedule end
*
* @return $this
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setEnd(\DateTime $end)
{
$this->end = $end;
@ -201,6 +417,14 @@ class Schedule
return $this;
}
/**
* @param int $creator Creator
*
* @return $this
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setCreatedBy(int $creator)
{
$this->createdBy = $creator;
@ -208,6 +432,12 @@ class Schedule
return $this;
}
/**
* @return int
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getCreatedBy() : int
{
return $this->createdBy;

View File

@ -19,6 +19,17 @@ use phpOMS\DataStorage\Database\DataMapperAbstract;
use phpOMS\DataStorage\Database\Query\Builder;
use phpOMS\DataStorage\Database\Query\Column;
/**
* Mapper class.
*
* @category Calendar
* @package Modules
* @author OMS Development Team <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 ScheduleMapper extends DataMapperAbstract
{
@ -44,9 +55,6 @@ class ScheduleMapper extends DataMapperAbstract
'scheule_created_by' => ['name' => 'scheule_created_by', 'type' => 'int', 'internal' => 'createdBy'],
];
protected static $hasMany = [
];
/**
* Primary table.
*
@ -55,6 +63,12 @@ class ScheduleMapper extends DataMapperAbstract
*/
protected static $table = 'schedule';
/**
* Created at.
*
* @var string
* @since 1.0.0
*/
protected static $createdAt = 'schedule_created_at';
/**

View File

@ -18,10 +18,10 @@ namespace Modules\Calendar\Models;
use phpOMS\Datatypes\Enum;
/**
* Occurrence type enum.
* Schedule status enum.
*
* @category OccurrenceType
* @package Framework
* @category Calendar
* @package Modules
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0