Add media support

This commit is contained in:
Dennis Eichhorn 2021-08-09 23:49:07 +02:00
parent b355009f53
commit 3067ca5946
8 changed files with 156 additions and 12 deletions

View File

@ -0,0 +1,9 @@
[
{
"type": "collection",
"create_directory": true,
"name": "Surveys",
"virtualPath": "/Modules",
"user": 1
}
]

43
Admin/Install/Media.php Normal file
View File

@ -0,0 +1,43 @@
<?php
/**
* Orange Management
*
* PHP Version 8.0
*
* @package Modules\Surveys\Admin\Install
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace Modules\Surveys\Admin\Install;
use phpOMS\Application\ApplicationAbstract;
/**
* Media class.
*
* @package Modules\Surveys\Admin\Install
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*/
class Media
{
/**
* Install media providing
*
* @param string $path Module path
* @param ApplicationAbstract $app Application
*
* @return void
*
* @since 1.0.0
*/
public static function install(string $path, ApplicationAbstract $app) : void
{
\Modules\Media\Admin\Installer::installExternal($app, ['path' => __DIR__ . '/Media.install.json']);
}
}

View File

@ -48,6 +48,32 @@
}
}
},
"survey_template_media": {
"name": "survey_template_media",
"fields": {
"survey_template_media_id": {
"name": "survey_template_media_id",
"type": "INT",
"null": false,
"primary": true,
"autoincrement": true
},
"survey_template_media_src": {
"name": "survey_template_media_src",
"type": "INT",
"null": false,
"foreignTable": "survey_template",
"foreignKey": "survey_template_id"
},
"survey_template_media_dst": {
"name": "survey_template_media_dst",
"type": "INT",
"null": false,
"foreignTable": "media",
"foreignKey": "media_id"
}
}
},
"survey_template_l11n": {
"name": "survey_template_l11n",
"fields": {

View File

@ -25,6 +25,7 @@ use Modules\Surveys\Models\SurveyTemplateElementMapper;
use Modules\Surveys\Models\SurveyTemplateMapper;
use Modules\Surveys\Models\SurveyStatus;
use Modules\Surveys\Models\SurveyElementType;
use Modules\Media\Models\NullMedia;
use phpOMS\Message\Http\HttpResponse;
use phpOMS\Message\Http\RequestStatusCode;
use phpOMS\Message\NotificationLevel;
@ -135,6 +136,26 @@ final class ApiController extends Controller
}
}
if (!empty($uploadedFiles = $request->getFiles() ?? [])) {
$uploaded = $this->app->moduleManager->get('Media')->uploadFiles(
[''],
$uploadedFiles,
$request->header->account,
__DIR__ . '/../../../Modules/Media/Files/Modules/Surveys',
'/Modules/Surveys',
);
foreach ($uploaded as $media) {
$template->addMedia($media);
}
}
if (!empty($mediaFiles = $request->getDataJson('media') ?? [])) {
foreach ($mediaFiles as $media) {
$template->addMedia(new NullMedia($media));
}
}
return $template;
}

View File

