mirror of
https://github.com/Karaka-Management/oms-Media.git
synced 2026-02-06 12:38:41 +00:00
many fixes and expands and module expansions
This commit is contained in:
parent
f497bafa9d
commit
c37fcdbc6d
|
|
@ -131,5 +131,31 @@
|
|||
"foreignKey": "media_id"
|
||||
}
|
||||
}
|
||||
},
|
||||
"media_tag": {
|
||||
"name": "media_tag",
|
||||
"fields": {
|
||||
"media_tag_id": {
|
||||
"name": "media_tag_id",
|
||||
"type": "INT",
|
||||
"null": false,
|
||||
"primary": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"media_tag_src": {
|
||||
"name": "media_tag_src",
|
||||
"type": "INT",
|
||||
"null": false,
|
||||
"foreignTable": "media",
|
||||
"foreignKey": "media_id"
|
||||
},
|
||||
"media_tag_dst": {
|
||||
"name": "task_tag_dst",
|
||||
"type": "INT",
|
||||
"null": false,
|
||||
"foreignTable": "tag",
|
||||
"foreignKey": "tag_id"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -39,6 +39,9 @@ use phpOMS\System\File\Local\Directory;
|
|||
use phpOMS\System\MimeType;
|
||||
use phpOMS\Utils\Parser\Markdown\Markdown;
|
||||
use phpOMS\Views\View;
|
||||
use phpOMS\Message\Http\HttpResponse;
|
||||
use phpOMS\Message\Http\HttpRequest;
|
||||
use Modules\Tag\Models\NullTag;
|
||||
|
||||
/**
|
||||
* Media class.
|
||||
|
|
@ -80,6 +83,35 @@ final class ApiController extends Controller
|
|||
$ids = [];
|
||||
foreach ($uploads as $file) {
|
||||
$ids[] = $file->getId();
|
||||
|
||||
// @todo: maybe improve, this could potentially be done immediately in the createDBEntry, especially if tags replace the type? But probably we need type and tags (both are slightly different e.g. tags are public, types are for modules e.g. itemmanagement item image)
|
||||
// add tags
|
||||
if (!empty($tags = $request->getDataJson('tags'))) {
|
||||
foreach ($tags as $tag) {
|
||||
if (!isset($tag['id'])) {
|
||||
$request->setData('title', $tag['title'], true);
|
||||
$request->setData('color', $tag['color'], true);
|
||||
$request->setData('icon', $tag['icon'] ?? null, true);
|
||||
$request->setData('language', $tag['language'], true);
|
||||
|
||||
$internalResponse = new HttpResponse();
|
||||
$this->app->moduleManager->get('Tag')->apiTagCreate($request, $internalResponse, null);
|
||||
$file->addTag($tId = $internalResponse->get($request->uri->__toString())['response']);
|
||||
} else {
|
||||
$file->addTag(new NullTag($tId = (int) $tag['id']));
|
||||
}
|
||||
|
||||
$this->createModelRelation(
|
||||
$request->header->account,
|
||||
$file->getId(),
|
||||
$tId,
|
||||
MediaMapper::class,
|
||||
'tags',
|
||||
'',
|
||||
$request->getOrigin()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Media', 'Media successfully created.', $ids);
|
||||
|
|
@ -198,6 +230,7 @@ final class ApiController extends Controller
|
|||
$this->app->orgId,
|
||||
$this->app->appName,
|
||||
self::MODULE_NAME,
|
||||
self::MODULE_NAME,
|
||||
PermissionState::MEDIA,
|
||||
$created->getId(),
|
||||
null,
|
||||
|
|
@ -605,7 +638,7 @@ final class ApiController extends Controller
|
|||
* Set header for report/template
|
||||
*
|
||||
* @param View $view Media view
|
||||
* @param string $name Template name
|
||||
* @param Media $media Media file
|
||||
* @param RequestAbstract $request Request
|
||||
* @param ResponseAbstract $response Response
|
||||
*
|
||||
|
|
|
|||
|
|
@ -156,6 +156,7 @@ final class BackendController extends Controller
|
|||
|
||||
$view->addData('media', $media);
|
||||
$view->addData('path', $path);
|
||||
$view->addData('account', $this->app->accountManager->get($request->header->account));
|
||||
|
||||
return $view;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,6 +43,6 @@ trait FileUploaderTrait
|
|||
public static function setUpFileUploaderTrait(RequestAbstract $request, ResponseAbstract $response, $data = null) : void
|
||||
{
|
||||
$head = $response->get('Content')->getData('head');
|
||||
$head->addAsset(AssetType::JS, '/Modules/Media/ModuleMedia.js');
|
||||
$head->addAsset(AssetType::JS, '/Modules/Media/Controller.js', ['type' => 'module']);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@ namespace Modules\Media\Models;
|
|||
|
||||
use Modules\Admin\Models\Account;
|
||||
use Modules\Admin\Models\NullAccount;
|
||||
use Modules\Tag\Models\Tag;
|
||||
use Modules\Tag\Models\NullTag;
|
||||
|
||||
/**
|
||||
* Media class.
|
||||
|
|
@ -163,6 +165,14 @@ class Media implements \JsonSerializable
|
|||
*/
|
||||
protected int $collection = 0;
|
||||
|
||||
/**
|
||||
* Tags.
|
||||
*
|
||||
* @var Tag[]
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected array $tags = [];
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
|
|
@ -328,6 +338,72 @@ class Media implements \JsonSerializable
|
|||
$this->virtualPath = \str_replace('\\', '/', $path);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ namespace Modules\Media\Models;
|
|||
use Modules\Admin\Models\AccountMapper;
|
||||
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
||||
use phpOMS\DataStorage\Database\RelationType;
|
||||
use Modules\Tag\Models\TagMapper;
|
||||
|
||||
/**
|
||||
* Media mapper class.
|
||||
|
|
@ -67,6 +68,21 @@ class MediaMapper 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 = [
|
||||
'tags' => [
|
||||
'mapper' => TagMapper::class,
|
||||
'table' => 'media_tag',
|
||||
'external' => 'media_tag_dst',
|
||||
'self' => 'media_tag_src',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Model to use by the mapper.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
data-emptyAfter="true"
|
||||
data-autocomplete="off"
|
||||
data-src="api/media/find?search={!#mediaInput}">
|
||||
<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>
|
||||
|
|
|
|||
|
|
@ -18,8 +18,11 @@
|
|||
|
||||
for($i = 0; $i < $archive->numFiles; ++$i) {
|
||||
$stat = $archive->statIndex($i);
|
||||
|
||||
echo '<tr><td>' . \str_repeat(' ', (\substr_count(\trim($stat['name'], '/'), '/')) * 8) . $stat['name'];
|
||||
echo '<tr>';
|
||||
echo '<td>'
|
||||
. \str_repeat(' ', (\substr_count(\trim($stat['name'], '/'), '/')) * 8)
|
||||
. ($stat['name'][\strlen($stat['name']) - 1] === '/' ? '<i class="fa fa-folder-open-o"></i> ' : '<i class="fa fa-file-o"></i> ')
|
||||
. $stat['name'];
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
data-emptyAfter="true"
|
||||
data-autocomplete="off"
|
||||
data-src="api/media/find?search={!#mediaInput}">
|
||||
<div id="iMediaInput-dropdown" class="dropdown" data-active="true">
|
||||
<div id="iMediaInput-popup" class="popup" data-active="true">
|
||||
<table id="iMediaInput-table" class="default">
|
||||
<thead>
|
||||
<tr>
|
||||
|
|
|
|||
|
|
@ -28,6 +28,9 @@ $mediaPath = \urldecode($this->getData('path') ?? '/');
|
|||
* @var \Modules\Media\Models\Media[] $media
|
||||
*/
|
||||
$media = $this->getData('media');
|
||||
$account = $this->getData('account');
|
||||
|
||||
$accountDir = $account->getId() . ' ' . $account->login;
|
||||
|
||||
$previous = empty($media) ? '{/prefix}media/list' : '{/prefix}media/list?{?}&id=' . \reset($media)->getId() . '&ptype=p';
|
||||
$next = empty($media) ? '{/prefix}media/list' : '{/prefix}media/list?{?}&id=' . \end($media)->getId() . '&ptype=n';
|
||||
|
|
@ -47,6 +50,7 @@ $next = empty($media) ? '{/prefix}media/list' : '{/prefix}media/list?{?}&id=
|
|||
<div class="col-xs-12">
|
||||
<div class="box">
|
||||
<ul class="crumbs-2">
|
||||
<li data-href="<?= UriFactory::build('{/prefix}media/list?path=/Accounts/' . $accountDir); ?>"><a href="<?= UriFactory::build('{/prefix}media/list?path=/Accounts/' . $accountDir); ?>"><i class="fa fa-home"></i></a>
|
||||
<li data-href="<?= UriFactory::build('{/prefix}media/list?path=/'); ?>"><a href="<?= UriFactory::build('{/prefix}media/list?path=/'); ?>">/</a></li>
|
||||
<?php
|
||||
$subPath = '';
|
||||
|
|
|
|||
|
|
@ -21,6 +21,9 @@ include __DIR__ . '/template-functions.php';
|
|||
$media = $this->getData('media');
|
||||
$view = $this->getData('view');
|
||||
|
||||
/** @var \Modules\Tag\Models\Tag[] $tag */
|
||||
$tags = $media->getTags();
|
||||
|
||||
/** @var \Modules\Media\Views\MediaView $this */
|
||||
echo $this->getData('nav')->render();
|
||||
?>
|
||||
|
|
@ -49,8 +52,12 @@ echo $this->getData('nav')->render();
|
|||
echo $this->printHtml(\number_format($size[0], 1, '.', ',') . $size[1]); ?>
|
||||
<tr><td><?= $this->getHtml('Created'); ?><td><?= $this->printHtml($media->createdAt->format('Y-m-d')); ?>
|
||||
<tr><td><?= $this->getHtml('Creator'); ?><td><a href="<?= UriFactory::build('{/prefix}profile/single?for=' . $media->createdBy->getId()); ?>"><?= $this->printHtml(
|
||||
\ltrim($media->createdBy->name2 . ', ' . $media->createdBy->name1, ', ')
|
||||
); ?></a>
|
||||
\ltrim($media->createdBy->name2 . ', ' . $media->createdBy->name1, ', ')
|
||||
); ?></a>
|
||||
<tr><td><?= $this->getHtml('Tags'); ?><td>
|
||||
<?php foreach ($tags as $tag) : ?>
|
||||
<span class="tag" style="background: <?= $this->printHtml($tag->color); ?>"><?= $tag->icon !== null ? '<i class="' . $this->printHtml($tag->icon ?? '') . '"></i>' : ''; ?><?= $this->printHtml($tag->getTitle()); ?></span>
|
||||
<?php endforeach; ?>
|
||||
<tr><td colspan="2"><?= $this->getHtml('Description'); ?>
|
||||
<tr><td colspan="2"><?= $media->description; ?>
|
||||
</table>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user