always use and many other todo implementations

This commit is contained in:
Dennis Eichhorn 2022-03-17 22:39:51 +01:00
parent 7227aabc9b
commit c91c5a56a5
11 changed files with 108 additions and 22 deletions

View File

@ -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']);
}

View File

@ -109,8 +109,8 @@
"type": "TINYINT",
"null": false
},
"media_hidden": {
"name": "media_hidden",
"media_status": {
"name": "media_status",
"type": "TINYINT",
"null": false
},

View File

@ -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

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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,

View File

@ -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;
}

View File

@ -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);
}
/**

43
Models/MediaStatus.php Normal file
View File

@ -0,0 +1,43 @@
<?php
/**
* Karaka
*
* PHP Version 8.0
*
* @package Modules\Media\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://karaka.app
*/
declare(strict_types=1);
namespace Modules\Media\Models;
/**
* Media class.
*
* @package Modules\Media\Models
* @license OMS License 1.0
* @link https://karaka.app
* @since 1.0.0
*/
use phpOMS\Stdlib\Base\Enum;
/**
* Media status enum.
*
* @package phpOMS\DataStorage\Database
* @license OMS License 1.0
* @link https://karaka.app
* @since 1.0.0
*/
abstract class MediaStatus extends Enum
{
public const NORMAL = 1;
public const HIDDEN = 2;
public const DELETED = 3;
}

View File

@ -25,6 +25,8 @@ $view = $this->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();
</div>
</div>
<div class="row">
<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 = '';
$paths = \explode('/', \ltrim($mediaPath, '/'));
$length = \count($paths);
$parentPath = '';
for ($i = 0; $i < $length; ++$i) :
if ($paths[$i] === '') {
continue;
}
if ($i === $length - 1) {
$parentPath = $subPath === '' ? '/' : $subPath;
}
$subPath .= '/' . $paths[$i];
$url = UriFactory::build('{/prefix}media/list?path=' . $subPath);
?>
<li data-href="<?= $url; ?>"<?= $i === $length - 1 ? 'class="active"' : ''; ?>><a href="<?= $url; ?>"><?= $this->printHtml($paths[$i]); ?></a></li>
<?php endfor; ?>
</ul>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<section class="portlet">

View File

@ -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,
],