new datamapper mostly implemented

This commit is contained in:
Dennis Eichhorn 2021-12-11 11:54:17 +01:00
parent f3d2f51d38
commit df0105c0b2
12 changed files with 98 additions and 104 deletions

View File

@ -69,7 +69,7 @@ final class Installer extends InstallerAbstract
// However, the admin account is created before the Media module is installed // However, the admin account is created before the Media module is installed
// Because of this, the directory needs to be created manually after the Media installation // Because of this, the directory needs to be created manually after the Media installation
// The admin account should be the only DB account, but we use a loop of all accounts to avoid bugs // The admin account should be the only DB account, but we use a loop of all accounts to avoid bugs
$accounts = AccountMapper::getAll(); $accounts = AccountMapper::getAll()->execute();
foreach ($accounts as $account) { foreach ($accounts as $account) {
$collection = new Collection(); $collection = new Collection();
@ -79,7 +79,7 @@ final class Installer extends InstallerAbstract
// The installation is always run by the admin account since the module is a "base" module which is always installed during the application setup // The installation is always run by the admin account since the module is a "base" module which is always installed during the application setup
$collection->createdBy = new NullAccount(1); $collection->createdBy = new NullAccount(1);
CollectionMapper::create($collection); CollectionMapper::create()->execute($collection);
} }
} }
@ -176,7 +176,7 @@ final class Installer extends InstallerAbstract
$collection->setPath($path); $collection->setPath($path);
$collection->createdBy = new NullAccount((int) $data['user'] ?? 1); $collection->createdBy = new NullAccount((int) $data['user'] ?? 1);
CollectionMapper::create($collection); CollectionMapper::create()->execute($collection);
if ($data['create_directory'] && !\is_dir($dirPath)) { if ($data['create_directory'] && !\is_dir($dirPath)) {
// @todo fix permission mode // @todo fix permission mode
@ -201,13 +201,13 @@ final class Installer extends InstallerAbstract
$type = new MediaType(); $type = new MediaType();
$type->name = $data['name'] ?? ''; $type->name = $data['name'] ?? '';
$id = MediaTypeMapper::create($type); $id = MediaTypeMapper::create()->execute($type);
foreach ($data['l11n'] as $l11n) { foreach ($data['l11n'] as $l11n) {
$l11n = new MediaTypeL11n($l11n['title'], $l11n['lang']); $l11n = new MediaTypeL11n($l11n['title'], $l11n['lang']);
$l11n->type = $id; $l11n->type = $id;
MediaTypeL11nMapper::create($l11n); MediaTypeL11nMapper::create()->execute($l11n);
} }
return $type; return $type;
@ -279,7 +279,7 @@ final class Installer extends InstallerAbstract
$media->setVirtualPath((string) ($data['virtualPath'] ?? '/')); $media->setVirtualPath((string) ($data['virtualPath'] ?? '/'));
$media->type = $data['media_type'] ?? null; // = identifier for modules $media->type = $data['media_type'] ?? null; // = identifier for modules
MediaMapper::create($media); MediaMapper::create()->execute($media);
$mediaFiles[] = $media; $mediaFiles[] = $media;
} }
@ -293,7 +293,7 @@ final class Installer extends InstallerAbstract
$collection->setSources($mediaFiles); $collection->setSources($mediaFiles);
CollectionMapper::create($collection); CollectionMapper::create()->execute($collection);
return [$collection]; return [$collection];
} }

View File