@ -17,6 +17,7 @@ namespace Modules\Surveys\Models;
use phpOMS\Localization\ISO639x1Enum;
use Modules\Admin\Models\Account;
use Modules\Tag\Models\Tag;
use Modules\Media\Models\Media;
/**
* Survey class.
@ -118,6 +119,14 @@ class SurveyTemplate
*/
private array $elements = [];
/**
* Media files
*
* @var Media[]
* @since 1.0.0
*/
protected array $media = [];
/**
* Constructor.
*
@ -191,6 +200,32 @@ class SurveyTemplate
$this->tags[] = $tag;
}
/**
* Get all media
*
* @return Media[]
*
* @since 1.0.0
*/
public function getMedia() : array
{
return $this->media;
}
/**
* Add media
*
* @param Media $media Media to add
*
* @return void
*
* @since 1.0.0
*/
public function addMedia(Media $media) : void
{
$this->media[] = $media;
}
/**
* Get elements
*

View File

@ -74,6 +74,12 @@ final class SurveyTemplateMapper extends DataMapperAbstract
'self' => 'survey_template_tag_dst',
'external' => 'survey_template_tag_src',
],
'media' => [
'mapper' => MediaMapper::class,
'table' => 'survey_template_media',
'external' => 'survey_template_media_dst',
'self' => 'survey_template_media_src',
],
];
/**

View File

@ -127,20 +127,22 @@ echo $this->getData('nav')->render(); ?>
<i class="filter fa fa-filter"></i>
</label>
<tbody>
<?php if (!empty($parentPath)) : $url = UriFactory::build('{/prefix}survey/list?path=' . $parentPath); ?>
<?php if (!empty($parentPath)) :
$url = UriFactory::build('{/prefix}survey/list?path=' . $parentPath);
?>
<tr tabindex="0" data-href="<?= $url; ?>">
<td>
<td data-label="<?= $this->getHtml('Type'); ?>"><a href="<?= $url; ?>"><i class="fa fa-folder-open-o"></i></a>
<td data-label="<?= $this->getHtml('Name'); ?>"><a href="<?= $url; ?>">..
</a>
<td data-label="<?= $this->getHtml('Name'); ?>"><a href="<?= $url; ?>">..</a>
<td>
<td>
<td>
<td>
<?php endif; ?>
<?php $count = 0; foreach ($collections as $key => $value) : ++$count;
$url = UriFactory::build('{/prefix}survey/list?path=' . \rtrim($value->getVirtualPath(), '/') . '/' . $value->name);
?>
<?php $count = 0;
foreach ($collections as $key => $value) : ++$count;
$url = UriFactory::build('{/prefix}survey/list?path=' . \rtrim($value->getVirtualPath(), '/') . '/' . $value->name);
?>
<tr data-href="<?= $url; ?>">
<td><label class="checkbox" for="surveyList-<?= $key; ?>">
<input type="checkbox" id="surveyList-<?= $key; ?>" name="surveyselect">
@ -151,11 +153,11 @@ echo $this->getData('nav')->render(); ?>
<td>
<td><a class="content" href="<?= UriFactory::build('{/prefix}profile/single?{?}&for=' . $value->createdBy->getId()); ?>"><?= $this->printHtml($value->createdBy->name1); ?></a>
<td><a href="<?= $url; ?>"><?= $this->printHtml($value->createdAt->format('Y-m-d')); ?></a>
<?php endforeach; ?>
<?php endforeach; ?>
<?php
$count = 0;
foreach ($surveys as $key => $value) : ++$count;
$url = UriFactory::build('{/prefix}survey/edit?{?}&id=' . $value->getId()); ?>
foreach ($surveys as $key => $value) : ++$count;
$url = UriFactory::build('{/prefix}survey/edit?{?}&id=' . $value->getId());
?>
<tr data-href="<?= $url; ?>">
<td><label class="checkbox" for="surveyList-<?= $key; ?>">
@ -169,8 +171,8 @@ echo $this->getData('nav')->render(); ?>
<td><a href="<?= $url; ?>"><?= $value->createdAt->format('Y-m-d'); ?></a>
<?php endforeach; ?>
<?php if ($count === 0) : ?>
<tr><td colspan="6" class="empty"><?= $this->getHtml('Empty', '0', '0'); ?>
<?php endif; ?>
<tr><td colspan="6" class="empty"><?= $this->getHtml('Empty', '0', '0'); ?>
<?php endif; ?>
</table>
<div class="portlet-foot">
<a tabindex="0" class="button" href="<?= UriFactory::build($previous); ?>"><?= $this->getHtml('Previous', '0', '0'); ?></a>

View File

@ -19,10 +19,12 @@
"dependencies": {
"Admin": "1.0.0",
"Tag": "1.0.0",
"Media": "1.0.0",
"Tools": "1.0.0"
},
"providing": {
"Navigation": "*"
"Navigation": "*",
"Media": "*"
},
"load": [
{