mirror of
https://github.com/Karaka-Management/oms-Surveys.git
synced 2026-02-16 15:18:40 +00:00
Add media support
This commit is contained in:
parent
b355009f53
commit
3067ca5946
9
Admin/Install/Media.install.json
Normal file
9
Admin/Install/Media.install.json
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"type": "collection",
|
||||||
|
"create_directory": true,
|
||||||
|
"name": "Surveys",
|
||||||
|
"virtualPath": "/Modules",
|
||||||
|
"user": 1
|
||||||
|
}
|
||||||
|
]
|
||||||
43
Admin/Install/Media.php
Normal file
43
Admin/Install/Media.php
Normal 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']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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": {
|
"survey_template_l11n": {
|
||||||
"name": "survey_template_l11n",
|
"name": "survey_template_l11n",
|
||||||
"fields": {
|
"fields": {
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ use Modules\Surveys\Models\SurveyTemplateElementMapper;
|
||||||
use Modules\Surveys\Models\SurveyTemplateMapper;
|
use Modules\Surveys\Models\SurveyTemplateMapper;
|
||||||
use Modules\Surveys\Models\SurveyStatus;
|
use Modules\Surveys\Models\SurveyStatus;
|
||||||
use Modules\Surveys\Models\SurveyElementType;
|
use Modules\Surveys\Models\SurveyElementType;
|
||||||
|
use Modules\Media\Models\NullMedia;
|
||||||
use phpOMS\Message\Http\HttpResponse;
|
use phpOMS\Message\Http\HttpResponse;
|
||||||
use phpOMS\Message\Http\RequestStatusCode;
|
use phpOMS\Message\Http\RequestStatusCode;
|
||||||
use phpOMS\Message\NotificationLevel;
|
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;
|
return $template;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ namespace Modules\Surveys\Models;
|
||||||
use phpOMS\Localization\ISO639x1Enum;
|
use phpOMS\Localization\ISO639x1Enum;
|
||||||
use Modules\Admin\Models\Account;
|
use Modules\Admin\Models\Account;
|
||||||
use Modules\Tag\Models\Tag;
|
use Modules\Tag\Models\Tag;
|
||||||
|
use Modules\Media\Models\Media;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Survey class.
|
* Survey class.
|
||||||
|
|
@ -118,6 +119,14 @@ class SurveyTemplate
|
||||||
*/
|
*/
|
||||||
private array $elements = [];
|
private array $elements = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Media files
|
||||||
|
*
|
||||||
|
* @var Media[]
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
protected array $media = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
|
|
@ -191,6 +200,32 @@ class SurveyTemplate
|
||||||
$this->tags[] = $tag;
|
$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
|
* Get elements
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,12 @@ final class SurveyTemplateMapper extends DataMapperAbstract
|
||||||
'self' => 'survey_template_tag_dst',
|
'self' => 'survey_template_tag_dst',
|
||||||
'external' => 'survey_template_tag_src',
|
'external' => 'survey_template_tag_src',
|
||||||
],
|
],
|
||||||
|
'media' => [
|
||||||
|
'mapper' => MediaMapper::class,
|
||||||
|
'table' => 'survey_template_media',
|
||||||
|
'external' => 'survey_template_media_dst',
|
||||||
|
'self' => 'survey_template_media_src',
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -127,20 +127,22 @@ echo $this->getData('nav')->render(); ?>
|
||||||
<i class="filter fa fa-filter"></i>
|
<i class="filter fa fa-filter"></i>
|
||||||
</label>
|
</label>
|
||||||
<tbody>
|
<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; ?>">
|
<tr tabindex="0" data-href="<?= $url; ?>">
|
||||||
<td>
|
<td>
|
||||||
<td data-label="<?= $this->getHtml('Type'); ?>"><a href="<?= $url; ?>"><i class="fa fa-folder-open-o"></i></a>
|
<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; ?>">..
|
<td data-label="<?= $this->getHtml('Name'); ?>"><a href="<?= $url; ?>">..</a>
|
||||||
</a>
|
|
||||||
<td>
|
<td>
|
||||||
<td>
|
<td>
|
||||||
<td>
|
<td>
|
||||||
<td>
|
<td>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<?php $count = 0; foreach ($collections as $key => $value) : ++$count;
|
<?php $count = 0;
|
||||||
$url = UriFactory::build('{/prefix}survey/list?path=' . \rtrim($value->getVirtualPath(), '/') . '/' . $value->name);
|
foreach ($collections as $key => $value) : ++$count;
|
||||||
?>
|
$url = UriFactory::build('{/prefix}survey/list?path=' . \rtrim($value->getVirtualPath(), '/') . '/' . $value->name);
|
||||||
|
?>
|
||||||
<tr data-href="<?= $url; ?>">
|
<tr data-href="<?= $url; ?>">
|
||||||
<td><label class="checkbox" for="surveyList-<?= $key; ?>">
|
<td><label class="checkbox" for="surveyList-<?= $key; ?>">
|
||||||
<input type="checkbox" id="surveyList-<?= $key; ?>" name="surveyselect">
|
<input type="checkbox" id="surveyList-<?= $key; ?>" name="surveyselect">
|
||||||
|
|
@ -151,11 +153,11 @@ echo $this->getData('nav')->render(); ?>
|
||||||
<td>
|
<td>
|
||||||
<td><a class="content" href="<?= UriFactory::build('{/prefix}profile/single?{?}&for=' . $value->createdBy->getId()); ?>"><?= $this->printHtml($value->createdBy->name1); ?></a>
|
<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>
|
<td><a href="<?= $url; ?>"><?= $this->printHtml($value->createdAt->format('Y-m-d')); ?></a>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
<?php
|
<?php
|
||||||
$count = 0;
|
$count = 0;
|
||||||
foreach ($surveys as $key => $value) : ++$count;
|
foreach ($surveys as $key => $value) : ++$count;
|
||||||
$url = UriFactory::build('{/prefix}survey/edit?{?}&id=' . $value->getId()); ?>
|
$url = UriFactory::build('{/prefix}survey/edit?{?}&id=' . $value->getId());
|
||||||
?>
|
?>
|
||||||
<tr data-href="<?= $url; ?>">
|
<tr data-href="<?= $url; ?>">
|
||||||
<td><label class="checkbox" for="surveyList-<?= $key; ?>">
|
<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>
|
<td><a href="<?= $url; ?>"><?= $value->createdAt->format('Y-m-d'); ?></a>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
<?php if ($count === 0) : ?>
|
<?php if ($count === 0) : ?>
|
||||||
<tr><td colspan="6" class="empty"><?= $this->getHtml('Empty', '0', '0'); ?>
|
<tr><td colspan="6" class="empty"><?= $this->getHtml('Empty', '0', '0'); ?>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</table>
|
</table>
|
||||||
<div class="portlet-foot">
|
<div class="portlet-foot">
|
||||||
<a tabindex="0" class="button" href="<?= UriFactory::build($previous); ?>"><?= $this->getHtml('Previous', '0', '0'); ?></a>
|
<a tabindex="0" class="button" href="<?= UriFactory::build($previous); ?>"><?= $this->getHtml('Previous', '0', '0'); ?></a>
|
||||||
|
|
|
||||||
|
|
@ -19,10 +19,12 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"Admin": "1.0.0",
|
"Admin": "1.0.0",
|
||||||
"Tag": "1.0.0",
|
"Tag": "1.0.0",
|
||||||
|
"Media": "1.0.0",
|
||||||
"Tools": "1.0.0"
|
"Tools": "1.0.0"
|
||||||
},
|
},
|
||||||
"providing": {
|
"providing": {
|
||||||
"Navigation": "*"
|
"Navigation": "*",
|
||||||
|
"Media": "*"
|
||||||
},
|
},
|
||||||
"load": [
|
"load": [
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user