@ -296,7 +296,7 @@ final class ApiController extends Controller
$media->setVirtualPath($virtualPath); $media->setVirtualPath($virtualPath);
$media->type = \is_int($type) ? new NullMediaType($type) : null; $media->type = \is_int($type) ? new NullMediaType($type) : null;
MediaMapper::create($media); MediaMapper::create()->execute($media);
return $media; return $media;
} }
@ -340,7 +340,7 @@ final class ApiController extends Controller
public function apiMediaUpdate(RequestAbstract $request, ResponseAbstract $response, $data = null) : void public function apiMediaUpdate(RequestAbstract $request, ResponseAbstract $response, $data = null) : void
{ {
/** @var Media $old */ /** @var Media $old */
$old = clone MediaMapper::get((int) $request->getData('id')); $old = clone MediaMapper::get()->where('id', (int) $request->getData('id'))->execute();
/** @var Media $new */ /** @var Media $new */
$new = $this->updateMediaFromRequest($request); $new = $this->updateMediaFromRequest($request);
@ -363,7 +363,7 @@ final class ApiController extends Controller
$id = (int) $request->getData('id'); $id = (int) $request->getData('id');
/** @var Media $media */ /** @var Media $media */
$media = MediaMapper::get($id); $media = MediaMapper::get()->where('id', $id)->execute();
$media->name = (string) ($request->getData('name') ?? $media->name); $media->name = (string) ($request->getData('name') ?? $media->name);
$media->description = (string) ($request->getData('description') ?? $media->description); $media->description = (string) ($request->getData('description') ?? $media->description);
$media->setPath((string) ($request->getData('path') ?? $media->getPath())); $media->setPath((string) ($request->getData('path') ?? $media->getPath()));
@ -479,7 +479,7 @@ final class ApiController extends Controller
$mediaCollection->setVirtualPath($virtualPath); $mediaCollection->setVirtualPath($virtualPath);
$mediaCollection->setPath($outputDir); $mediaCollection->setPath($outputDir);
CollectionMapper::create($mediaCollection); CollectionMapper::create()->execute($mediaCollection);
return $mediaCollection; return $mediaCollection;
} }
@ -604,7 +604,7 @@ final class ApiController extends Controller
{ {
if (((int) $request->getData('id')) !== 0) { if (((int) $request->getData('id')) !== 0) {
/** @var Media $media */ /** @var Media $media */
$media = MediaMapper::get((int) $request->getData('id')); $media = MediaMapper::get()->where('id', (int) $request->getData('id'))->execute();
} else { } else {
$path = \urldecode($request->getData('path')); $path = \urldecode($request->getData('path'));
$media = new NullMedia(); $media = new NullMedia();

View File

@ -73,8 +73,8 @@ final class BackendController extends Controller
$path = \str_replace('+', ' ', (string) ($request->getData('path') ?? '/')); $path = \str_replace('+', ' ', (string) ($request->getData('path') ?? '/'));
/** @var Media[] $media */ /** @var Media[] $media */
$media = MediaMapper::getByVirtualPath($path); $media = MediaMapper::getByVirtualPath($path)->where('tags/title/language', $request->getLanguage())->execute();
$collection = CollectionMapper::getParentCollection($path); $collection = CollectionMapper::getParentCollection($path)->where('tags/title/language', $request->getLanguage())->execute();
if (\is_array($collection) && \is_dir(__DIR__ . '/../Files' . $path)) { if (\is_array($collection) && \is_dir(__DIR__ . '/../Files' . $path)) {
$collection = new Collection(); $collection = new Collection();
@ -160,13 +160,20 @@ final class BackendController extends Controller
$view->addData('view', $this->createMediaView($media, $request, $response)); $view->addData('view', $this->createMediaView($media, $request, $response));
} }
} else { } else {
$media = MediaMapper::get($id); $media = MediaMapper::get()
->with('createdBy')
->with('tags')
->with('tags/title')
->where('id', $id)
->where('tags/title/language', $request->getLanguage())
->execute();
if ($media->extension === 'collection') { if ($media->extension === 'collection') {
$media = MediaMapper::getByVirtualPath( $media = MediaMapper::getByVirtualPath(
$media->getVirtualPath() . ($media->getVirtualPath() !== '/' ? '/' : '') . $media->name $media->getVirtualPath() . ($media->getVirtualPath() !== '/' ? '/' : '') . $media->name
); )->with('tags/title/language', $request->getLanguage())->execute();
$collection = CollectionMapper::get($id); $collection = CollectionMapper::get()->where('id', $id)->execute();
$media = \array_merge($media, $collection->getSources()); $media = \array_merge($media, $collection->getSources());
$view->addData('path', $collection->getVirtualPath() . '/' . $collection->name); $view->addData('path', $collection->getVirtualPath() . '/' . $collection->name);
@ -285,12 +292,12 @@ final class BackendController extends Controller
$id = $request->getData('id') ?? ''; $id = $request->getData('id') ?? '';
$settings = SettingMapper::getFor($id, 'module'); $settings = SettingMapper::getAll()->where('module', $id)->execute();
if (!($settings instanceof NullSetting)) { if (!($settings instanceof NullSetting)) {
$view->setData('settings', !\is_array($settings) ? [$settings] : $settings); $view->setData('settings', !\is_array($settings) ? [$settings] : $settings);
} }
$types = MediaTypeMapper::with('language', $response->getLanguage())::getAll(); $types = MediaTypeMapper::getAll()->with('title')->where('title/language', $response->getLanguage())->execute();
$view->setData('types', $types); $view->setData('types', $types);
if (\is_file(__DIR__ . '/../Admin/Settings/Theme/Backend/settings.tpl.php')) { if (\is_file(__DIR__ . '/../Admin/Settings/Theme/Backend/settings.tpl.php')) {
@ -319,12 +326,12 @@ 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');
$type = MediaTypeMapper::with('language', $response->getLanguage())::get((int) $request->getData('id')); $type = MediaTypeMapper::get()->with('title')->where('title/language', $response->getLanguage())->where('id', (int) $request->getData('id'))->execute();
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1007501001, $request, $response)); $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1007501001, $request, $response));
$view->addData('type', $type); $view->addData('type', $type);
$l11n = MediaTypeL11nMapper::with('tag', $type->getId())::getAll(); $l11n = MediaTypeL11nMapper::getAll()->where('type', $type->getId())->execute();
$view->addData('l11n', $l11n); $view->addData('l11n', $l11n);
return $view; return $view;

View File

@ -15,7 +15,7 @@ declare(strict_types=1);
namespace Modules\Media\Models; namespace Modules\Media\Models;
use Modules\Admin\Models\Account; use Modules\Admin\Models\Account;
use phpOMS\DataStorage\Database\RelationType; use phpOMS\DataStorage\Database\Mapper\ReadMapper;
/** /**
* Mapper class. * Mapper class.
@ -33,7 +33,7 @@ final class CollectionMapper extends MediaMapper
* @var array<string, array{mapper:string, table:string, self?:?string, external?:?string, column?:string}> * @var array<string, array{mapper:string, table:string, self?:?string, external?:?string, column?:string}>
* @since 1.0.0 * @since 1.0.0
*/ */
protected static array $hasMany = [ public const HAS_MANY = [
'sources' => [ 'sources' => [
'mapper' => MediaMapper::class, 'mapper' => MediaMapper::class,
'table' => 'media_relation', 'table' => 'media_relation',
@ -48,7 +48,7 @@ final class CollectionMapper extends MediaMapper
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
protected static string $model = Collection::class; public const MODEL = Collection::class;
/** /**
* Primary table. * Primary table.
@ -56,7 +56,7 @@ final class CollectionMapper extends MediaMapper
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
protected static string $table = 'media'; public const TABLE = 'media';
/** /**
* Created at. * Created at.
@ -64,7 +64,7 @@ final class CollectionMapper extends MediaMapper
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
protected static string $createdAt = 'media_created_at'; public const CREATED_AT = 'media_created_at';
/** /**
* Primary field name. * Primary field name.
@ -72,7 +72,7 @@ final class CollectionMapper extends MediaMapper
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
protected static string $primaryField = 'media_id'; public const PRIMARYFIELD ='media_id';
/** /**
* Get media based on virtual path. * Get media based on virtual path.
@ -92,22 +92,17 @@ final class CollectionMapper extends MediaMapper
* @param string $virtualPath Virtual path * @param string $virtualPath Virtual path
* @param bool $hidden Get hidden files * @param bool $hidden Get hidden files
* *
* @return array * @return ReadMapper
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public static function getByVirtualPath(string $virtualPath = '/', bool $hidden = false) : array public static function getByVirtualPath(string $virtualPath = '/', bool $hidden = false) : ReadMapper
{ {
$depth = 3; return self::getAll()->where('virtualPath', $virtualPath)
$query = self::getQuery(depth: $depth); ->with('createdBy')
$query->where(self::$table . '_d' . $depth . '.media_virtual', '=', $virtualPath); ->with('tags')
$query->where(self::$table . '_d' . $depth . '.media_collection', '=', 1); ->where('isHidden', $hidden)
->where('collection', true);
if ($hidden === false) {
$query->andWhere(self::$table . '_d' . $depth . '.media_hidden', '=', (int) $hidden);
}
return self::getAllByQuery($query, RelationType::ALL, $depth);
} }
/** /**
@ -123,11 +118,11 @@ final class CollectionMapper extends MediaMapper
public static function getCollectionsByPath(string $virtualPath, bool $showDirectories = false) : array public static function getCollectionsByPath(string $virtualPath, bool $showDirectories = false) : array
{ {
/** @var Media[] $collection */ /** @var Media[] $collection */
$collection = self::getByVirtualPath($virtualPath); $collection = self::getByVirtualPath($virtualPath)->with('sources')->execute();
$parent = []; $parent = [];
if ($showDirectories) { if ($showDirectories) {
$parent = self::getParentCollection($virtualPath); $parent = self::getParentCollection($virtualPath)->execute();
if (\is_array($parent) && \is_dir(__DIR__ . '/../../Media/Files' . $virtualPath)) { if (\is_array($parent) && \is_dir(__DIR__ . '/../../Media/Files' . $virtualPath)) {
$parent = new Collection(); $parent = new Collection();
$parent->name = \basename($virtualPath); $parent->name = \basename($virtualPath);

View File

@ -16,8 +16,8 @@ namespace Modules\Media\Models;
use Modules\Admin\Models\AccountMapper; use Modules\Admin\Models\AccountMapper;
use Modules\Tag\Models\TagMapper; use Modules\Tag\Models\TagMapper;
use phpOMS\DataStorage\Database\DataMapperAbstract; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
use phpOMS\DataStorage\Database\RelationType; use phpOMS\DataStorage\Database\Mapper\ReadMapper;
/** /**
* Media mapper class. * Media mapper class.
@ -27,7 +27,7 @@ use phpOMS\DataStorage\Database\RelationType;
* @link https://orange-management.org * @link https://orange-management.org
* @since 1.0.0 * @since 1.0.0
*/ */
class MediaMapper extends DataMapperAbstract class MediaMapper extends DataMapperFactory
{ {
/** /**
* Columns. * Columns.
@ -35,7 +35,7 @@ class MediaMapper extends DataMapperAbstract
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}> * @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
* @since 1.0.0 * @since 1.0.0
*/ */
protected static array $columns = [ public const COLUMNS = [
'media_id' => ['name' => 'media_id', 'type' => 'int', 'internal' => 'id'], 'media_id' => ['name' => 'media_id', 'type' => 'int', 'internal' => 'id'],
'media_name' => ['name' => 'media_name', 'type' => 'string', 'internal' => 'name', 'autocomplete' => true], 'media_name' => ['name' => 'media_name', 'type' => 'string', 'internal' => 'name', 'autocomplete' => true],
'media_type' => ['name' => 'media_type', 'type' => 'int', 'internal' => 'type'], 'media_type' => ['name' => 'media_type', 'type' => 'int', 'internal' => 'type'],
@ -61,7 +61,7 @@ class MediaMapper extends DataMapperAbstract
* @var array<string, array{mapper:string, external:string}> * @var array<string, array{mapper:string, external:string}>
* @since 1.0.0 * @since 1.0.0
*/ */
protected static array $belongsTo = [ public const BELONGS_TO = [
'createdBy' => [ 'createdBy' => [
'mapper' => AccountMapper::class, 'mapper' => AccountMapper::class,
'external' => 'media_created_by', 'external' => 'media_created_by',
@ -74,7 +74,7 @@ class MediaMapper extends DataMapperAbstract
* @var array<string, array{mapper:string, external:string}> * @var array<string, array{mapper:string, external:string}>
* @since 1.0.0 * @since 1.0.0
*/ */
protected static array $ownsOne = [ public const OWNS_ONE = [
'type' => [ 'type' => [
'mapper' => MediaTypeMapper::class, 'mapper' => MediaTypeMapper::class,
'external' => 'media_type', 'external' => 'media_type',
@ -87,7 +87,7 @@ class MediaMapper extends DataMapperAbstract
* @var array<string, array{mapper:string, table:string, self?:?string, external?:?string, column?:string}> * @var array<string, array{mapper:string, table:string, self?:?string, external?:?string, column?:string}>
* @since 1.0.0 * @since 1.0.0
*/ */
protected static array $hasMany = [ public const HAS_MANY = [
'tags' => [ 'tags' => [
'mapper' => TagMapper::class, 'mapper' => TagMapper::class,
'table' => 'media_tag', 'table' => 'media_tag',
@ -102,7 +102,7 @@ class MediaMapper extends DataMapperAbstract
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
protected static string $model = Media::class; public const MODEL = Media::class;
/** /**
* Primary table. * Primary table.
@ -110,7 +110,7 @@ class MediaMapper extends DataMapperAbstract
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
protected static string $table = 'media'; public const TABLE = 'media';
/** /**
* Created at. * Created at.
@ -118,7 +118,7 @@ class MediaMapper extends DataMapperAbstract
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
protected static string $createdAt = 'media_created_at'; public const CREATED_AT = 'media_created_at';
/** /**
* Primary field name. * Primary field name.
@ -126,7 +126,7 @@ class MediaMapper extends DataMapperAbstract
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
protected static string $primaryField = 'media_id'; public const PRIMARYFIELD ='media_id';
/** /**
* Get media based on virtual path. * Get media based on virtual path.
@ -146,21 +146,18 @@ class MediaMapper extends DataMapperAbstract
* @param string $virtualPath Virtual path * @param string $virtualPath Virtual path
* @param bool $hidden Get hidden files * @param bool $hidden Get hidden files
* *
* @return array * @return ReadMapper
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public static function getByVirtualPath(string $virtualPath = '/', bool $hidden = false) : array public static function getByVirtualPath(string $virtualPath = '/', bool $hidden = false) : ReadMapper
{ {
$depth = 3; return self::getAll()
$query = self::getQuery(depth: $depth); ->with('createdBy')
$query->where(self::$table . '_d' . $depth . '.media_virtual', '=', $virtualPath); ->with('tags')
->with('tags/title')
if ($hidden === false) { ->where('virtualPath', $virtualPath)
$query->andWhere(self::$table . '_d' . $depth . '.media_hidden', '=', (int) $hidden); ->where('isHidden', $hidden);
}
return self::getAllByQuery($query, RelationType::ALL, $depth);
} }
/** /**
@ -168,22 +165,18 @@ class MediaMapper extends DataMapperAbstract
* *
* @param string $path Virtual path * @param string $path Virtual path
* *
* @return mixed * @return ReadMapper
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public static function getParentCollection(string $path = '/') public static function getParentCollection(string $path = '/') : ReadMapper
{ {
$virtualPath = '/' . \trim(\substr($path, 0, \strripos($path, '/') + 1), '/'); $virtualPath = '/' . \trim(\substr($path, 0, \strripos($path, '/') + 1), '/');
$name = \substr($path, \strripos($path, '/') + 1); $name = \substr($path, \strripos($path, '/') + 1);
$depth = 3; return self::get()
$query = self::getQuery(); ->with('sources')
$query->where(self::$table. '_d' . $depth . '.media_virtual', '=', $virtualPath) ->where('virtualPath', $virtualPath)
->andWhere(self::$table. '_d' . $depth . '.media_name', '=', $name); ->where('name', $name);
$objs = self::getAllByQuery($query, RelationType::ALL, $depth);
return \count($objs) === 1 ? \reset($objs) : $objs;
} }
} }

View File

@ -14,7 +14,7 @@ declare(strict_types=1);
namespace Modules\Media\Models; namespace Modules\Media\Models;
use phpOMS\DataStorage\Database\DataMapperAbstract; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
/** /**
* Media type l11n mapper class. * Media type l11n mapper class.
@ -24,7 +24,7 @@ use phpOMS\DataStorage\Database\DataMapperAbstract;
* @link https://orange-management.org * @link https://orange-management.org
* @since 1.0.0 * @since 1.0.0
*/ */
final class MediaTypeL11nMapper extends DataMapperAbstract final class MediaTypeL11nMapper extends DataMapperFactory
{ {
/** /**
* Columns. * Columns.
@ -32,7 +32,7 @@ final class MediaTypeL11nMapper extends DataMapperAbstract
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}> * @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
* @since 1.0.0 * @since 1.0.0
*/ */
protected static array $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' => 'title', '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' => 'type'],
@ -45,7 +45,7 @@ final class MediaTypeL11nMapper extends DataMapperAbstract
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
protected static string $table = 'media_type_l11n'; public const TABLE = 'media_type_l11n';
/** /**
* Primary field name. * Primary field name.
@ -53,5 +53,5 @@ final class MediaTypeL11nMapper extends DataMapperAbstract
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
protected static string $primaryField = 'media_type_l11n_id'; public const PRIMARYFIELD ='media_type_l11n_id';
} }

View File

@ -14,7 +14,7 @@ declare(strict_types=1);
namespace Modules\Media\Models; namespace Modules\Media\Models;
use phpOMS\DataStorage\Database\DataMapperAbstract; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
/** /**
* Media type mapper class. * Media type mapper class.
@ -24,7 +24,7 @@ use phpOMS\DataStorage\Database\DataMapperAbstract;
* @link https://orange-management.org * @link https://orange-management.org
* @since 1.0.0 * @since 1.0.0
*/ */
final class MediaTypeMapper extends DataMapperAbstract final class MediaTypeMapper extends DataMapperFactory
{ {
/** /**
* Columns. * Columns.
@ -32,7 +32,7 @@ final class MediaTypeMapper extends DataMapperAbstract
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}> * @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
* @since 1.0.0 * @since 1.0.0
*/ */
protected static array $columns = [ public const COLUMNS = [
'media_type_id' => ['name' => 'media_type_id', 'type' => 'int', 'internal' => 'id'], 'media_type_id' => ['name' => 'media_type_id', 'type' => 'int', 'internal' => 'id'],
'media_type_name' => ['name' => 'media_type_name', 'type' => 'string', 'internal' => 'name'], 'media_type_name' => ['name' => 'media_type_name', 'type' => 'string', 'internal' => 'name'],
'media_type_isvisible' => ['name' => 'media_type_isvisible', 'type' => 'bool', 'internal' => 'isVisible'], 'media_type_isvisible' => ['name' => 'media_type_isvisible', 'type' => 'bool', 'internal' => 'isVisible'],
@ -44,13 +44,12 @@ final class MediaTypeMapper extends DataMapperAbstract
* @var array<string, array{mapper:string, table:string, self?:?string, external?:?string, column?:string}> * @var array<string, array{mapper:string, table:string, self?:?string, external?:?string, column?:string}>
* @since 1.0.0 * @since 1.0.0
*/ */
protected static array $hasMany = [ public const HAS_MANY = [
'title' => [ 'title' => [
'mapper' => MediaTypeL11nMapper::class, 'mapper' => MediaTypeL11nMapper::class,
'table' => 'media_type_l11n', 'table' => 'media_type_l11n',
'self' => 'media_type_l11n_type', 'self' => 'media_type_l11n_type',
'column' => 'title', 'column' => 'title',
'conditional' => true,
'external' => null, 'external' => null,
], ],
]; ];
@ -61,7 +60,7 @@ final class MediaTypeMapper extends DataMapperAbstract
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
protected static string $model = MediaType::class; public const MODEL = MediaType::class;
/** /**
* Primary table. * Primary table.
@ -69,7 +68,7 @@ final class MediaTypeMapper extends DataMapperAbstract
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
protected static string $table = 'media_type'; public const TABLE = 'media_type';
/** /**
* Primary field name. * Primary field name.
@ -77,5 +76,5 @@ final class MediaTypeMapper extends DataMapperAbstract
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
protected static string $primaryField = 'media_type_id'; public const PRIMARYFIELD ='media_type_id';
} }

View File

@ -12,7 +12,7 @@ require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/Autoloader.php'; require_once __DIR__ . '/Autoloader.php';
use phpOMS\DataStorage\Database\DatabasePool; use phpOMS\DataStorage\Database\DatabasePool;
use phpOMS\DataStorage\Database\DataMapperAbstract; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
use phpOMS\DataStorage\Session\HttpSession; use phpOMS\DataStorage\Session\HttpSession;
$CONFIG = [ $CONFIG = [
@ -329,7 +329,7 @@ $GLOBALS['dbpool']->create('delete', $CONFIG['db']['core']['masters']['delete'])
$GLOBALS['dbpool']->create('insert', $CONFIG['db']['core']['masters']['insert']); $GLOBALS['dbpool']->create('insert', $CONFIG['db']['core']['masters']['insert']);
$GLOBALS['dbpool']->create('schema', $CONFIG['db']['core']['masters']['schema']); $GLOBALS['dbpool']->create('schema', $CONFIG['db']['core']['masters']['schema']);
DataMapperAbstract::setConnection($GLOBALS['dbpool']->get()); DataMapperFactory::db($GLOBALS['dbpool']->get());
$GLOBALS['frameworkpath'] = '/phpOMS/'; $GLOBALS['frameworkpath'] = '/phpOMS/';

View File

@ -142,7 +142,7 @@ trait ApiControllerCollectionTrait
$media->size = 11; $media->size = 11;
$media->extension = 'png'; $media->extension = 'png';
$media->name = 'Media for collection'; $media->name = 'Media for collection';
$id = MediaMapper::create($media); $id = MediaMapper::create()->execute($media);
self::assertGreaterThan(0, $media->getId()); self::assertGreaterThan(0, $media->getId());
self::assertEquals($id, $media->getId()); self::assertEquals($id, $media->getId());

View File

@ -231,7 +231,7 @@ trait ApiControllerMediaTrait
$request->setData('content', 'Test Content'); $request->setData('content', 'Test Content');
$this->module->apiMediaUpdate($request, $response); $this->module->apiMediaUpdate($request, $response);
$media = MediaMapper::get($id); $media = MediaMapper::get()->where('id', $id)->execute();
self::assertEquals('Test Changed', $media->name); self::assertEquals('Test Changed', $media->name);
self::assertEquals('Test Content', \file_get_contents(__DIR__ . '/../test/path/testFile1.txt')); self::assertEquals('Test Content', \file_get_contents(__DIR__ . '/../test/path/testFile1.txt'));

View File

@ -37,12 +37,12 @@ final class CollectionMapperTest extends \PHPUnit\Framework\TestCase
$media->setVirtualPath('/some/path'); $media->setVirtualPath('/some/path');
$media->size = 11; $media->size = 11;
$media->name = 'Collection'; $media->name = 'Collection';
$id = CollectionMapper::create($media); $id = CollectionMapper::create()->execute($media);
self::assertGreaterThan(0, $media->getId()); self::assertGreaterThan(0, $media->getId());
self::assertEquals($id, $media->getId()); self::assertEquals($id, $media->getId());
$mediaR = CollectionMapper::get($media->getId()); $mediaR = CollectionMapper::get()->where('id', $media->getId())->execute();
self::assertEquals($media->createdAt->format('Y-m-d'), $mediaR->createdAt->format('Y-m-d')); self::assertEquals($media->createdAt->format('Y-m-d'), $mediaR->createdAt->format('Y-m-d'));
self::assertEquals($media->createdBy->getId(), $mediaR->createdBy->getId()); self::assertEquals($media->createdBy->getId(), $mediaR->createdBy->getId());
self::assertEquals($media->description, $mediaR->description); self::assertEquals($media->description, $mediaR->description);
@ -53,7 +53,7 @@ final class CollectionMapperTest extends \PHPUnit\Framework\TestCase
self::assertEquals($media->extension, $mediaR->extension); self::assertEquals($media->extension, $mediaR->extension);
self::assertEquals($media->name, $mediaR->name); self::assertEquals($media->name, $mediaR->name);
self::assertGreaterThan(0, \count(CollectionMapper::getByVirtualPath('/some/path'))); self::assertGreaterThan(0, \count(CollectionMapper::getByVirtualPath('/some/path')->execute()));
self::assertGreaterThan(0, \count(CollectionMapper::getCollectionsByPath('/', true))); self::assertGreaterThan(0, \count(CollectionMapper::getCollectionsByPath('/', true)));
} }
} }

View File

@ -39,12 +39,12 @@ final class MediaMapperTest extends \PHPUnit\Framework\TestCase
$media->size = 11; $media->size = 11;
$media->extension = 'png'; $media->extension = 'png';
$media->name = 'Image'; $media->name = 'Image';
$id = MediaMapper::create($media); $id = MediaMapper::create()->execute($media);
self::assertGreaterThan(0, $media->getId()); self::assertGreaterThan(0, $media->getId());
self::assertEquals($id, $media->getId()); self::assertEquals($id, $media->getId());
$mediaR = MediaMapper::get($media->getId()); $mediaR = MediaMapper::get()->where('id', $media->getId())->execute();
self::assertEquals($media->createdAt->format('Y-m-d'), $mediaR->createdAt->format('Y-m-d')); self::assertEquals($media->createdAt->format('Y-m-d'), $mediaR->createdAt->format('Y-m-d'));
self::assertEquals($media->createdBy->getId(), $mediaR->createdBy->getId()); self::assertEquals($media->createdBy->getId(), $mediaR->createdBy->getId());
self::assertEquals($media->description, $mediaR->description); self::assertEquals($media->description, $mediaR->description);
@ -70,12 +70,12 @@ final class MediaMapperTest extends \PHPUnit\Framework\TestCase
$media->size = 11; $media->size = 11;
$media->extension = 'png'; $media->extension = 'png';
$media->name = 'Absolute path'; $media->name = 'Absolute path';
$id = MediaMapper::create($media); $id = MediaMapper::create()->execute($media);
self::assertGreaterThan(0, $media->getId()); self::assertGreaterThan(0, $media->getId());
self::assertEquals($id, $media->getId()); self::assertEquals($id, $media->getId());
$mediaR = MediaMapper::get($media->getId()); $mediaR = MediaMapper::get()->where('id', $media->getId())->execute();
self::assertEquals($media->createdAt->format('Y-m-d'), $mediaR->createdAt->format('Y-m-d')); self::assertEquals($media->createdAt->format('Y-m-d'), $mediaR->createdAt->format('Y-m-d'));
self::assertEquals($media->createdBy->getId(), $mediaR->createdBy->getId()); self::assertEquals($media->createdBy->getId(), $mediaR->createdBy->getId());
self::assertEquals($media->description, $mediaR->description); self::assertEquals($media->description, $mediaR->description);
@ -100,12 +100,12 @@ final class MediaMapperTest extends \PHPUnit\Framework\TestCase
$media->size = 11; $media->size = 11;
$media->extension = 'collection'; $media->extension = 'collection';
$media->name = 'Directory'; $media->name = 'Directory';
$id = MediaMapper::create($media); $id = MediaMapper::create()->execute($media);
self::assertGreaterThan(0, $media->getId()); self::assertGreaterThan(0, $media->getId());
self::assertEquals($id, $media->getId()); self::assertEquals($id, $media->getId());
$mediaR = MediaMapper::get($media->getId()); $mediaR = MediaMapper::get()->where('id', $media->getId())->execute();
self::assertEquals($media->createdAt->format('Y-m-d'), $mediaR->createdAt->format('Y-m-d')); self::assertEquals($media->createdAt->format('Y-m-d'), $mediaR->createdAt->format('Y-m-d'));
self::assertEquals($media->createdBy->getId(), $mediaR->createdBy->getId()); self::assertEquals($media->createdBy->getId(), $mediaR->createdBy->getId());
self::assertEquals($media->description, $mediaR->description); self::assertEquals($media->description, $mediaR->description);
@ -131,12 +131,12 @@ final class MediaMapperTest extends \PHPUnit\Framework\TestCase
$media->size = 11; $media->size = 11;
$media->extension = 'png'; $media->extension = 'png';
$media->name = 'With virtual path'; $media->name = 'With virtual path';
$id = MediaMapper::create($media); $id = MediaMapper::create()->execute($media);
self::assertGreaterThan(0, $media->getId()); self::assertGreaterThan(0, $media->getId());
self::assertEquals($id, $media->getId()); self::assertEquals($id, $media->getId());
$found = MediaMapper::getByVirtualPath($media->getVirtualPath()); $found = MediaMapper::getByVirtualPath($media->getVirtualPath())->execute();
$mediaR = \reset($found); $mediaR = \reset($found);
self::assertEquals($media->createdAt->format('Y-m-d'), $mediaR->createdAt->format('Y-m-d')); self::assertEquals($media->createdAt->format('Y-m-d'), $mediaR->createdAt->format('Y-m-d'));
self::assertEquals($media->createdBy->getId(), $mediaR->createdBy->getId()); self::assertEquals($media->createdBy->getId(), $mediaR->createdBy->getId());
@ -162,7 +162,7 @@ final class MediaMapperTest extends \PHPUnit\Framework\TestCase
$collection->setVirtualPath('/virtual/path'); $collection->setVirtualPath('/virtual/path');
$collection->size = 11; $collection->size = 11;
$collection->name = 'Collection'; $collection->name = 'Collection';
$idCollection = CollectionMapper::create($collection); $idCollection = CollectionMapper::create()->execute($collection);
self::assertGreaterThan(0, $collection->getId()); self::assertGreaterThan(0, $collection->getId());
self::assertEquals($idCollection, $collection->getId()); self::assertEquals($idCollection, $collection->getId());
@ -176,12 +176,12 @@ final class MediaMapperTest extends \PHPUnit\Framework\TestCase
$media->size = 11; $media->size = 11;
$media->extension = 'png'; $media->extension = 'png';
$media->name = 'Absolute path'; $media->name = 'Absolute path';
$idMedia = MediaMapper::create($media); $idMedia = MediaMapper::create()->execute($media);
self::assertGreaterThan(0, $media->getId()); self::assertGreaterThan(0, $media->getId());
self::assertEquals($idMedia, $media->getId()); self::assertEquals($idMedia, $media->getId());
$collectionR = MediaMapper::getParentCollection($media->getVirtualPath()); $collectionR = MediaMapper::getParentCollection($media->getVirtualPath())->execute();
self::assertEquals($idCollection, $collectionR->getId()); self::assertEquals($idCollection, $collectionR->getId());
self::assertEquals($collection->name, $collectionR->name); self::assertEquals($collection->name, $collectionR->name);
} }