diff --git a/Admin/Install/Media.install.json b/Admin/Install/Media.install.json index e944548..31ef3e5 100755 --- a/Admin/Install/Media.install.json +++ b/Admin/Install/Media.install.json @@ -5,5 +5,24 @@ "name": "Organization", "virtualPath": "/Modules", "user": 1 + }, + { + "type": "collection", + "create_directory": true, + "name": "Templates", + "virtualPath": "/Modules/Organization", + "user": 1 + }, + { + "type": "upload", + "create_collection": false, + "name": "Letter", + "type": "default_letter", + "virtualPath": "/Modules/Organization/Templates", + "path": "/Modules/Media/Files/Modules/Organization/Templates", + "files": [ + "/Modules/Organization/Admin/Install/Media/letter.doc.php" + ], + "user": 1 } ] \ No newline at end of file diff --git a/Admin/Install/Media/letter.doc.php b/Admin/Install/Media/letter.doc.php new file mode 100644 index 0000000..e69de29 diff --git a/Admin/Install/db.json b/Admin/Install/db.json index 710b826..196dfb8 100755 --- a/Admin/Install/db.json +++ b/Admin/Install/db.json @@ -51,6 +51,32 @@ } } }, + "organization_unit_media": { + "name": "organization_unit_media", + "fields": { + "organization_unit_media_id": { + "name": "organization_unit_media_id", + "type": "INT", + "null": false, + "primary": true, + "autoincrement": true + }, + "organization_unit_media_src": { + "name": "organization_unit_media_src", + "type": "INT", + "null": false, + "foreignTable": "organization_unit", + "foreignKey": "organization_unit_id" + }, + "organization_unit_media_dst": { + "name": "organization_unit_media_dst", + "type": "INT", + "null": false, + "foreignTable": "media", + "foreignKey": "media_id" + } + } + }, "organization_department": { "name": "organization_department", "fields": { diff --git a/Models/Unit.php b/Models/Unit.php index d6fab4b..cfaff5b 100755 --- a/Models/Unit.php +++ b/Models/Unit.php @@ -84,6 +84,14 @@ class Unit implements \JsonSerializable, ArrayableInterface */ protected int $status = Status::INACTIVE; + /** + * Media files + * + * @var array + * @since 1.0.0 + */ + protected array $files = []; + /** * Constructor. * @@ -107,6 +115,73 @@ class Unit implements \JsonSerializable, ArrayableInterface return $this->id; } + /** + * Get media. + * + * @return array + * + * @since 1.0.0 + */ + public function getFiles() : array + { + return $this->files; + } + + /** + * Add media. + * + * @param Media $file Media + * + * @return void + * + * @since 1.0.0 + */ + public function addFile(Media $file) : void + { + $this->files[] = $file; + } + + /** + * Get media file by type + * + * @param string $type Media type + * + * @return Media + * + * @since 1.0.0 + */ + public function getFileByType(string $type) : Media + { + foreach ($this->files as $file) { + if ($file->type === $type) { + return $file; + } + } + + return new NullMedia(); + } + + /** + * Get all media files by type + * + * @param string $type Media type + * + * @return Media[] + * + * @since 1.0.0 + */ + public function getFilesByType(string $type) : array + { + $files = []; + foreach ($this->files as $file) { + if ($file->type === $type) { + $files[] = $file; + } + } + + return $files; + } + /** * Get status * diff --git a/Models/UnitMapper.php b/Models/UnitMapper.php index cd527fb..b610045 100755 --- a/Models/UnitMapper.php +++ b/Models/UnitMapper.php @@ -69,6 +69,21 @@ final class UnitMapper extends DataMapperAbstract ], ]; + /** + * Has many relation. + * + * @var array + * @since 1.0.0 + */ + protected static array $hasMany = [ + 'files' => [ + 'mapper' => MediaMapper::class, /* mapper of the related object */ + 'table' => 'organization_unit_media', /* table of the related object, null if no relation table is used (many->1) */ + 'external' => 'organization_unit_media_dst', + 'self' => 'organization_unit_media_src', + ], + ]; + /** * Model to use by the mapper. * diff --git a/Theme/Backend/Components/DepartmentTagSelector/department-selector.tpl.php b/Theme/Backend/Components/DepartmentTagSelector/department-selector.tpl.php index fc52f4a..7f9e208 100755 --- a/Theme/Backend/Components/DepartmentTagSelector/department-selector.tpl.php +++ b/Theme/Backend/Components/DepartmentTagSelector/department-selector.tpl.php @@ -17,7 +17,7 @@ data-emptyAfter="true" data-autocomplete="off" data-src="api/organization/find/department?search={!#igetId(); ?>}"> -