many fixes and expands and module expansions

This commit is contained in:
Dennis Eichhorn 2021-04-04 17:10:52 +02:00
parent 18c2de5b9e
commit 9e0e153484
8 changed files with 138 additions and 3 deletions

View File

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

View File

View File

@ -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": {

View File

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

View File

@ -69,6 +69,21 @@ final class UnitMapper extends DataMapperAbstract
],
];
/**
* Has many relation.
*
* @var array<string, array{mapper:string, table:string, self?:?string, external?:?string, column?:string}>
* @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.
*

View File

@ -17,7 +17,7 @@
data-emptyAfter="true"
data-autocomplete="off"
data-src="api/organization/find/department?search={!#i<?= $this->getId(); ?>}">
<div id="<?= $this->getId(); ?>-dropdown" class="dropdown" data-active="true">
<div id="<?= $this->getId(); ?>-popup" class="popup" data-active="true">
<table class="default">
<thead>
<tr>

View File

@ -17,7 +17,7 @@
data-emptyAfter="true"
data-autocomplete="off"
data-src="api/organization/find/position?search={!#i<?= $this->getId(); ?>}">
<div id="<?= $this->getId(); ?>-dropdown" class="dropdown" data-active="true">
<div id="<?= $this->getId(); ?>-popup" class="popup" data-active="true">
<table class="default">
<thead>
<tr>

View File

@ -17,7 +17,7 @@
data-emptyAfter="true"
data-autocomplete="off"
data-src="api/organization/find/unit?search={!#i<?= $this->getId(); ?>}">
<div id="<?= $this->getId(); ?>-dropdown" class="dropdown" data-active="true">
<div id="<?= $this->getId(); ?>-popup" class="popup" data-active="true">
<table class="default">
<thead>
<tr>