mirror of
https://github.com/Karaka-Management/oms-Media.git
synced 2026-02-17 01:38:41 +00:00
l11n, unit/app and simplification fixes
This commit is contained in:
parent
36e6f0f8c1
commit
81519fe144
|
|
@ -174,6 +174,30 @@
|
||||||
"foreignTable": "media",
|
"foreignTable": "media",
|
||||||
"foreignKey": "media_id"
|
"foreignKey": "media_id"
|
||||||
},
|
},
|
||||||
|
"media_unit": {
|
||||||
|
"name": "media_unit",
|
||||||
|
"type": "INT",
|
||||||
|
"default": null,
|
||||||
|
"null": true,
|
||||||
|
"foreignTable": "organization_unit",
|
||||||
|
"foreignKey": "organization_unit_id"
|
||||||
|
},
|
||||||
|
"media_language": {
|
||||||
|
"name": "media_language",
|
||||||
|
"type": "VARCHAR(2)",
|
||||||
|
"null": true,
|
||||||
|
"default": null,
|
||||||
|
"foreignTable": "language",
|
||||||
|
"foreignKey": "language_639_1"
|
||||||
|
},
|
||||||
|
"media_country": {
|
||||||
|
"name": "media_country",
|
||||||
|
"type": "VARCHAR(2)",
|
||||||
|
"null": true,
|
||||||
|
"default": null,
|
||||||
|
"foreignTable": "country",
|
||||||
|
"foreignKey": "country_code2"
|
||||||
|
},
|
||||||
"media_created_by": {
|
"media_created_by": {
|
||||||
"name": "media_created_by",
|
"name": "media_created_by",
|
||||||
"type": "INT",
|
"type": "INT",
|
||||||
|
|
|
||||||
|
|
@ -210,6 +210,11 @@ final class Installer extends InstallerAbstract
|
||||||
$request->header->account = 1;
|
$request->header->account = 1;
|
||||||
$request->setData('name', $data['name'] ?? '');
|
$request->setData('name', $data['name'] ?? '');
|
||||||
|
|
||||||
|
if (!empty($data['l11n'])) {
|
||||||
|
$request->setData('title', \reset($data['l11n'])['title']);
|
||||||
|
$request->setData('lang', \reset($data['l11n'])['lang']);
|
||||||
|
}
|
||||||
|
|
||||||
$module->apiMediaTypeCreate($request, $response);
|
$module->apiMediaTypeCreate($request, $response);
|
||||||
|
|
||||||
$responseData = $response->get('');
|
$responseData = $response->get('');
|
||||||
|
|
@ -220,7 +225,13 @@ final class Installer extends InstallerAbstract
|
||||||
$type = $responseData['response'];
|
$type = $responseData['response'];
|
||||||
$id = $type->getId();
|
$id = $type->getId();
|
||||||
|
|
||||||
|
$isFirst = true;
|
||||||
foreach ($data['l11n'] as $l11n) {
|
foreach ($data['l11n'] as $l11n) {
|
||||||
|
if ($isFirst) {
|
||||||
|
$isFirst = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$response = new HttpResponse();
|
$response = new HttpResponse();
|
||||||
$request = new HttpRequest(new HttpUri(''));
|
$request = new HttpRequest(new HttpUri(''));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ use Modules\Media\Models\Media;
|
||||||
use Modules\Media\Models\MediaContent;
|
use Modules\Media\Models\MediaContent;
|
||||||
use Modules\Media\Models\MediaMapper;
|
use Modules\Media\Models\MediaMapper;
|
||||||
use Modules\Media\Models\MediaType;
|
use Modules\Media\Models\MediaType;
|
||||||
use Modules\Media\Models\MediaTypeL11n;
|
use phpOMS\Localization\BaseStringL11n;
|
||||||
use Modules\Media\Models\MediaTypeL11nMapper;
|
use Modules\Media\Models\MediaTypeL11nMapper;
|
||||||
use Modules\Media\Models\MediaTypeMapper;
|
use Modules\Media\Models\MediaTypeMapper;
|
||||||
use Modules\Media\Models\NullCollection;
|
use Modules\Media\Models\NullCollection;
|
||||||
|
|
@ -52,7 +52,6 @@ use phpOMS\System\File\Local\Directory;
|
||||||
use phpOMS\System\MimeType;
|
use phpOMS\System\MimeType;
|
||||||
use phpOMS\Utils\ImageUtils;
|
use phpOMS\Utils\ImageUtils;
|
||||||
use phpOMS\Utils\Parser\Markdown\Markdown;
|
use phpOMS\Utils\Parser\Markdown\Markdown;
|
||||||
use phpOMS\Utils\Parser\Pdf\PdfParser;
|
|
||||||
use phpOMS\Views\View;
|
use phpOMS\Views\View;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -81,16 +80,19 @@ final class ApiController extends Controller
|
||||||
public function apiMediaUpload(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
|
public function apiMediaUpload(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
|
||||||
{
|
{
|
||||||
$uploads = $this->uploadFiles(
|
$uploads = $this->uploadFiles(
|
||||||
names: $request->getDataList('names'),
|
names: $request->getDataList('names'),
|
||||||
fileNames: $request->getDataList('filenames'),
|
fileNames: $request->getDataList('filenames'),
|
||||||
files: $request->getFiles(),
|
files: $request->getFiles(),
|
||||||
account: $request->header->account,
|
account: $request->header->account,
|
||||||
basePath: __DIR__ . '/../../../Modules/Media/Files' . \urldecode((string) ($request->getData('path') ?? '')),
|
basePath: __DIR__ . '/../../../Modules/Media/Files' . \urldecode((string) ($request->getData('path') ?? '')),
|
||||||
virtualPath: \urldecode((string) ($request->getData('virtualpath') ?? '')),
|
virtualPath: \urldecode((string) ($request->getData('virtualpath') ?? '')),
|
||||||
type: $request->getData('type', 'int'),
|
type: $request->getData('type', 'int'),
|
||||||
password: (string) ($request->getData('password') ?? ''),
|
password: (string) ($request->getData('password') ?? ''),
|
||||||
encryptionKey: (string) ($request->getData('encrypt') ?? ''),
|
encryptionKey: (string) ($request->getData('encrypt') ?? ''),
|
||||||
pathSettings: (int) ($request->getData('pathsettings') ?? PathSettings::RANDOM_PATH) // IMPORTANT!!!
|
pathSettings: (int) ($request->getData('pathsettings') ?? PathSettings::RANDOM_PATH), // IMPORTANT!!!
|
||||||
|
hasAccountRelation: (bool) ($request->getData('link_account') ?? false),
|
||||||
|
readContent: (bool) ($request->getData('parse_content') ?? false),
|
||||||
|
unit: $request->getData('unit', 'int')
|
||||||
);
|
);
|
||||||
|
|
||||||
$ids = [];
|
$ids = [];
|
||||||
|
|
@ -166,7 +168,9 @@ final class ApiController extends Controller
|
||||||
string $password = '',
|
string $password = '',
|
||||||
string $encryptionKey = '',
|
string $encryptionKey = '',
|
||||||
int $pathSettings = PathSettings::RANDOM_PATH,
|
int $pathSettings = PathSettings::RANDOM_PATH,
|
||||||
bool $hasAccountRelation = true
|
bool $hasAccountRelation = true,
|
||||||
|
bool $readContent = false,
|
||||||
|
int $unit = null
|
||||||
) : array
|
) : array
|
||||||
{
|
{
|
||||||
if (empty($files)) {
|
if (empty($files)) {
|
||||||
|
|
@ -208,7 +212,9 @@ final class ApiController extends Controller
|
||||||
$account,
|
$account,
|
||||||
$virtualPath,
|
$virtualPath,
|
||||||
$type,
|
$type,
|
||||||
app: $hasAccountRelation ? $this->app : null
|
app: $hasAccountRelation ? $this->app : null,
|
||||||
|
readContent: $readContent,
|
||||||
|
unit: $unit
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -265,6 +271,7 @@ final class ApiController extends Controller
|
||||||
* @param null|int $type Media type (internal categorization)
|
* @param null|int $type Media type (internal categorization)
|
||||||
* @param string $ip Ip of the origin
|
* @param string $ip Ip of the origin
|
||||||
* @param null|ApplicationAbstract $app Should create relation to uploader
|
* @param null|ApplicationAbstract $app Should create relation to uploader
|
||||||
|
* @param bool $readContent Should the content of the file be stored in the db
|
||||||
*
|
*
|
||||||
* @return Media
|
* @return Media
|
||||||
*
|
*
|
||||||
|
|
@ -276,7 +283,9 @@ final class ApiController extends Controller
|
||||||
string $virtualPath = '',
|
string $virtualPath = '',
|
||||||
int $type = null,
|
int $type = null,
|
||||||
string $ip = '127.0.0.1',
|
string $ip = '127.0.0.1',
|
||||||
ApplicationAbstract $app = null
|
ApplicationAbstract $app = null,
|
||||||
|
bool $readContent = false,
|
||||||
|
int $unit = null
|
||||||
) : Media
|
) : Media
|
||||||
{
|
{
|
||||||
if (!isset($status['status']) || $status['status'] !== UploadStatus::OK) {
|
if (!isset($status['status']) || $status['status'] !== UploadStatus::OK) {
|
||||||
|
|
@ -291,9 +300,10 @@ final class ApiController extends Controller
|
||||||
$media->createdBy = new NullAccount($account);
|
$media->createdBy = new NullAccount($account);
|
||||||
$media->extension = $status['extension'];
|
$media->extension = $status['extension'];
|
||||||
$media->type = $type === null ? null : new NullMediaType($type);
|
$media->type = $type === null ? null : new NullMediaType($type);
|
||||||
|
$media->unit = $unit;
|
||||||
$media->setVirtualPath($virtualPath);
|
$media->setVirtualPath($virtualPath);
|
||||||
|
|
||||||
if (\is_file($media->getAbsolutePath())) {
|
if ($readContent && \is_file($media->getAbsolutePath())) {
|
||||||
$content = self::loadFileContent($media->getAbsolutePath(), $media->extension);
|
$content = self::loadFileContent($media->getAbsolutePath(), $media->extension);
|
||||||
|
|
||||||
if (!empty($content)) {
|
if (!empty($content)) {
|
||||||
|
|
@ -335,23 +345,36 @@ final class ApiController extends Controller
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private static function loadFileContent(string $path, string $extension) : string
|
public static function loadFileContent(string $path, string $extension, string $output = 'html') : string
|
||||||
{
|
{
|
||||||
switch ($extension) {
|
switch ($extension) {
|
||||||
case 'pdf':
|
case 'pdf':
|
||||||
return PdfParser::pdf2text($path, __DIR__ . '/../../../Tools/OCRImageOptimizer/bin/App');
|
return \phpOMS\Utils\Parser\Pdf\PdfParser::pdf2text($path/*, __DIR__ . '/../../../Tools/OCRImageOptimizer/bin/OCRImageOptimizerApp'*/);
|
||||||
case 'doc':
|
case 'doc':
|
||||||
case 'docx':
|
case 'docx':
|
||||||
Autoloader::addPath(__DIR__ . '/../../../Resources/');
|
if (!Autoloader::inPaths($include = \realpath(__DIR__ . '/../../../Resources/'))) {
|
||||||
|
Autoloader::addPath($include);
|
||||||
|
}
|
||||||
|
|
||||||
$reader = IOFactory::createReader('Word2007');
|
return \phpOMS\Utils\Parser\Document\DocumentParser::parseDocument($path, $output);
|
||||||
$doc = $reader->load($path);
|
case 'ppt':
|
||||||
|
case 'pptx':
|
||||||
|
if (!Autoloader::inPaths($include = \realpath(__DIR__ . '/../../../Resources/'))) {
|
||||||
|
Autoloader::addPath($include);
|
||||||
|
}
|
||||||
|
|
||||||
$writer = new HTML($doc);
|
return \phpOMS\Utils\Parser\Presentation\PresentationParser::parsePresentation($path, $output);
|
||||||
return $writer->getContent();
|
case 'xls':
|
||||||
|
case 'xlsx':
|
||||||
|
if (!Autoloader::inPaths($include = \realpath(__DIR__ . '/../../../Resources/'))) {
|
||||||
|
Autoloader::addPath($include);
|
||||||
|
}
|
||||||
|
|
||||||
|
return \phpOMS\Utils\Parser\Spreadsheet\SpreadsheetParser::parseSpreadsheet($path, $output);
|
||||||
case 'txt':
|
case 'txt':
|
||||||
case 'md':
|
case 'md':
|
||||||
$contents = \file_get_contents($path);
|
$contents = \file_get_contents($path);
|
||||||
|
|
||||||
return $contents === false ? '' : $contents;
|
return $contents === false ? '' : $contents;
|
||||||
default:
|
default:
|
||||||
return '';
|
return '';
|
||||||
|
|
@ -710,7 +733,8 @@ final class ApiController extends Controller
|
||||||
$virtualPath,
|
$virtualPath,
|
||||||
$request->getData('type', 'int'),
|
$request->getData('type', 'int'),
|
||||||
$request->getOrigin(),
|
$request->getOrigin(),
|
||||||
$this->app
|
$this->app,
|
||||||
|
unit: $request->getData('unit', 'int')
|
||||||
);
|
);
|
||||||
|
|
||||||
$ids[] = $created->getId();
|
$ids[] = $created->getId();
|
||||||
|
|
@ -1015,15 +1039,15 @@ final class ApiController extends Controller
|
||||||
*
|
*
|
||||||
* @param RequestAbstract $request Request
|
* @param RequestAbstract $request Request
|
||||||
*
|
*
|
||||||
* @return MediaTypeL11n
|
* @return BaseStringL11n
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private function createMediaTypeL11nFromRequest(RequestAbstract $request) : MediaTypeL11n
|
private function createMediaTypeL11nFromRequest(RequestAbstract $request) : BaseStringL11n
|
||||||
{
|
{
|
||||||
$l11nMediaType = new MediaTypeL11n();
|
$l11nMediaType = new BaseStringL11n();
|
||||||
$l11nMediaType->type = (int) ($request->getData('type') ?? 0);
|
$l11nMediaType->ref = (int) ($request->getData('type') ?? 0);
|
||||||
$l11nMediaType->title = (string) ($request->getData('title') ?? '');
|
$l11nMediaType->content = (string) ($request->getData('title') ?? '');
|
||||||
$l11nMediaType->setLanguage((string) (
|
$l11nMediaType->setLanguage((string) (
|
||||||
$request->getData('language') ?? $request->getLanguage()
|
$request->getData('language') ?? $request->getLanguage()
|
||||||
));
|
));
|
||||||
|
|
|
||||||
|
|
@ -406,7 +406,7 @@ final class BackendController extends Controller
|
||||||
$view = new View($this->app->l11nManager, $request, $response);
|
$view = new View($this->app->l11nManager, $request, $response);
|
||||||
$view->setTemplate('/Modules/' . static::NAME . '/Admin/Settings/Theme/Backend/settings-type');
|
$view->setTemplate('/Modules/' . static::NAME . '/Admin/Settings/Theme/Backend/settings-type');
|
||||||
|
|
||||||
/** @var \Modules\Media\Models\MediaType $type */
|
/** @var \phpOMS\Localization\BaseStringL11n $type */
|
||||||
$type = MediaTypeMapper::get()
|
$type = MediaTypeMapper::get()
|
||||||
->with('title')
|
->with('title')
|
||||||
->where('title/language', $response->getLanguage())
|
->where('title/language', $response->getLanguage())
|
||||||
|
|
|
||||||
|
|
@ -181,6 +181,14 @@ class Media implements \JsonSerializable
|
||||||
*/
|
*/
|
||||||
public int $class = MediaClass::FILE;
|
public int $class = MediaClass::FILE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unit
|
||||||
|
*
|
||||||
|
* @var null|int
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public ?int $unit = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tags.
|
* Tags.
|
||||||
*
|
*
|
||||||
|
|
@ -189,6 +197,22 @@ class Media implements \JsonSerializable
|
||||||
*/
|
*/
|
||||||
protected array $tags = [];
|
protected array $tags = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Language.
|
||||||
|
*
|
||||||
|
* @var null|string
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
protected ?string $language = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Country.
|
||||||
|
*
|
||||||
|
* @var null|string
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
protected ?string $country = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,9 @@ class MediaMapper extends DataMapperFactory
|
||||||
'media_size' => ['name' => 'media_size', 'type' => 'int', 'internal' => 'size'],
|
'media_size' => ['name' => 'media_size', 'type' => 'int', 'internal' => 'size'],
|
||||||
'media_source' => ['name' => 'media_source', 'type' => 'int', 'internal' => 'source'],
|
'media_source' => ['name' => 'media_source', 'type' => 'int', 'internal' => 'source'],
|
||||||
'media_class' => ['name' => 'media_class', 'type' => 'int', 'internal' => 'class'],
|
'media_class' => ['name' => 'media_class', 'type' => 'int', 'internal' => 'class'],
|
||||||
|
'media_language' => ['name' => 'media_language', 'type' => 'string', 'internal' => 'language'],
|
||||||
|
'media_country' => ['name' => 'media_country', 'type' => 'string', 'internal' => 'country'],
|
||||||
|
'media_unit' => ['name' => 'media_unit', 'type' => 'int', 'internal' => 'unit', 'readonly' => true],
|
||||||
'media_created_by' => ['name' => 'media_created_by', 'type' => 'int', 'internal' => 'createdBy', 'readonly' => true],
|
'media_created_by' => ['name' => 'media_created_by', 'type' => 'int', 'internal' => 'createdBy', 'readonly' => true],
|
||||||
'media_created_at' => ['name' => 'media_created_at', 'type' => 'DateTimeImmutable', 'internal' => 'createdAt', 'readonly' => true],
|
'media_created_at' => ['name' => 'media_created_at', 'type' => 'DateTimeImmutable', 'internal' => 'createdAt', 'readonly' => true],
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ declare(strict_types=1);
|
||||||
namespace Modules\Media\Models;
|
namespace Modules\Media\Models;
|
||||||
|
|
||||||
use phpOMS\Localization\ISO639x1Enum;
|
use phpOMS\Localization\ISO639x1Enum;
|
||||||
|
use phpOMS\Localization\BaseStringL11n;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Media type class.
|
* Media type class.
|
||||||
|
|
@ -55,10 +56,10 @@ class MediaType implements \JsonSerializable
|
||||||
/**
|
/**
|
||||||
* Title.
|
* Title.
|
||||||
*
|
*
|
||||||
* @var string|MediaTypeL11n
|
* @var string|BaseStringL11n
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
protected $title = '';
|
protected string | BaseStringL11n $title = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
|
|
@ -91,28 +92,29 @@ class MediaType implements \JsonSerializable
|
||||||
*/
|
*/
|
||||||
public function getL11n() : string
|
public function getL11n() : string
|
||||||
{
|
{
|
||||||
return $this->title instanceof MediaTypeL11n ? $this->title->title : $this->title;
|
return $this->title instanceof BaseStringL11n ? $this->title->content : $this->title;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set title
|
* Set title
|
||||||
*
|
*
|
||||||
* @param string|MediaTypeL11n $title Media article title
|
* @param string|BaseStringL11n $title Media article title
|
||||||
* @param string $lang Language
|
* @param string $lang Language
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public function setL11n(string | MediaTypeL11n $title, string $lang = ISO639x1Enum::_EN) : void
|
public function setL11n(string | BaseStringL11n $title, string $lang = ISO639x1Enum::_EN) : void
|
||||||
{
|
{
|
||||||
if ($title instanceof MediaTypeL11n) {
|
if ($title instanceof BaseStringL11n) {
|
||||||
$this->title = $title;
|
$this->title = $title;
|
||||||
} elseif ($this->title instanceof MediaTypeL11n) {
|
} elseif ($this->title instanceof BaseStringL11n) {
|
||||||
$this->title->title = $title;
|
$this->title->content = $title;
|
||||||
} else {
|
} else {
|
||||||
$this->title = new MediaTypeL11n();
|
$this->title = new BaseStringL11n();
|
||||||
$this->title->title = $title;
|
$this->title->ref = $this->id;
|
||||||
|
$this->title->content = $title;
|
||||||
$this->title->setLanguage($lang);
|
$this->title->setLanguage($lang);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,132 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* Karaka
|
|
||||||
*
|
|
||||||
* PHP Version 8.1
|
|
||||||
*
|
|
||||||
* @package Modules\Media\Models
|
|
||||||
* @copyright Dennis Eichhorn
|
|
||||||
* @license OMS License 1.0
|
|
||||||
* @version 1.0.0
|
|
||||||
* @link https://jingga.app
|
|
||||||
*/
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Modules\Media\Models;
|
|
||||||
|
|
||||||
use phpOMS\Localization\ISO639x1Enum;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Media type l11n class.
|
|
||||||
*
|
|
||||||
* @package Modules\Media\Models
|
|
||||||
* @license OMS License 1.0
|
|
||||||
* @link https://jingga.app
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
class MediaTypeL11n implements \JsonSerializable
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* ID.
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
protected int $id = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Type ID.
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public int $type = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Language.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
protected string $language = ISO639x1Enum::_EN;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Title.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public string $title = '';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor.
|
|
||||||
*
|
|
||||||
* @param string $title Title
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function __construct(string $title = '', string $language = ISO639x1Enum::_EN)
|
|
||||||
{
|
|
||||||
$this->title = $title;
|
|
||||||
$this->language = $language;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get id
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function getId() : int
|
|
||||||
{
|
|
||||||
return $this->id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get language
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function getLanguage() : string
|
|
||||||
{
|
|
||||||
return $this->language;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set language
|
|
||||||
*
|
|
||||||
* @param string $language Language
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function setLanguage(string $language) : void
|
|
||||||
{
|
|
||||||
$this->language = $language;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function toArray() : array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'id' => $this->id,
|
|
||||||
'title' => $this->title,
|
|
||||||
'type' => $this->type,
|
|
||||||
'language' => $this->language,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function jsonSerialize() : mixed
|
|
||||||
{
|
|
||||||
return $this->toArray();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -15,6 +15,7 @@ declare(strict_types=1);
|
||||||
namespace Modules\Media\Models;
|
namespace Modules\Media\Models;
|
||||||
|
|
||||||
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||||
|
use phpOMS\Localization\BaseStringL11n;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Media type l11n mapper class.
|
* Media type l11n mapper class.
|
||||||
|
|
@ -34,8 +35,8 @@ final class MediaTypeL11nMapper extends DataMapperFactory
|
||||||
*/
|
*/
|
||||||
public const COLUMNS = [
|
public const COLUMNS = [
|
||||||
'media_type_l11n_id' => ['name' => 'media_type_l11n_id', 'type' => 'int', 'internal' => 'id'],
|
'media_type_l11n_id' => ['name' => 'media_type_l11n_id', 'type' => 'int', 'internal' => 'id'],
|
||||||
'media_type_l11n_title' => ['name' => 'media_type_l11n_title', 'type' => 'string', 'internal' => 'title', 'autocomplete' => true],
|
'media_type_l11n_title' => ['name' => 'media_type_l11n_title', 'type' => 'string', 'internal' => 'content', 'autocomplete' => true],
|
||||||
'media_type_l11n_type' => ['name' => 'media_type_l11n_type', 'type' => 'int', 'internal' => 'type'],
|
'media_type_l11n_type' => ['name' => 'media_type_l11n_type', 'type' => 'int', 'internal' => 'ref'],
|
||||||
'media_type_l11n_language' => ['name' => 'media_type_l11n_language', 'type' => 'string', 'internal' => 'language'],
|
'media_type_l11n_language' => ['name' => 'media_type_l11n_language', 'type' => 'string', 'internal' => 'language'],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
@ -54,4 +55,12 @@ final class MediaTypeL11nMapper extends DataMapperFactory
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public const PRIMARYFIELD ='media_type_l11n_id';
|
public const PRIMARYFIELD ='media_type_l11n_id';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Model to use by the mapper.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public const MODEL = BaseStringL11n::class;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,47 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* Karaka
|
|
||||||
*
|
|
||||||
* PHP Version 8.1
|
|
||||||
*
|
|
||||||
* @package Modules\Media\Models
|
|
||||||
* @copyright Dennis Eichhorn
|
|
||||||
* @license OMS License 1.0
|
|
||||||
* @version 1.0.0
|
|
||||||
* @link https://jingga.app
|
|
||||||
*/
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Modules\Media\Models;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Media type l11n class.
|
|
||||||
*
|
|
||||||
* @package Modules\Media\Models
|
|
||||||
* @license OMS License 1.0
|
|
||||||
* @link https://jingga.app
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
final class NullMediaTypeL11n extends MediaTypeL11n
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Constructor
|
|
||||||
*
|
|
||||||
* @param int $id Model id
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function __construct(int $id = 0)
|
|
||||||
{
|
|
||||||
$this->id = $id;
|
|
||||||
parent::__construct();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function jsonSerialize() : mixed
|
|
||||||
{
|
|
||||||
return ['id' => $this->id];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -15,18 +15,10 @@ declare(strict_types=1);
|
||||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
use PhpOffice\PhpSpreadsheet\Writer\Html;
|
use PhpOffice\PhpSpreadsheet\Writer\Html;
|
||||||
use phpOMS\Autoloader;
|
use phpOMS\Autoloader;
|
||||||
|
use phpOMS\Utils\Parser\Spreadsheet\SpreadsheetParser;
|
||||||
|
|
||||||
Autoloader::addPath(__DIR__ . '/../../../../Resources/');
|
Autoloader::addPath(__DIR__ . '/../../../../Resources/');
|
||||||
|
|
||||||
$media = $this->getData('media');
|
$media = $this->getData('media');
|
||||||
|
|
||||||
$reader = IOFactory::createReaderforFile(($media->isAbsolute ? '' : __DIR__ . '/../../../../') . $media->getPath());
|
echo SpreadsheetParser::parseSpreadsheet(($media->isAbsolute ? '' : __DIR__ . '/../../../../') . $media->getPath(), 'html');
|
||||||
$reader->setReadDataOnly(true);
|
|
||||||
$spreadsheet = $reader->load(($media->isAbsolute ? '' : __DIR__ . '/../../../../') . $media->getPath());
|
|
||||||
|
|
||||||
$writer = new Html($spreadsheet);
|
|
||||||
$writer->writeAllSheets();
|
|
||||||
|
|
||||||
$writer->save('php://output');
|
|
||||||
|
|
||||||
echo '<style>body { margin: 0; } table { width: 100%; } table .n, table .s { text-align: left; } td { padding: .5rem; }</style>';
|
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,31 @@
|
||||||
*/
|
*/
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
require_once __DIR__ . '/../../../../../../phpOMS/Autoloader.php';
|
|
||||||
use phpOMS\Autoloader;
|
use phpOMS\Autoloader;
|
||||||
|
use phpOMS\Uri\UriFactory;
|
||||||
|
use phpOMS\Utils\Parser\Presentation\PresentationParser;
|
||||||
|
|
||||||
Autoloader::addPath(__DIR__ . '/../../../../../../Resources/');
|
Autoloader::addPath(__DIR__ . '/../../../../../../Resources/');
|
||||||
|
?>
|
||||||
|
<section id="mediaFile" class="portlet">
|
||||||
|
<div class="portlet-body">
|
||||||
|
<div id="media" class="tabview tab-2 m-editor">
|
||||||
|
<ul class="tab-links">
|
||||||
|
<li><label tabindex="0" for="media-c-tab-1"><?= $this->getHtml('Preview', 'Media'); ?></label>
|
||||||
|
<li><label tabindex="0" for="media-c-tab-2">Status</label>
|
||||||
|
</ul>
|
||||||
|
<div class="tab-content">
|
||||||
|
<input type="radio" id="media-c-tab-1" name="tabular-1" checked>
|
||||||
|
<div class="tab">
|
||||||
|
<iframe src="<?= UriFactory::build('{/api}media/export?id=' . $this->media->getId()); ?>&type=html"></iframe>
|
||||||
|
</div>
|
||||||
|
<input type="radio" id="media-c-tab-2" name="tabular-1" checked>
|
||||||
|
<div class="tab">
|
||||||
|
<?php
|
||||||
|
echo PresentationParser::parsePresentation($this->media->getPath(), 'html');
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
@ -14,10 +14,11 @@
|
||||||
"name": "Karaka",
|
"name": "Karaka",
|
||||||
"website": "jingga.app"
|
"website": "jingga.app"
|
||||||
},
|
},
|
||||||
"description": "The profile module.",
|
"description": "The media module.",
|
||||||
"directory": "Media",
|
"directory": "Media",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"Admin": "1.0.0",
|
"Admin": "1.0.0",
|
||||||
|
"Organization": "1.0.0",
|
||||||
"Home": "1.0.0",
|
"Home": "1.0.0",
|
||||||
"Tag": "1.0.0"
|
"Tag": "1.0.0"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1,87 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* Karaka
|
|
||||||
*
|
|
||||||
* PHP Version 8.1
|
|
||||||
*
|
|
||||||
* @package tests
|
|
||||||
* @copyright Dennis Eichhorn
|
|
||||||
* @license OMS License 1.0
|
|
||||||
* @version 1.0.0
|
|
||||||
* @link https://jingga.app
|
|
||||||
*/
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Modules\Media\tests\Models;
|
|
||||||
|
|
||||||
use Modules\Media\Models\MediaTypeL11n;
|
|
||||||
use phpOMS\Localization\ISO639x1Enum;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
final class MediaTypeL11nTest extends \PHPUnit\Framework\TestCase
|
|
||||||
{
|
|
||||||
private MediaTypeL11n $l11n;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function setUp() : void
|
|
||||||
{
|
|
||||||
$this->l11n = new MediaTypeL11n();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers Modules\Media\Models\MediaTypeL11n
|
|
||||||
* @group module
|
|
||||||
*/
|
|
||||||
public function testDefault() : void
|
|
||||||
{
|
|
||||||
self::assertEquals(0, $this->l11n->getId());
|
|
||||||
self::assertEquals('', $this->l11n->title);
|
|
||||||
self::assertEquals(0, $this->l11n->type);
|
|
||||||
self::assertEquals(ISO639x1Enum::_EN, $this->l11n->getLanguage());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers Modules\Media\Models\MediaTypeL11n
|
|
||||||
* @group module
|
|
||||||
*/
|
|
||||||
public function testNameInputOutput() : void
|
|
||||||
{
|
|
||||||
$this->l11n->title = 'TestName';
|
|
||||||
self::assertEquals('TestName', $this->l11n->title);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers Modules\Media\Models\MediaTypeL11n
|
|
||||||
* @group module
|
|
||||||
*/
|
|
||||||
public function testLanguageInputOutput() : void
|
|
||||||
{
|
|
||||||
$this->l11n->setLanguage(ISO639x1Enum::_DE);
|
|
||||||
self::assertEquals(ISO639x1Enum::_DE, $this->l11n->getLanguage());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers Modules\Media\Models\MediaTypeL11n
|
|
||||||
* @group module
|
|
||||||
*/
|
|
||||||
public function testSerialize() : void
|
|
||||||
{
|
|
||||||
$this->l11n->title = 'Title';
|
|
||||||
$this->l11n->type = 2;
|
|
||||||
$this->l11n->setLanguage(ISO639x1Enum::_DE);
|
|
||||||
|
|
||||||
self::assertEquals(
|
|
||||||
[
|
|
||||||
'id' => 0,
|
|
||||||
'title' => 'Title',
|
|
||||||
'type' => 2,
|
|
||||||
'language' => ISO639x1Enum::_DE,
|
|
||||||
],
|
|
||||||
$this->l11n->jsonSerialize()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -15,7 +15,7 @@ declare(strict_types=1);
|
||||||
namespace Modules\Media\tests\Models;
|
namespace Modules\Media\tests\Models;
|
||||||
|
|
||||||
use Modules\Media\Models\MediaType;
|
use Modules\Media\Models\MediaType;
|
||||||
use Modules\Media\Models\MediaTypeL11n;
|
use phpOMS\Localization\BaseStringL11n;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
|
|
@ -51,7 +51,7 @@ final class MediaTypeTest extends \PHPUnit\Framework\TestCase
|
||||||
$this->type->setL11n('Test1');
|
$this->type->setL11n('Test1');
|
||||||
self::assertEquals('Test1', $this->type->getL11n());
|
self::assertEquals('Test1', $this->type->getL11n());
|
||||||
|
|
||||||
$this->type->setL11n(new MediaTypeL11n('Test2'));
|
$this->type->setL11n(new BaseStringL11n('Test2'));
|
||||||
self::assertEquals('Test2', $this->type->getL11n());
|
self::assertEquals('Test2', $this->type->getL11n());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,42 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* Karaka
|
|
||||||
*
|
|
||||||
* PHP Version 8.1
|
|
||||||
*
|
|
||||||
* @package tests
|
|
||||||
* @copyright Dennis Eichhorn
|
|
||||||
* @license OMS License 1.0
|
|
||||||
* @version 1.0.0
|
|
||||||
* @link https://jingga.app
|
|
||||||
*/
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Modules\Media\tests\Models;
|
|
||||||
|
|
||||||
use Modules\Media\Models\NullMediaTypeL11n;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
final class NullMediaTypeL11nTest extends \PHPUnit\Framework\TestCase
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @covers Modules\Media\Models\NullMediaTypeL11n
|
|
||||||
* @group framework
|
|
||||||
*/
|
|
||||||
public function testNull() : void
|
|
||||||
{
|
|
||||||
self::assertInstanceOf('\Modules\Media\Models\MediaTypeL11n', new NullMediaTypeL11n());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers Modules\Media\Models\NullMediaTypeL11n
|
|
||||||
* @group framework
|
|
||||||
*/
|
|
||||||
public function testId() : void
|
|
||||||
{
|
|
||||||
$null = new NullMediaTypeL11n(2);
|
|
||||||
self::assertEquals(2, $null->getId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user