This commit is contained in:
Dennis Eichhorn 2020-03-05 20:35:58 +01:00
parent 8eb88fd7e2
commit 10eefe96e2
4 changed files with 58 additions and 26 deletions

View File

@ -14,8 +14,8 @@ declare(strict_types=1);
namespace Modules\Calendar\Models; namespace Modules\Calendar\Models;
use Modules\Admin\Models\NullAccount;
use phpOMS\Account\Account; use phpOMS\Account\Account;
use phpOMS\Account\NullAccount;
use phpOMS\Stdlib\Base\Location; use phpOMS\Stdlib\Base\Location;
/** /**
@ -63,10 +63,10 @@ class Event
/** /**
* Creator. * Creator.
* *
* @var int|\Modules\Admin\Models\Account * @var Account
* @since 1.0.0 * @since 1.0.0
*/ */
private $createdBy = 0; private Account $createdBy;
/** /**
* Event type. * Event type.
@ -91,10 +91,10 @@ class Event
/** /**
* Schedule * Schedule
* *
* @var int|Schedule * @var Schedule
* @since 1.0.0 * @since 1.0.0
*/ */
private $schedule; private Schedule $schedule;
/** /**
* Location of the event. * Location of the event.
@ -127,6 +127,7 @@ class Event
*/ */
public function __construct() public function __construct()
{ {
$this->createdBy = new NullAccount();
$this->createdAt = new \DateTime('now'); $this->createdAt = new \DateTime('now');
$this->location = new Location(); $this->location = new Location();
$this->schedule = new Schedule(); $this->schedule = new Schedule();
@ -247,11 +248,11 @@ class Event
} }
/** /**
* @return int|\Modules\Admin\Models\Account * @return Account
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function getCreatedBy() public function getCreatedBy() : Account
{ {
return $this->createdBy; return $this->createdBy;
} }
@ -259,13 +260,13 @@ class Event
/** /**
* Set creator * Set creator
* *
* @param int $createdBy Creator * @param Account $createdBy Creator
* *
* @return void * @return void
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function setCreatedBy(int $createdBy) : void public function setCreatedBy(Account $createdBy) : void
{ {
$this->createdBy = $createdBy; $this->createdBy = $createdBy;
@ -339,11 +340,11 @@ class Event
} }
/** /**
* @return int|Schedule * @return Schedule
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function getSchedule() public function getSchedule() : Schedule
{ {
return $this->schedule; return $this->schedule;
} }

View File

@ -14,6 +14,7 @@ declare(strict_types=1);
namespace Modules\Calendar\Models; namespace Modules\Calendar\Models;
use Modules\Admin\Models\AccountMapper;
use phpOMS\DataStorage\Database\DataMapperAbstract; use phpOMS\DataStorage\Database\DataMapperAbstract;
/** /**
@ -41,7 +42,7 @@ final class EventMapper extends DataMapperAbstract
'calendar_event_status' => ['name' => 'calendar_event_status', 'type' => 'int', 'internal' => 'status'], 'calendar_event_status' => ['name' => 'calendar_event_status', 'type' => 'int', 'internal' => 'status'],
'calendar_event_schedule' => ['name' => 'calendar_event_schedule', 'type' => 'int', 'internal' => 'schedule'], 'calendar_event_schedule' => ['name' => 'calendar_event_schedule', 'type' => 'int', 'internal' => 'schedule'],
'calendar_event_calendar' => ['name' => 'calendar_event_calendar', 'type' => 'int', 'internal' => 'calendar'], '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_by' => ['name' => 'calendar_event_created_by', 'type' => 'int', 'internal' => 'createdBy', 'readonly' => true],
'calendar_event_created_at' => ['name' => 'calendar_event_created_at', 'type' => 'DateTime', 'internal' => 'createdAt', 'readonly' => true], 'calendar_event_created_at' => ['name' => 'calendar_event_created_at', 'type' => 'DateTime', 'internal' => 'createdAt', 'readonly' => true],
]; ];
@ -58,6 +59,19 @@ final class EventMapper extends DataMapperAbstract
], ],
]; ];
/**
* Belongs to.
*
* @var array<string, array{mapper:string, self:string}>
* @since 1.0.0
*/
protected static array $belongsTo = [
'createdBy' => [
'mapper' => AccountMapper::class,
'self' => 'calendar_event_created_by',
],
];
/** /**
* Primary table. * Primary table.
* *

View File

@ -14,6 +14,8 @@ declare(strict_types=1);
namespace Modules\Calendar\Models; namespace Modules\Calendar\Models;
use Modules\Admin\Models\Account;
use Modules\Admin\Models\NullAccount;
use phpOMS\Stdlib\Base\Exception\InvalidEnumValue; use phpOMS\Stdlib\Base\Exception\InvalidEnumValue;
/** /**
@ -125,10 +127,10 @@ class Schedule
/** /**
* Created by. * Created by.
* *
* @var int|\Modules\Admin\Models\Account * @var Account
* @since 1.0.0 * @since 1.0.0
*/ */
private $createdBy = 0; private Account $createdBy;
/** /**
* Constructor. * Constructor.
@ -137,6 +139,7 @@ class Schedule
*/ */
public function __construct() public function __construct()
{ {
$this->createdBy = new NullAccount();
$this->createdAt = new \DateTime('now'); $this->createdAt = new \DateTime('now');
$this->start = new \DateTime('now'); $this->start = new \DateTime('now');
$this->end = new \DateTime('now'); $this->end = new \DateTime('now');
@ -170,7 +173,7 @@ class Schedule
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function setStatus(int $status) public function setStatus(int $status) : self
{ {
if (!ScheduleStatus::isValidValue($status)) { if (!ScheduleStatus::isValidValue($status)) {
throw new InvalidEnumValue($status); throw new InvalidEnumValue($status);
@ -198,7 +201,7 @@ class Schedule
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function setFreqType(int $freqType) public function setFreqType(int $freqType) : self
{ {
if (!FrequencyType::isValidValue($freqType)) { if (!FrequencyType::isValidValue($freqType)) {
throw new InvalidEnumValue($freqType); throw new InvalidEnumValue($freqType);
@ -226,7 +229,7 @@ class Schedule
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function setIntervalType(int $intervalType) public function setIntervalType(int $intervalType) : self
{ {
if (!IntervalType::isValidValue($intervalType)) { if (!IntervalType::isValidValue($intervalType)) {
throw new InvalidEnumValue($intervalType); throw new InvalidEnumValue($intervalType);
@ -254,7 +257,7 @@ class Schedule
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function setFrequencyRelative(int $relativeInterval) public function setFrequencyRelative(int $relativeInterval) : self
{ {
if (!FrequencyRelative::isValidValue($relativeInterval)) { if (!FrequencyRelative::isValidValue($relativeInterval)) {
throw new InvalidEnumValue($relativeInterval); throw new InvalidEnumValue($relativeInterval);
@ -272,7 +275,7 @@ class Schedule
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function setFreqInterval(int $freqInterval) public function setFreqInterval(int $freqInterval) : self
{ {
if (!FrequencyInterval::isValidValue($freqInterval)) { if (!FrequencyInterval::isValidValue($freqInterval)) {
throw new InvalidEnumValue($freqInterval); throw new InvalidEnumValue($freqInterval);
@ -310,7 +313,7 @@ class Schedule
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function setRecurrenceFactor(int $recurrence) public function setRecurrenceFactor(int $recurrence) : self
{ {
$this->recurrenceFactor = $recurrence; $this->recurrenceFactor = $recurrence;
@ -334,7 +337,7 @@ class Schedule
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function setStart(\DateTime $start) public function setStart(\DateTime $start) : self
{ {
$this->start = $start; $this->start = $start;
@ -394,13 +397,13 @@ class Schedule
} }
/** /**
* @param int $creator Creator * @param Account $creator Creator
* *
* @return $this * @return $this
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function setCreatedBy(int $creator) public function setCreatedBy(Account $creator) : self
{ {
$this->createdBy = $creator; $this->createdBy = $creator;
@ -408,11 +411,11 @@ class Schedule
} }
/** /**
* @return int|\Modules\Admin\Models\Account * @return Account
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function getCreatedBy() public function getCreatedBy() : Account
{ {
return $this->createdBy; return $this->createdBy;
} }

View File

@ -14,6 +14,7 @@ declare(strict_types=1);
namespace Modules\Calendar\Models; namespace Modules\Calendar\Models;
use Modules\Admin\Models\AccountMapper;
use phpOMS\DataStorage\Database\DataMapperAbstract; use phpOMS\DataStorage\Database\DataMapperAbstract;
/** /**
@ -45,7 +46,20 @@ final class ScheduleMapper extends DataMapperAbstract
'schedule_duration' => ['name' => 'schedule_duration', 'type' => 'int', 'internal' => 'duration'], 'schedule_duration' => ['name' => 'schedule_duration', 'type' => 'int', 'internal' => 'duration'],
'schedule_end' => ['name' => 'schedule_end', 'type' => 'DateTime', 'internal' => 'end'], 'schedule_end' => ['name' => 'schedule_end', 'type' => 'DateTime', 'internal' => 'end'],
'schedule_created_at' => ['name' => 'schedule_created_at', 'type' => 'DateTime', 'internal' => 'createdAt', 'readonly' => true], 'schedule_created_at' => ['name' => 'schedule_created_at', 'type' => 'DateTime', 'internal' => 'createdAt', 'readonly' => true],
'schedule_created_by' => ['name' => 'schedule_created_by', 'type' => 'int', 'internal' => 'createdBy'], 'schedule_created_by' => ['name' => 'schedule_created_by', 'type' => 'int', 'internal' => 'createdBy', 'readonly' => true],
];
/**
* Belongs to.
*
* @var array<string, array{mapper:string, self:string}>
* @since 1.0.0
*/
protected static array $belongsTo = [
'createdBy' => [
'mapper' => AccountMapper::class,
'self' => 'schedule_created_by',
],
]; ];
/** /**