diff --git a/Admin/Install/db.json b/Admin/Install/db.json index 257e1b1..7b5eaae 100755 --- a/Admin/Install/db.json +++ b/Admin/Install/db.json @@ -167,5 +167,31 @@ "foreignKey": "account_id" } } + }, + "calendar_event_tag": { + "name": "calendar_event_tag", + "fields": { + "calendar_event_tag_id": { + "name": "calendar_event_tag_id", + "type": "INT", + "null": false, + "primary": true, + "autoincrement": true + }, + "calendar_event_tag_src": { + "name": "calendar_event_tag_src", + "type": "INT", + "null": false, + "foreignTable": "calendar_event", + "foreignKey": "calendar_event_id" + }, + "calendar_event_tag_dst": { + "name": "calendar_event_tag_dst", + "type": "INT", + "null": false, + "foreignTable": "tag", + "foreignKey": "tag_id" + } + } } } \ No newline at end of file diff --git a/Docs/Dev/img/er.png b/Docs/Dev/img/er.png new file mode 100644 index 0000000..3af9741 Binary files /dev/null and b/Docs/Dev/img/er.png differ diff --git a/Models/Event.php b/Models/Event.php index cd4b76d..6f12731 100755 --- a/Models/Event.php +++ b/Models/Event.php @@ -17,6 +17,8 @@ namespace Modules\Calendar\Models; use Modules\Admin\Models\Account; use Modules\Admin\Models\NullAccount; use phpOMS\Stdlib\Base\Location; +use Modules\Tag\Models\NullTag; +use Modules\Tag\Models\Tag; /** * Event class. @@ -120,6 +122,14 @@ class Event */ private array $people = []; + /** + * Tags. + * + * @var Tag[] + * @since 1.0.0 + */ + protected array $tags = []; + /** * Constructor. * @@ -298,4 +308,70 @@ class Event { return $this->schedule; } + + /** + * Adding new tag. + * + * @param Tag $tag Tag + * + * @return int + * + * @since 1.0.0 + */ + public function addTag(Tag $tag) : int + { + $this->tags[] = $tag; + + \end($this->tags); + $key = (int) \key($this->tags); + \reset($this->tags); + + return $key; + } + + /** + * Remove Tag from list. + * + * @param int $id Tag + * + * @return bool + * + * @since 1.0.0 + */ + public function removeTag($id) : bool + { + if (isset($this->tags[$id])) { + unset($this->tags[$id]); + + return true; + } + + return false; + } + + /** + * Get task elements. + * + * @return Tag[] + * + * @since 1.0.0 + */ + public function getTags() : array + { + return $this->tags; + } + + /** + * Get task elements. + * + * @param int $id Element id + * + * @return Tag + * + * @since 1.0.0 + */ + public function getTag(int $id) : Tag + { + return $this->tags[$id] ?? new NullTag(); + } } diff --git a/Models/EventMapper.php b/Models/EventMapper.php index b6edd13..691a792 100755 --- a/Models/EventMapper.php +++ b/Models/EventMapper.php @@ -16,6 +16,7 @@ namespace Modules\Calendar\Models; use Modules\Admin\Models\AccountMapper; use phpOMS\DataStorage\Database\DataMapperAbstract; +use Modules\Tag\Models\TagMapper; /** * Mapper class. @@ -72,6 +73,21 @@ final class EventMapper extends DataMapperAbstract ], ]; + /** + * Has many relation. + * + * @var array + * @since 1.0.0 + */ + protected static array $hasMany = [ + 'tags' => [ + 'mapper' => TagMapper::class, + 'table' => 'calendar_event_tag', + 'external' => 'calendar_event_tag_dst', + 'self' => 'calendar_event_tag_src', + ], + ]; + /** * Primary table. *