diff --git a/.github/workflows/greetings.yml b/.github/workflows/greetings.yml index adb8716..75cb759 100755 --- a/.github/workflows/greetings.yml +++ b/.github/workflows/greetings.yml @@ -9,5 +9,5 @@ jobs: - uses: actions/first-interaction@v1 with: repo-token: ${{ secrets.GITHUB_TOKEN }} - issue-message: 'Thank you for createing this issue. We will check it as soon as possible.' + issue-message: 'Thank you for creating this issue. We will check it as soon as possible.' pr-message: 'Thank you for your pull request. We will check it as soon as possible.' diff --git a/Admin/Install/Media.install.json b/Admin/Install/Media.install.json deleted file mode 100644 index 1e3880f..0000000 --- a/Admin/Install/Media.install.json +++ /dev/null @@ -1,114 +0,0 @@ -[ - { - "type": "type", - "name": "contract", - "l11n": [ - { - "title": "Contract", - "lang": "en" - }, - { - "title": "Vertrag", - "lang": "de" - } - ] - }, - { - "type": "type", - "name": "nda", - "l11n": [ - { - "title": "NDA", - "lang": "en" - }, - { - "title": "NDA", - "lang": "de" - } - ] - }, - { - "type": "type", - "name": "receipt", - "l11n": [ - { - "title": "Receipt", - "lang": "en" - }, - { - "title": "Quittung", - "lang": "de" - } - ] - }, - { - "type": "type", - "name": "invoice", - "l11n": [ - { - "title": "Invoice", - "lang": "en" - }, - { - "title": "Rechnung", - "lang": "de" - } - ] - }, - { - "type": "type", - "name": "letter", - "l11n": [ - { - "title": "Letter", - "lang": "en" - }, - { - "title": "Brief", - "lang": "de" - } - ] - }, - { - "type": "type", - "name": "minutes", - "l11n": [ - { - "title": "Minutes", - "lang": "en" - }, - { - "title": "Protokoll", - "lang": "de" - } - ] - }, - { - "type": "type", - "name": "leasing", - "l11n": [ - { - "title": "Leasing", - "lang": "en" - }, - { - "title": "Leasing", - "lang": "de" - } - ] - }, - { - "type": "type", - "name": "insurance", - "l11n": [ - { - "title": "Insurance", - "lang": "en" - }, - { - "title": "Versicherung", - "lang": "de" - } - ] - } -] \ No newline at end of file diff --git a/Admin/Install/SearchCommands.php b/Admin/Install/SearchCommands.php index 8259aad..9607342 100644 --- a/Admin/Install/SearchCommands.php +++ b/Admin/Install/SearchCommands.php @@ -23,6 +23,7 @@ return [ 'dest' => '\Modules\Media\Controller\SearchController:searchGeneral', 'verb' => RouteVerb::ANY, 'active' => true, + 'order' => 3, 'permission' => [ 'module' => SearchController::NAME, 'type' => PermissionType::READ, diff --git a/Admin/Install/Tag.install.json b/Admin/Install/Tag.install.json new file mode 100644 index 0000000..338a13e --- /dev/null +++ b/Admin/Install/Tag.install.json @@ -0,0 +1,37 @@ +[ + { + "name": "nda", + "l11n": { + "en": "NDA", + "de": "NDA" + } + }, + { + "name": "receipt", + "l11n": { + "en": "Receipt", + "de": "Quittung" + } + }, + { + "name": "invoice", + "l11n": { + "en": "Invoice", + "de": "Rechnung" + } + }, + { + "name": "letter", + "l11n": { + "en": "Letter", + "de": "Brief" + } + }, + { + "name": "minutes", + "l11n": { + "en": "Minutes", + "de": "Protokoll" + } + } +] \ No newline at end of file diff --git a/Admin/Install/Media.php b/Admin/Install/Tag.php similarity index 84% rename from Admin/Install/Media.php rename to Admin/Install/Tag.php index 53e280d..443217d 100644 --- a/Admin/Install/Media.php +++ b/Admin/Install/Tag.php @@ -17,14 +17,14 @@ namespace Modules\Media\Admin\Install; use phpOMS\Application\ApplicationAbstract; /** - * Media class. + * Tag class. * * @package Modules\Media\Admin\Install * @license OMS License 2.0 * @link https://jingga.app * @since 1.0.0 */ -class Media +class Tag { /** * Install media providing @@ -38,6 +38,6 @@ class Media */ public static function install(ApplicationAbstract $app, string $path) : void { - \Modules\Media\Admin\Installer::installExternal($app, ['path' => __DIR__ . '/Media.install.json']); + \Modules\Tag\Admin\Installer::installExternal($app, ['path' => __DIR__ . '/Tag.install.json']); } } diff --git a/Admin/Install/db.json b/Admin/Install/db.json index f39d967..6fe05ec 100755 --- a/Admin/Install/db.json +++ b/Admin/Install/db.json @@ -1,58 +1,4 @@ { - "media_type": { - "name": "media_type", - "fields": { - "media_type_id": { - "name": "media_type_id", - "type": "INT", - "null": false, - "primary": true, - "autoincrement": true - }, - "media_type_name": { - "name": "media_type_name", - "type": "VARCHAR(255)", - "null": false - }, - "media_type_isvisible": { - "name": "media_type_isvisible", - "type": "TINYINT(1)", - "null": false - } - } - }, - "media_type_l11n": { - "name": "media_type_l11n", - "fields": { - "media_type_l11n_id": { - "name": "media_type_l11n_id", - "type": "INT", - "null": false, - "primary": true, - "autoincrement": true - }, - "media_type_l11n_title": { - "name": "media_type_l11n_title", - "type": "VARCHAR(255)", - "null": false - }, - "media_type_l11n_type": { - "name": "media_type_l11n_type", - "type": "INT", - "null": false, - "foreignTable": "media_type", - "foreignKey": "media_type_id" - }, - "media_type_l11n_language": { - "name": "media_type_l11n_language", - "type": "VARCHAR(2)", - "default": null, - "null": true, - "foreignTable": "language", - "foreignKey": "language_639_1" - } - } - }, "media_parsed": { "name": "media_parsed", "fields": { @@ -256,31 +202,5 @@ "foreignKey": "tag_id" } } - }, - "media_type_rel": { - "name": "media_type_rel", - "fields": { - "media_type_rel_id": { - "name": "media_type_rel_id", - "type": "INT", - "null": false, - "primary": true, - "autoincrement": true - }, - "media_type_rel_src": { - "name": "media_type_rel_src", - "type": "INT", - "null": false, - "foreignTable": "media", - "foreignKey": "media_id" - }, - "media_type_rel_dst": { - "name": "media_type_rel_dst", - "type": "INT", - "null": false, - "foreignTable": "media_type", - "foreignKey": "media_type_id" - } - } } } \ No newline at end of file diff --git a/Admin/Installer.php b/Admin/Installer.php index dd30645..cd565ea 100755 --- a/Admin/Installer.php +++ b/Admin/Installer.php @@ -144,9 +144,6 @@ final class Installer extends InstallerAbstract case 'upload': $result['upload'][] = self::uploadMedia($apiApp, $media); break; - case 'type': - $result['type'][] = self::createType($apiApp, $media); - break; case 'reference': $result['reference'][] = self::createReference($apiApp, $media); break; @@ -230,65 +227,6 @@ final class Installer extends InstallerAbstract : $responseData['response']->toArray(); } - /** - * Create type. - * - * @param ApplicationAbstract $app Application - * @param array $data Media info - * - * @return array - * - * @since 1.0.0 - */ - private static function createType(ApplicationAbstract $app, array $data) : array - { - /** @var \Modules\Media\Controller\ApiController $module */ - $module = $app->moduleManager->get('Media'); - - $response = new HttpResponse(); - $request = new HttpRequest(); - - $request->header->account = 1; - $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); - - $responseData = $response->getData(''); - if (!\is_array($responseData)) { - return []; - } - - $type = $responseData['response']; - $id = $type->id; - - $isFirst = true; - foreach ($data['l11n'] as $l11n) { - if ($isFirst) { - $isFirst = false; - continue; - } - - $response = new HttpResponse(); - $request = new HttpRequest(); - - $request->header->account = 1; - $request->setData('title', $l11n['title'] ?? ''); - $request->setData('lang', $l11n['lang'] ?? null); - $request->setData('type', $id); - - $module->apiMediaTypeL11nCreate($request, $response); - } - - return \is_array($type) - ? $type - : $type->toArray(); - } - /** * Upload media. * @@ -316,7 +254,7 @@ final class Installer extends InstallerAbstract : ($data['virtualPath'] ?? '/') ) ); - $request->setData('type', $data['media_type'] ?? null); // = identifier for modules + $request->setData('type', $data['tag'] ?? null); // = identifier for modules $request->setData('pathsettings', $data['path_setting'] ?? PathSettings::FILE_PATH); $tempPath = __DIR__ . '/../../../temp/'; diff --git a/Admin/Routes/Web/Backend.php b/Admin/Routes/Web/Backend.php index a3795af..965c2c8 100755 --- a/Admin/Routes/Web/Backend.php +++ b/Admin/Routes/Web/Backend.php @@ -18,18 +18,6 @@ use phpOMS\Account\PermissionType; use phpOMS\Router\RouteVerb; return [ - '^/admin/module/settings\?id=Media&type=.*?$' => [ - [ - 'dest' => '\Modules\Media\Controller\BackendController:viewMediaTypeSettings', - 'verb' => RouteVerb::GET, - 'active' => true, - 'permission' => [ - 'module' => BackendController::NAME, - 'type' => PermissionType::READ, - 'state' => \Modules\Admin\Models\PermissionCategory::MODULE, - ], - ], - ], '^/media/list(\?.*$|$)' => [ [ 'dest' => '\Modules\Media\Controller\BackendController:viewMediaList', diff --git a/Admin/Settings/Theme/Backend/settings.tpl.php b/Admin/Settings/Theme/Backend/settings.tpl.php index 5603437..e212282 100755 --- a/Admin/Settings/Theme/Backend/settings.tpl.php +++ b/Admin/Settings/Theme/Backend/settings.tpl.php @@ -24,7 +24,7 @@ echo $this->data['nav']->render(); ?>
-
+
getHtml('Types'); ?>download
@@ -80,6 +80,6 @@ echo $this->data['nav']->render(); ?>
-
+
diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 62b4188..4a1c3db 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -23,12 +23,8 @@ use Modules\Media\Models\MediaClass; use Modules\Media\Models\MediaContent; use Modules\Media\Models\MediaContentMapper; use Modules\Media\Models\MediaMapper; -use Modules\Media\Models\MediaType; -use Modules\Media\Models\MediaTypeL11nMapper; -use Modules\Media\Models\MediaTypeMapper; use Modules\Media\Models\NullCollection; use Modules\Media\Models\NullMedia; -use Modules\Media\Models\NullMediaType; use Modules\Media\Models\PathSettings; use Modules\Media\Models\PermissionCategory; use Modules\Media\Models\Reference; @@ -37,13 +33,12 @@ use Modules\Media\Models\UploadFile; use Modules\Media\Models\UploadStatus; use Modules\Media\Theme\Backend\Components\Media\ElementView; use Modules\Messages\Models\EmailMapper; +use Modules\Tag\Models\NullTag; use phpOMS\Account\PermissionType; use phpOMS\Ai\Ocr\Tesseract\TesseractOcr; use phpOMS\Application\ApplicationAbstract; use phpOMS\Asset\AssetType; use phpOMS\Autoloader; -use phpOMS\Localization\BaseStringL11n; -use phpOMS\Localization\ISO639x1Enum; use phpOMS\Message\Http\HttpResponse; use phpOMS\Message\Http\RequestStatusCode; use phpOMS\Message\RequestAbstract; @@ -179,51 +174,26 @@ final class ApiController extends Controller foreach ($uploads as $file) { $ids[] = $file->id; - // add media types - if (!empty($types = $request->getDataJson('types'))) { - foreach ($types as $type) { - if (!isset($type['id'])) { - $request->setData('name', $type['name'], true); - $request->setData('title', $type['title'], true); - $request->setData('lang', $type['lang'] ?? null, true); - - $internalResponse = new HttpResponse(); - $this->apiMediaTypeCreate($request, $internalResponse); - - if (!\is_array($data = $internalResponse->getDataArray($request->uri->__toString()))) { - continue; - } - - $file->addMediaType($tId = $data['response']); - } else { - $file->addMediaType(new NullMediaType($tId = (int) $type['id'])); + // add media tags + if (!empty($tags = $request->getDataJson('tags'))) { + foreach ($tags as $tag) { + if (!isset($tag['id'])) { + continue; } + $file->tags[] = new NullTag($tId = (int) $tag['id']); + $this->createModelRelation( $request->header->account, $file->id, $tId, MediaMapper::class, - 'types', + 'tags', '', $request->getOrigin() ); } } - - if ($request->hasData('tags')) { - $file->tags = $this->app->moduleManager->get('Tag', 'Api')->createTagsFromRequest($request); - } - - $this->createModelRelation( - $request->header->account, - $file->id, - \array_map(function (\Modules\Tag\Models\Tag $tag) { return $tag->id; }, $file->tags), - MediaMapper::class, - 'tags', - '', - $request->getOrigin() - ); } $this->createStandardAddResponse($request, $response, $ids); @@ -337,7 +307,7 @@ final class ApiController extends Controller bool $readContent = false, ?int $unit = null, bool $createCollection = true, - ?int $type = null, + ?int $tag = null, ?int $rel = null, string $mapper = '', string $field = '' @@ -394,9 +364,9 @@ final class ApiController extends Controller isEncrypted: !empty($encryptionKey) ); - // Create relation to type - if (!empty($type)) { - $this->createModelRelation($account, $media->id, $type, MediaMapper::class, 'types', '', '127.0.0.1'); + // Create relation to tag + if (!empty($tag)) { + $this->createModelRelation($account, $media->id, $tag, MediaMapper::class, 'tags', '', '127.0.0.1'); } // Create relation to model @@ -1125,6 +1095,10 @@ final class ApiController extends Controller string $collectionPath = '' ) : void { + if (empty($files)) { + return; + } + /** @var \Modules\Media\Models\Media[] $mediaFiles */ $mediaFiles = MediaMapper::getAll() ->where('id', $files) @@ -1601,144 +1575,6 @@ final class ApiController extends Controller } } - /** - * Validate document create request - * - * @param RequestAbstract $request Request - * - * @return array - * - * @since 1.0.0 - */ - private function validateMediaTypeCreate(RequestAbstract $request) : array - { - $val = []; - if (($val['name'] = !$request->hasData('name')) - ) { - return $val; - } - - return []; - } - - /** - * Api method to create document - * - * @param RequestAbstract $request Request - * @param ResponseAbstract $response Response - * @param array $data Generic data - * - * @return void - * - * @api - * - * @since 1.0.0 - */ - public function apiMediaTypeCreate(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void - { - if (!empty($val = $this->validateMediaTypeCreate($request))) { - $response->header->status = RequestStatusCode::R_400; - $this->createInvalidCreateResponse($request, $response, $val); - - return; - } - - $type = $this->createDocTypeFromRequest($request); - $this->createModel($request->header->account, $type, MediaTypeMapper::class, 'doc_type', $request->getOrigin()); - $this->createStandardCreateResponse($request, $response, $type); - } - - /** - * Method to create task from request. - * - * @param RequestAbstract $request Request - * - * @return MediaType - * - * @since 1.0.0 - */ - private function createDocTypeFromRequest(RequestAbstract $request) : MediaType - { - $type = new MediaType(); - $type->name = $request->getDataString('name') ?? ''; - - if ($request->hasData('title')) { - $type->setL11n( - $request->getDataString('title') ?? '', - ISO639x1Enum::tryFromValue($request->getDataString('lang')) ?? $request->header->l11n->language - ); - } - - return $type; - } - - /** - * Validate l11n create request - * - * @param RequestAbstract $request Request - * - * @return array - * - * @since 1.0.0 - */ - private function validateMediaTypeL11nCreate(RequestAbstract $request) : array - { - $val = []; - if (($val['title'] = !$request->hasData('title')) - || ($val['type'] = !$request->hasData('type')) - ) { - return $val; - } - - return []; - } - - /** - * Api method to create media type localization - * - * @param RequestAbstract $request Request - * @param ResponseAbstract $response Response - * @param array $data Generic data - * - * @return void - * - * @api - * - * @since 1.0.0 - */ - public function apiMediaTypeL11nCreate(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void - { - if (!empty($val = $this->validateMediaTypeL11nCreate($request))) { - $response->header->status = RequestStatusCode::R_400; - $this->createInvalidCreateResponse($request, $response, $val); - - return; - } - - $l11nMediaType = $this->createMediaTypeL11nFromRequest($request); - $this->createModel($request->header->account, $l11nMediaType, MediaTypeL11nMapper::class, 'media_type_l11n', $request->getOrigin()); - $this->createStandardCreateResponse($request, $response, $l11nMediaType); - } - - /** - * Method to create media type localization from request. - * - * @param RequestAbstract $request Request - * - * @return BaseStringL11n - * - * @since 1.0.0 - */ - private function createMediaTypeL11nFromRequest(RequestAbstract $request) : BaseStringL11n - { - $l11nMediaType = new BaseStringL11n(); - $l11nMediaType->ref = $request->getDataInt('type') ?? 0; - $l11nMediaType->content = $request->getDataString('title') ?? ''; - $l11nMediaType->language = ISO639x1Enum::tryFromValue($request->getDataString('language')) ?? $request->header->l11n->language; - - return $l11nMediaType; - } - /** * Resize image file * diff --git a/Controller/BackendController.php b/Controller/BackendController.php index e294cf1..f8324e8 100755 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -22,8 +22,6 @@ use Modules\Media\Models\CollectionMapper; use Modules\Media\Models\Media; use Modules\Media\Models\MediaClass; use Modules\Media\Models\MediaMapper; -use Modules\Media\Models\MediaTypeL11nMapper; -use Modules\Media\Models\MediaTypeMapper; use Modules\Media\Models\NullMedia; use Modules\Media\Models\PermissionCategory; use Modules\Media\Theme\Backend\Components\Media\ElementView; @@ -390,47 +388,11 @@ final class BackendController extends Controller $settings = SettingMapper::getAll()->where('module', $id)->executeGetArray(); $view->data['settings'] = $settings; - $types = MediaTypeMapper::getAll()->with('title')->where('title/language', $response->header->l11n->language)->executeGetArray(); - $view->data['types'] = $types; - $view->setTemplate('/Modules/' . static::NAME . '/Admin/Settings/Theme/Backend/settings'); return $view; } - /** - * Routing end-point for application behavior. - * - * @param RequestAbstract $request Request - * @param ResponseAbstract $response Response - * @param array $data Generic data - * - * @return RenderableInterface - * - * @since 1.0.0 - * @codeCoverageIgnore - */ - public function viewMediaTypeSettings(RequestAbstract $request, ResponseAbstract $response, array $data = []) : RenderableInterface - { - $view = new View($this->app->l11nManager, $request, $response); - $view->setTemplate('/Modules/' . static::NAME . '/Admin/Settings/Theme/Backend/settings-type'); - - /** @var \phpOMS\Localization\BaseStringL11n $type */ - $type = MediaTypeMapper::get() - ->with('title') - ->where('title/language', $response->header->l11n->language) - ->where('id', (int) $request->getData('id')) - ->execute(); - - $view->data['nav'] = $this->app->moduleManager->get('Navigation')->createNavigationMid(1007501001, $request, $response); - $view->data['type'] = $type; - - $l11n = MediaTypeL11nMapper::getAll()->where('type', $type->id)->executeGetArray(); - $view->data['l11n'] = $l11n; - - return $view; - } - /** * Routing end-point for application behavior. * diff --git a/Models/Media.php b/Models/Media.php index bab42a5..8a64a35 100755 --- a/Models/Media.php +++ b/Models/Media.php @@ -16,7 +16,6 @@ namespace Modules\Media\Models; use Modules\Admin\Models\Account; use Modules\Admin\Models\NullAccount; -use Modules\Tag\Models\Tag; use phpOMS\Security\EncryptionHelper; /** @@ -53,14 +52,6 @@ class Media implements \JsonSerializable */ public ?MediaContent $content = null; - /** - * Type. - * - * @var MediaType[] - * @since 1.0.0 - */ - public array $types = []; - /** * Extension. * @@ -189,14 +180,6 @@ class Media implements \JsonSerializable */ public ?int $unit = null; - /** - * Tags. - * - * @var Tag[] - * @since 1.0.0 - */ - public array $tags = []; - /** * Language. * @@ -396,104 +379,18 @@ class Media implements \JsonSerializable } /** - * Adding new type. + * Has media tag by id * - * @param MediaType $type MediaType - * - * @return int - * - * @since 1.0.0 - */ - public function addMediaType(MediaType $type) : int - { - $this->types[] = $type; - - \end($this->types); - $key = (int) \key($this->types); - \reset($this->types); - - return $key; - } - - /** - * Remove MediaType from list. - * - * @param int $id MediaType + * @param int $id Media tag id * * @return bool * * @since 1.0.0 */ - public function removeMediaType($id) : bool + public function hasMediaTagId(int $id) : bool { - if (isset($this->types[$id])) { - unset($this->types[$id]); - - return true; - } - - return false; - } - - /** - * Get media types. - * - * @return MediaType[] - * - * @since 1.0.0 - */ - public function getMediaTypes() : array - { - return $this->types; - } - - /** - * Get media type. - * - * @param int $id Element id - * - * @return MediaType - * - * @since 1.0.0 - */ - public function getMediaType(int $id) : MediaType - { - return $this->types[$id] ?? new NullMediaType(); - } - - /** - * Get media type by name - * - * @param string $name Type name - * - * @return MediaType - * - * @since 1.0.0 - */ - public function getMediaTypeName(string $name) : MediaType - { - foreach ($this->types as $type) { - if ($type->name === $name) { - return $type; - } - } - - return new NullMediaType(); - } - - /** - * Has media type by id - * - * @param int $id Media type id - * - * @return bool - * - * @since 1.0.0 - */ - public function hasMediaTypeId(int $id) : bool - { - foreach ($this->types as $type) { - if ($type->id === $id) { + foreach ($this->tags as $tag) { + if ($tag->id === $id) { return true; } } @@ -502,18 +399,18 @@ class Media implements \JsonSerializable } /** - * Has media type by name + * Has media tag by name * - * @param string $name Media type name + * @param string $name Media tag name * * @return bool * * @since 1.0.0 */ - public function hasMediaTypeName(string $name) : bool + public function hasMediaTagName(string $name) : bool { - foreach ($this->types as $type) { - if ($type->name === $name) { + foreach ($this->tags as $tag) { + if ($tag->name === $name) { return true; } } @@ -521,46 +418,6 @@ class Media implements \JsonSerializable return false; } - /** - * 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; - } - /** * {@inheritdoc} */ @@ -589,4 +446,6 @@ class Media implements \JsonSerializable { return $this->toArray(); } + + use \Modules\Tag\Models\TagListTrait; } diff --git a/Models/MediaListTrait.php b/Models/MediaListTrait.php index ffe141e..f98dc3b 100644 --- a/Models/MediaListTrait.php +++ b/Models/MediaListTrait.php @@ -35,18 +35,18 @@ trait MediaListTrait public array $files = []; /** - * Get media file by type + * Get media file by tag * - * @param int $type Media type + * @param int $tag Media tag * * @return Media * * @since 1.0.0 */ - public function getFileByType(int $type) : Media + public function getFileByTag(int $tag) : Media { foreach ($this->files as $file) { - if ($file->hasMediaTypeId($type)) { + if ($file->hasMediaTagId($tag)) { return $file; } } @@ -55,18 +55,18 @@ trait MediaListTrait } /** - * Get all media files by type name + * Get all media files by tag name * - * @param string $type Media type + * @param string $tag Media tag * * @return Media * * @since 1.0.0 */ - public function getFileByTypeName(string $type) : Media + public function getFileByTagName(string $tag) : Media { foreach ($this->files as $file) { - if ($file->hasMediaTypeName($type)) { + if ($file->hasMediaTagName($tag)) { return $file; } } @@ -75,19 +75,19 @@ trait MediaListTrait } /** - * Get all media files by type name + * Get all media files by tag name * - * @param string $type Media type + * @param string $tag Media tag * * @return Media[] * * @since 1.0.0 */ - public function getFilesByTypeName(string $type) : array + public function getFilesByTagName(string $tag) : array { $files = []; foreach ($this->files as $file) { - if ($file->hasMediaTypeName($type)) { + if ($file->hasMediaTagName($tag)) { $files[] = $file; } } @@ -96,18 +96,18 @@ trait MediaListTrait } /** - * Check if file with a certain type name exists + * Check if file with a certain tag name exists * - * @param string $type Type name + * @param string $tag Tag name * * @return bool * * @since 1.0.0 */ - public function hasFileTypeName(string $type) : bool + public function hasFileTagName(string $tag) : bool { foreach ($this->files as $file) { - if ($file->hasMediaTypeName($type)) { + if ($file->hasMediaTagName($tag)) { return true; } } diff --git a/Models/MediaMapper.php b/Models/MediaMapper.php index e3235b1..208f5ac 100755 --- a/Models/MediaMapper.php +++ b/Models/MediaMapper.php @@ -106,12 +106,6 @@ class MediaMapper extends DataMapperFactory 'external' => 'media_tag_dst', 'self' => 'media_tag_src', ], - 'types' => [ - 'mapper' => MediaTypeMapper::class, - 'table' => 'media_type_rel', - 'external' => 'media_type_rel_dst', - 'self' => 'media_type_rel_src', - ], ]; /** @@ -182,8 +176,6 @@ class MediaMapper extends DataMapperFactory /** * Get parent collection * - * WARNING: THIS IS NOT RETURNING THE COLLECTION OF A MEDIA OBJECT BUT ITS PARENT!!! - * * @param string $path Virtual path * * @return ReadMapper @@ -196,9 +188,6 @@ class MediaMapper extends DataMapperFactory $name = \basename($path); $virtualPath = '/' . \trim(\dirname($path), '/'); - //$virtualPath = '/' . \trim(\substr($path, 0, \strripos($path, '/') + 1), '/'); - //$name = \substr($path, \strripos($path, '/') + 1); - return CollectionMapper::get() ->with('sources') ->with('source') diff --git a/Models/MediaType.php b/Models/MediaType.php deleted file mode 100755 index 5d4b867..0000000 --- a/Models/MediaType.php +++ /dev/null @@ -1,129 +0,0 @@ -setL11n($name); - } - - /** - * @return string - * - * @since 1.0.0 - */ - public function getL11n() : string - { - return $this->title instanceof BaseStringL11n ? $this->title->content : $this->title; - } - - /** - * Set title - * - * @param string|BaseStringL11n $title Media article title - * @param string $lang Language - * - * @return void - * - * @since 1.0.0 - */ - public function setL11n(string | BaseStringL11n $title, string $lang = ISO639x1Enum::_EN) : void - { - if ($title instanceof BaseStringL11n) { - $this->title = $title; - } elseif ($this->title instanceof BaseStringL11n) { - $this->title->content = $title; - } else { - $this->title = new BaseStringL11n(); - $this->title->ref = $this->id; - $this->title->content = $title; - $this->title->language = $lang; - } - } - - /** - * {@inheritdoc} - */ - public function toArray() : array - { - return [ - 'id' => $this->id, - 'title' => $this->title, - 'name' => $this->name, - ]; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return $this->toArray(); - } -} diff --git a/Models/MediaTypeL11nMapper.php b/Models/MediaTypeL11nMapper.php deleted file mode 100755 index 7de59e4..0000000 --- a/Models/MediaTypeL11nMapper.php +++ /dev/null @@ -1,69 +0,0 @@ - - */ -final class MediaTypeL11nMapper extends DataMapperFactory -{ - /** - * Columns. - * - * @var array - * @since 1.0.0 - */ - public const COLUMNS = [ - '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' => 'content', 'autocomplete' => true], - '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'], - ]; - - /** - * Primary table. - * - * @var string - * @since 1.0.0 - */ - public const TABLE = 'media_type_l11n'; - - /** - * Primary field name. - * - * @var string - * @since 1.0.0 - */ - public const PRIMARYFIELD = 'media_type_l11n_id'; - - /** - * Model to use by the mapper. - * - * @var class-string - * @since 1.0.0 - */ - public const MODEL = BaseStringL11n::class; -} diff --git a/Models/MediaTypeMapper.php b/Models/MediaTypeMapper.php deleted file mode 100755 index 44b332b..0000000 --- a/Models/MediaTypeMapper.php +++ /dev/null @@ -1,83 +0,0 @@ - - */ -final class MediaTypeMapper extends DataMapperFactory -{ - /** - * Columns. - * - * @var array - * @since 1.0.0 - */ - public const COLUMNS = [ - 'media_type_id' => ['name' => 'media_type_id', 'type' => 'int', 'internal' => 'id'], - 'media_type_name' => ['name' => 'media_type_name', 'type' => 'string', 'internal' => 'name'], - 'media_type_isvisible' => ['name' => 'media_type_isvisible', 'type' => 'bool', 'internal' => 'isVisible'], - ]; - - /** - * Has many relation. - * - * @var array - * @since 1.0.0 - */ - public const HAS_MANY = [ - 'title' => [ - 'mapper' => MediaTypeL11nMapper::class, - 'table' => 'media_type_l11n', - 'self' => 'media_type_l11n_type', - 'column' => 'content', - 'external' => null, - ], - ]; - - /** - * Model to use by the mapper. - * - * @var class-string - * @since 1.0.0 - */ - public const MODEL = MediaType::class; - - /** - * Primary table. - * - * @var string - * @since 1.0.0 - */ - public const TABLE = 'media_type'; - - /** - * Primary field name. - * - * @var string - * @since 1.0.0 - */ - public const PRIMARYFIELD = 'media_type_id'; -} diff --git a/Models/NullMediaType.php b/Models/NullMediaType.php deleted file mode 100644 index cdd5bd8..0000000 --- a/Models/NullMediaType.php +++ /dev/null @@ -1,46 +0,0 @@ -id = $id; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return ['id' => $this->id]; - } -} diff --git a/Theme/Backend/Components/Media/list.tpl.php b/Theme/Backend/Components/Media/list.tpl.php index 616650b..f9b31fe 100755 --- a/Theme/Backend/Components/Media/list.tpl.php +++ b/Theme/Backend/Components/Media/list.tpl.php @@ -25,7 +25,7 @@ $next = empty($this->media) ? '{%}' : '{%}?{?}&mpivot=' . \end($this->media)->id . '&mptype=n'; ?> -
+
getHtml('Media', 'Media'); ?>download
@@ -66,4 +66,4 @@ $next = empty($this->media) getHtml('Next', '0', '0'); ?> --> - \ No newline at end of file + \ No newline at end of file diff --git a/Theme/Backend/Components/Upload/upload-list.tpl.php b/Theme/Backend/Components/Upload/upload-list.tpl.php index bc8761c..2f28ef8 100755 --- a/Theme/Backend/Components/Upload/upload-list.tpl.php +++ b/Theme/Backend/Components/Upload/upload-list.tpl.php @@ -17,7 +17,7 @@ use phpOMS\Uri\UriFactory; ?>
-
+
getHtml('Upload', 'Media', 'Backend'); ?>
@@ -61,7 +61,7 @@ use phpOMS\Uri\UriFactory;
-
+
getHtml('Files', 'Media', 'Backend'); ?>download
diff --git a/Theme/Backend/media-collection-create.tpl.php b/Theme/Backend/media-collection-create.tpl.php index 3b75393..62c300b 100755 --- a/Theme/Backend/media-collection-create.tpl.php +++ b/Theme/Backend/media-collection-create.tpl.php @@ -29,8 +29,8 @@ use phpOMS\Uri\UriFactory;
-
-
+
+
getHtml('CreateCollection'); ?>
@@ -61,6 +61,6 @@ use phpOMS\Uri\UriFactory;
-
+
\ No newline at end of file diff --git a/Theme/Backend/media-file-create.tpl.php b/Theme/Backend/media-file-create.tpl.php index 7ef4bb3..f2c175a 100755 --- a/Theme/Backend/media-file-create.tpl.php +++ b/Theme/Backend/media-file-create.tpl.php @@ -20,17 +20,17 @@ use phpOMS\Uri\UriFactory; ?>
-
+
-
+
-
+
getData('editor')->render('editor'); ?>
-
+
getData('editor')->getData('text')->render('editor', 'content', 'fEditor'); ?> @@ -42,7 +42,7 @@ use phpOMS\Uri\UriFactory; getHtml('Back'); ?>
-
+
getHtml('Settings'); ?>
@@ -64,9 +64,9 @@ use phpOMS\Uri\UriFactory;
-
+ -
+
@@ -79,7 +79,7 @@ use phpOMS\Uri\UriFactory;
-
+ diff --git a/Theme/Backend/media-list.tpl.php b/Theme/Backend/media-list.tpl.php index 52f2f69..578b275 100755 --- a/Theme/Backend/media-list.tpl.php +++ b/Theme/Backend/media-list.tpl.php @@ -90,7 +90,7 @@ $next = empty($media) ? '{/base}/media/list' : '{/base}/media/list?{?}&offse
-
+
getHtml('Media'); ?>download
@@ -249,6 +249,6 @@ $next = empty($media) ? '{/base}/media/list' : '{/base}/media/list?{?}&offse getHtml('Download'); ?>
-
+
diff --git a/Theme/Backend/media-upload.tpl.php b/Theme/Backend/media-upload.tpl.php index 8424826..f290c40 100755 --- a/Theme/Backend/media-upload.tpl.php +++ b/Theme/Backend/media-upload.tpl.php @@ -29,8 +29,8 @@ use phpOMS\Uri\UriFactory;
-
-
+
+
getHtml('Upload'); ?>
@@ -60,7 +60,7 @@ use phpOMS\Uri\UriFactory;
-
- + +
\ No newline at end of file diff --git a/info.json b/info.json index 89a1a37..2bfc281 100755 --- a/info.json +++ b/info.json @@ -24,8 +24,8 @@ }, "providing": { "Navigation": "*", - "Media": "*", - "Search": "*" + "Search": "*", + "Tag": "*" }, "load": [ { diff --git a/tests/Models/MediaTypeTest.php b/tests/Models/MediaTypeTest.php deleted file mode 100755 index 9150960..0000000 --- a/tests/Models/MediaTypeTest.php +++ /dev/null @@ -1,69 +0,0 @@ -type = new MediaType(); - } - - #[\PHPUnit\Framework\Attributes\Group('module')] - public function testDefault() : void - { - self::assertEquals(0, $this->type->id); - self::assertEquals('', $this->type->name); - } - - #[\PHPUnit\Framework\Attributes\Group('module')] - public function testL11nInputOutput() : void - { - $this->type->setL11n('Test1'); - self::assertEquals('Test1', $this->type->getL11n()); - - $this->type->setL11n(new BaseStringL11n('Test2')); - self::assertEquals('Test2', $this->type->getL11n()); - } - - #[\PHPUnit\Framework\Attributes\Group('module')] - public function testSerialize() : void - { - $this->type->name = 'Name'; - - $serialized = $this->type->jsonSerialize(); - unset($serialized['title']); - - self::assertEquals( - [ - 'id' => 0, - 'name' => 'Name', - ], - $serialized - ); - } -} diff --git a/tests/Models/NullMediaTypeTest.php b/tests/Models/NullMediaTypeTest.php deleted file mode 100755 index dc3c1c3..0000000 --- a/tests/Models/NullMediaTypeTest.php +++ /dev/null @@ -1,44 +0,0 @@ -id); - } - - #[\PHPUnit\Framework\Attributes\Group('module')] - public function testJsonSerialize() : void - { - $null = new NullMediaType(2); - self::assertEquals(['id' => 2], $null->jsonSerialize()); - } -}