From c91c5a56a55aab0cf1f27c36685a9456a4a48090 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Thu, 17 Mar 2022 22:39:51 +0100 Subject: [PATCH] always use and many other todo implementations --- Admin/Install/Navigation.php | 4 +-- Admin/Install/db.json | 4 +-- Admin/Installer.php | 4 +-- Controller/BackendController.php | 4 +++ Models/CollectionMapper.php | 6 ++--- Models/Media.php | 6 ++--- Models/MediaClass.php | 8 ++++-- Models/MediaMapper.php | 8 +++--- Models/MediaStatus.php | 43 ++++++++++++++++++++++++++++++ Theme/Backend/media-single.tpl.php | 34 +++++++++++++++++++++++ tests/Models/MediaTest.php | 9 ++++--- 11 files changed, 108 insertions(+), 22 deletions(-) create mode 100644 Models/MediaStatus.php diff --git a/Admin/Install/Navigation.php b/Admin/Install/Navigation.php index 355c2f9..8242ba2 100755 --- a/Admin/Install/Navigation.php +++ b/Admin/Install/Navigation.php @@ -29,14 +29,14 @@ class Navigation /** * Install navigation providing * - * @param string $path Module path * @param ApplicationAbstract $app Application + * @param string $path Module path * * @return void * * @since 1.0.0 */ - public static function install(string $path, ApplicationAbstract $app) : void + public static function install(ApplicationAbstract $app, string $path) : void { \Modules\Navigation\Admin\Installer::installExternal($app, ['path' => __DIR__ . '/Navigation.install.json']); } diff --git a/Admin/Install/db.json b/Admin/Install/db.json index 689249e..31059fd 100755 --- a/Admin/Install/db.json +++ b/Admin/Install/db.json @@ -109,8 +109,8 @@ "type": "TINYINT", "null": false }, - "media_hidden": { - "name": "media_hidden", + "media_status": { + "name": "media_status", "type": "TINYINT", "null": false }, diff --git a/Admin/Installer.php b/Admin/Installer.php index 2e8ddd6..b7ea350 100755 --- a/Admin/Installer.php +++ b/Admin/Installer.php @@ -56,13 +56,13 @@ final class Installer extends InstallerAbstract /** * {@inheritdoc} */ - public static function install(DatabasePool $dbPool, ModuleInfo $info, SettingsInterface $cfgHandler) : void + public static function install(ApplicationAbstract $app, ModuleInfo $info, SettingsInterface $cfgHandler) : void { if (!\is_dir(__DIR__ . '/../Files')) { \mkdir(__DIR__ . '/../Files'); } - parent::install($dbPool, $info, $cfgHandler); + parent::install($app, $info, $cfgHandler); // Create directory for admin account // All other accounts are automatically created in the admin module whenever they get created diff --git a/Controller/BackendController.php b/Controller/BackendController.php index ea53f93..68f8282 100755 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -21,6 +21,7 @@ use Modules\Admin\Models\PermissionAbstractMapper; use Modules\Media\Models\Collection; use Modules\Media\Models\CollectionMapper; use Modules\Media\Models\Media; +use Modules\Media\Models\MediaClass; use Modules\Media\Models\MediaMapper; use Modules\Media\Models\MediaTypeMapper; use Modules\Media\Models\MediaTypeL11nMapper; @@ -173,6 +174,9 @@ final class BackendController extends Controller $localMedia->extension = \is_dir($file) ? 'collection' : $pathinfo['extension'] ?? ''; $localMedia->setVirtualPath($path); $localMedia->createdBy = new Account(); + $localMedia->class = $localMedia->extension === 'collection' + ? MediaClass::SYSTEM_DIRECTORY + : MediaClass::SYSTEM_FILE; $unIndexedFiles[] = $localMedia; } diff --git a/Models/CollectionMapper.php b/Models/CollectionMapper.php index 36acf87..b7444c3 100755 --- a/Models/CollectionMapper.php +++ b/Models/CollectionMapper.php @@ -66,18 +66,18 @@ final class CollectionMapper extends MediaMapper * path if so desired without deleting or moving the orginal media files. * * @param string $virtualPath Virtual path - * @param bool $hidden Get hidden files + * @param int $status Media status * * @return ReadMapper * * @since 1.0.0 */ - public static function getByVirtualPath(string $virtualPath = '/', bool $hidden = false) : ReadMapper + public static function getByVirtualPath(string $virtualPath = '/', int $status = MediaStatus::NORMAL) : ReadMapper { return self::getAll()->where('virtualPath', $virtualPath) ->with('createdBy') ->with('tags') - ->where('isHidden', $hidden) + ->where('status', $status) ->where('class', MediaClass::COLLECTION); } diff --git a/Models/Media.php b/Models/Media.php index 7419839..eaa23bc 100755 --- a/Models/Media.php +++ b/Models/Media.php @@ -168,10 +168,10 @@ class Media implements \JsonSerializable /** * Media is hidden. * - * @var bool + * @var int * @since 1.0.0 */ - public bool $isHidden = false; + public int $status = MediaStatus::NORMAL; /** * Media class. @@ -438,7 +438,7 @@ class Media implements \JsonSerializable 'extension' => $this->extension, 'virtualpath' => $this->virtualPath, 'size' => $this->size, - 'hidden' => $this->isHidden, + 'status' => $this->status, 'path' => $this->path, 'absolute' => $this->isAbsolute, 'createdBy' => $this->createdBy, diff --git a/Models/MediaClass.php b/Models/MediaClass.php index eaac6fc..8e10ad2 100644 --- a/Models/MediaClass.php +++ b/Models/MediaClass.php @@ -25,9 +25,9 @@ namespace Modules\Media\Models; use phpOMS\Stdlib\Base\Enum; /** - * Database type enum. + * Media class enum. * - * Database types that are supported by the application + * Used to differentiate the type/class of media * * @package phpOMS\DataStorage\Database * @license OMS License 1.0 @@ -42,4 +42,8 @@ abstract class MediaClass extends Enum public const REFERENCE = 2; + public const SYSTEM_FILE = 3; + + public const SYSTEM_DIRECTORY = 4; + } \ No newline at end of file diff --git a/Models/MediaMapper.php b/Models/MediaMapper.php index 13f2dbd..d4e16a7 100755 --- a/Models/MediaMapper.php +++ b/Models/MediaMapper.php @@ -43,7 +43,7 @@ class MediaMapper extends DataMapperFactory 'media_description_raw' => ['name' => 'media_description_raw', 'type' => 'string', 'internal' => 'descriptionRaw'], 'media_content' => ['name' => 'media_content', 'type' => 'int', 'internal' => 'content'], 'media_versioned' => ['name' => 'media_versioned', 'type' => 'bool', 'internal' => 'isVersioned'], - 'media_hidden' => ['name' => 'media_hidden', 'type' => 'bool', 'internal' => 'isHidden'], + 'media_status' => ['name' => 'media_status', 'type' => 'bool', 'internal' => 'status'], 'media_file' => ['name' => 'media_file', 'type' => 'string', 'internal' => 'path', 'autocomplete' => true], 'media_virtual' => ['name' => 'media_virtual', 'type' => 'string', 'internal' => 'virtualPath', 'autocomplete' => true], 'media_absolute' => ['name' => 'media_absolute', 'type' => 'bool', 'internal' => 'isAbsolute'], @@ -154,13 +154,13 @@ class MediaMapper extends DataMapperFactory * path if so desired without deleting or moving the orginal media files. * * @param string $virtualPath Virtual path - * @param bool $hidden Get hidden files + * @param int $status Media status * * @return ReadMapper * * @since 1.0.0 */ - public static function getByVirtualPath(string $virtualPath = '/', bool $hidden = false) : ReadMapper + public static function getByVirtualPath(string $virtualPath = '/', int $status = MediaStatus::NORMAL) : ReadMapper { return self::getAll() ->with('createdBy') @@ -168,7 +168,7 @@ class MediaMapper extends DataMapperFactory ->with('tags') ->with('tags/title') ->where('virtualPath', $virtualPath) - ->where('isHidden', $hidden); + ->where('status', $status); } /** diff --git a/Models/MediaStatus.php b/Models/MediaStatus.php new file mode 100644 index 0000000..36199c1 --- /dev/null +++ b/Models/MediaStatus.php @@ -0,0 +1,43 @@ +getData('view'); /** @var \Modules\Tag\Models\Tag[] $tag */ $tags = $media->getTags(); +$mediaPath = \urldecode($media->getVirtualPath() ?? '/'); + /** @var \phpOMS\Message\Http\HttpRequest $this->request */ echo $this->getData('nav')->render(); @@ -41,6 +43,38 @@ echo $this->getData('nav')->render(); +
+
+
+ +
+
+
+
diff --git a/tests/Models/MediaTest.php b/tests/Models/MediaTest.php index e5812c9..0416205 100755 --- a/tests/Models/MediaTest.php +++ b/tests/Models/MediaTest.php @@ -16,6 +16,7 @@ namespace Modules\Media\tests\Models; use Modules\Admin\Models\NullAccount; use Modules\Media\Models\Media; +use Modules\Media\Models\MediaStatus; use Modules\Tag\Models\Tag; /** @@ -164,8 +165,8 @@ final class MediaTest extends \PHPUnit\Framework\TestCase */ public function testHiddenInputOutput() : void { - $this->media->isHidden = true; - self::assertTrue($this->media->isHidden); + $this->media->status = MediaStatus::HIDDEN; + self::assertEquals(MediaStatus::HIDDEN, $this->media->status); } /** @@ -236,7 +237,7 @@ final class MediaTest extends \PHPUnit\Framework\TestCase $this->media->size = 11; $this->media->isVersioned = true; $this->media->setVirtualPath('/test/path'); - $this->media->isHidden = true; + $this->media->status = MediaStatus::HIDDEN; self::assertEquals($this->media->toArray(), $this->media->jsonSerialize()); @@ -252,7 +253,7 @@ final class MediaTest extends \PHPUnit\Framework\TestCase 'extension' => 'pdf', 'virtualpath' => '/test/path', 'size' => 11, - 'hidden' => true, + 'status' => MediaStatus::HIDDEN, 'path' => '/home/root', 'absolute' => true, ],