mirror of
https://github.com/Karaka-Management/oms-Media.git
synced 2026-02-08 05:28:41 +00:00
new datamapper mostly implemented
This commit is contained in:
parent
f3d2f51d38
commit
df0105c0b2
|
|
@ -69,7 +69,7 @@ final class Installer extends InstallerAbstract
|
|||
// 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
|
||||
// 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) {
|
||||
$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
|
||||
$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->createdBy = new NullAccount((int) $data['user'] ?? 1);
|
||||
|
||||
CollectionMapper::create($collection);
|
||||
CollectionMapper::create()->execute($collection);
|
||||
|
||||
if ($data['create_directory'] && !\is_dir($dirPath)) {
|
||||
// @todo fix permission mode
|
||||
|
|
@ -201,13 +201,13 @@ final class Installer extends InstallerAbstract
|
|||
$type = new MediaType();
|
||||
$type->name = $data['name'] ?? '';
|
||||
|
||||
$id = MediaTypeMapper::create($type);
|
||||
$id = MediaTypeMapper::create()->execute($type);
|
||||
|
||||
foreach ($data['l11n'] as $l11n) {
|
||||
$l11n = new MediaTypeL11n($l11n['title'], $l11n['lang']);
|
||||
$l11n->type = $id;
|
||||
|
||||
MediaTypeL11nMapper::create($l11n);
|
||||
MediaTypeL11nMapper::create()->execute($l11n);
|
||||
}
|
||||
|
||||
return $type;
|
||||
|
|
@ -279,7 +279,7 @@ final class Installer extends InstallerAbstract
|
|||
$media->setVirtualPath((string) ($data['virtualPath'] ?? '/'));
|
||||
$media->type = $data['media_type'] ?? null; // = identifier for modules
|
||||
|
||||
MediaMapper::create($media);
|
||||
MediaMapper::create()->execute($media);
|
||||
|
||||
$mediaFiles[] = $media;
|
||||
}
|
||||
|
|
@ -293,7 +293,7 @@ final class Installer extends InstallerAbstract
|
|||
|
||||
$collection->setSources($mediaFiles);
|
||||
|
||||
CollectionMapper::create($collection);
|
||||
CollectionMapper::create()->execute($collection);
|
||||
return [$collection];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -296,7 +296,7 @@ final class ApiController extends Controller
|
|||
$media->setVirtualPath($virtualPath);
|
||||
$media->type = \is_int($type) ? new NullMediaType($type) : null;
|
||||
|
||||
MediaMapper::create($media);
|
||||
MediaMapper::create()->execute($media);
|
||||
|
||||
return $media;
|
||||
}
|
||||
|
|
@ -340,7 +340,7 @@ final class ApiController extends Controller
|
|||
public function apiMediaUpdate(RequestAbstract $request, ResponseAbstract $response, $data = null) : void
|
||||
{
|
||||
/** @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 */
|
||||
$new = $this->updateMediaFromRequest($request);
|
||||
|
|
@ -363,7 +363,7 @@ final class ApiController extends Controller
|
|||
$id = (int) $request->getData('id');
|
||||
|
||||
/** @var Media $media */
|
||||
$media = MediaMapper::get($id);
|
||||
$media = MediaMapper::get()->where('id', $id)->execute();
|
||||
$media->name = (string) ($request->getData('name') ?? $media->name);
|
||||
$media->description = (string) ($request->getData('description') ?? $media->description);
|
||||
$media->setPath((string) ($request->getData('path') ?? $media->getPath()));
|
||||
|
|
@ -479,7 +479,7 @@ final class ApiController extends Controller
|
|||
$mediaCollection->setVirtualPath($virtualPath);
|
||||
$mediaCollection->setPath($outputDir);
|
||||
|
||||
CollectionMapper::create($mediaCollection);
|
||||
CollectionMapper::create()->execute($mediaCollection);
|
||||
|
||||
return $mediaCollection;
|
||||
}
|
||||
|
|
@ -604,7 +604,7 @@ final class ApiController extends Controller
|
|||
{
|
||||
if (((int) $request->getData('id')) !== 0) {
|
||||
/** @var Media $media */
|
||||
$media = MediaMapper::get((int) $request->getData('id'));
|
||||
$media = MediaMapper::get()->where('id', (int) $request->getData('id'))->execute();
|
||||
} else {
|
||||
$path = \urldecode($request->getData('path'));
|
||||
$media = new NullMedia();
|
||||
|
|
|
|||
|
|
@ -73,8 +73,8 @@ final class BackendController extends Controller
|
|||
$path = \str_replace('+', ' ', (string) ($request->getData('path') ?? '/'));
|
||||
|
||||
/** @var Media[] $media */
|
||||
$media = MediaMapper::getByVirtualPath($path);
|
||||
$collection = CollectionMapper::getParentCollection($path);
|
||||
$media = MediaMapper::getByVirtualPath($path)->where('tags/title/language', $request->getLanguage())->execute();
|
||||
$collection = CollectionMapper::getParentCollection($path)->where('tags/title/language', $request->getLanguage())->execute();
|
||||
|
||||
if (\is_array($collection) && \is_dir(__DIR__ . '/../Files' . $path)) {
|
||||
$collection = new Collection();
|
||||
|
|
@ -160,13 +160,20 @@ final class BackendController extends Controller
|
|||
$view->addData('view', $this->createMediaView($media, $request, $response));
|
||||
}
|
||||
} 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') {
|
||||
$media = MediaMapper::getByVirtualPath(
|
||||
$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());
|
||||
|
||||
$view->addData('path', $collection->getVirtualPath() . '/' . $collection->name);
|
||||
|
|
@ -285,12 +292,12 @@ final class BackendController extends Controller
|
|||
|
||||
$id = $request->getData('id') ?? '';
|
||||
|
||||
$settings = SettingMapper::getFor($id, 'module');
|
||||
$settings = SettingMapper::getAll()->where('module', $id)->execute();
|
||||
if (!($settings instanceof NullSetting)) {
|
||||
$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);
|
||||
|
||||
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->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('type', $type);
|
||||
|
||||
$l11n = MediaTypeL11nMapper::with('tag', $type->getId())::getAll();
|
||||
$l11n = MediaTypeL11nMapper::getAll()->where('type', $type->getId())->execute();
|
||||
$view->addData('l11n', $l11n);
|
||||
|
||||
return $view;
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ declare(strict_types=1);
|
|||
namespace Modules\Media\Models;
|
||||
|
||||
use Modules\Admin\Models\Account;
|
||||
use phpOMS\DataStorage\Database\RelationType;
|
||||
use phpOMS\DataStorage\Database\Mapper\ReadMapper;
|
||||
|
||||
/**
|
||||
* 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}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static array $hasMany = [
|
||||
public const HAS_MANY = [
|
||||
'sources' => [
|
||||
'mapper' => MediaMapper::class,
|
||||
'table' => 'media_relation',
|
||||
|
|
@ -48,7 +48,7 @@ final class CollectionMapper extends MediaMapper
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $model = Collection::class;
|
||||
public const MODEL = Collection::class;
|
||||
|
||||
/**
|
||||
* Primary table.
|
||||
|
|
@ -56,7 +56,7 @@ final class CollectionMapper extends MediaMapper
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $table = 'media';
|
||||
public const TABLE = 'media';
|
||||
|
||||
/**
|
||||
* Created at.
|
||||
|
|
@ -64,7 +64,7 @@ final class CollectionMapper extends MediaMapper
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $createdAt = 'media_created_at';
|
||||
public const CREATED_AT = 'media_created_at';
|
||||
|
||||
/**
|
||||
* Primary field name.
|
||||
|
|
@ -72,7 +72,7 @@ final class CollectionMapper extends MediaMapper
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $primaryField = 'media_id';
|
||||
public const PRIMARYFIELD ='media_id';
|
||||
|
||||
/**
|
||||
* Get media based on virtual path.
|
||||
|
|
@ -92,22 +92,17 @@ final class CollectionMapper extends MediaMapper
|
|||
* @param string $virtualPath Virtual path
|
||||
* @param bool $hidden Get hidden files
|
||||
*
|
||||
* @return array
|
||||
* @return ReadMapper
|
||||
*
|
||||
* @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;
|
||||
$query = self::getQuery(depth: $depth);
|
||||
$query->where(self::$table . '_d' . $depth . '.media_virtual', '=', $virtualPath);
|
||||
$query->where(self::$table . '_d' . $depth . '.media_collection', '=', 1);
|
||||
|
||||
if ($hidden === false) {
|
||||
$query->andWhere(self::$table . '_d' . $depth . '.media_hidden', '=', (int) $hidden);
|
||||
}
|
||||
|
||||
return self::getAllByQuery($query, RelationType::ALL, $depth);
|
||||
return self::getAll()->where('virtualPath', $virtualPath)
|
||||
->with('createdBy')
|
||||
->with('tags')
|
||||
->where('isHidden', $hidden)
|
||||
->where('collection', true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -123,11 +118,11 @@ final class CollectionMapper extends MediaMapper
|
|||
public static function getCollectionsByPath(string $virtualPath, bool $showDirectories = false) : array
|
||||
{
|
||||
/** @var Media[] $collection */
|
||||
$collection = self::getByVirtualPath($virtualPath);
|
||||
$collection = self::getByVirtualPath($virtualPath)->with('sources')->execute();
|
||||
$parent = [];
|
||||
|
||||
if ($showDirectories) {
|
||||
$parent = self::getParentCollection($virtualPath);
|
||||
$parent = self::getParentCollection($virtualPath)->execute();
|
||||
if (\is_array($parent) && \is_dir(__DIR__ . '/../../Media/Files' . $virtualPath)) {
|
||||
$parent = new Collection();
|
||||
$parent->name = \basename($virtualPath);
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@ namespace Modules\Media\Models;
|
|||
|
||||
use Modules\Admin\Models\AccountMapper;
|
||||
use Modules\Tag\Models\TagMapper;
|
||||
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
||||
use phpOMS\DataStorage\Database\RelationType;
|
||||
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||
use phpOMS\DataStorage\Database\Mapper\ReadMapper;
|
||||
|
||||
/**
|
||||
* Media mapper class.
|
||||
|
|
@ -27,7 +27,7 @@ use phpOMS\DataStorage\Database\RelationType;
|
|||
* @link https://orange-management.org
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class MediaMapper extends DataMapperAbstract
|
||||
class MediaMapper extends DataMapperFactory
|
||||
{
|
||||
/**
|
||||
* 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}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static array $columns = [
|
||||
public const COLUMNS = [
|
||||
'media_id' => ['name' => 'media_id', 'type' => 'int', 'internal' => 'id'],
|
||||
'media_name' => ['name' => 'media_name', 'type' => 'string', 'internal' => 'name', 'autocomplete' => true],
|
||||
'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}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static array $belongsTo = [
|
||||
public const BELONGS_TO = [
|
||||
'createdBy' => [
|
||||
'mapper' => AccountMapper::class,
|
||||
'external' => 'media_created_by',
|
||||
|
|
@ -74,7 +74,7 @@ class MediaMapper extends DataMapperAbstract
|
|||
* @var array<string, array{mapper:string, external:string}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static array $ownsOne = [
|
||||
public const OWNS_ONE = [
|
||||
'type' => [
|
||||
'mapper' => MediaTypeMapper::class,
|
||||
'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}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static array $hasMany = [
|
||||
public const HAS_MANY = [
|
||||
'tags' => [
|
||||
'mapper' => TagMapper::class,
|
||||
'table' => 'media_tag',
|
||||
|
|
@ -102,7 +102,7 @@ class MediaMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $model = Media::class;
|
||||
public const MODEL = Media::class;
|
||||
|
||||
/**
|
||||
* Primary table.
|
||||
|
|
@ -110,7 +110,7 @@ class MediaMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $table = 'media';
|
||||
public const TABLE = 'media';
|
||||
|
||||
/**
|
||||
* Created at.
|
||||
|
|
@ -118,7 +118,7 @@ class MediaMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $createdAt = 'media_created_at';
|
||||
public const CREATED_AT = 'media_created_at';
|
||||
|
||||
/**
|
||||
* Primary field name.
|
||||
|
|
@ -126,7 +126,7 @@ class MediaMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $primaryField = 'media_id';
|
||||
public const PRIMARYFIELD ='media_id';
|
||||
|
||||
/**
|
||||
* Get media based on virtual path.
|
||||
|
|
@ -146,21 +146,18 @@ class MediaMapper extends DataMapperAbstract
|
|||
* @param string $virtualPath Virtual path
|
||||
* @param bool $hidden Get hidden files
|
||||
*
|
||||
* @return array
|
||||
* @return ReadMapper
|
||||
*
|
||||
* @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;
|
||||
$query = self::getQuery(depth: $depth);
|
||||
$query->where(self::$table . '_d' . $depth . '.media_virtual', '=', $virtualPath);
|
||||
|
||||
if ($hidden === false) {
|
||||
$query->andWhere(self::$table . '_d' . $depth . '.media_hidden', '=', (int) $hidden);
|
||||
}
|
||||
|
||||
return self::getAllByQuery($query, RelationType::ALL, $depth);
|
||||
return self::getAll()
|
||||
->with('createdBy')
|
||||
->with('tags')
|
||||
->with('tags/title')
|
||||
->where('virtualPath', $virtualPath)
|
||||
->where('isHidden', $hidden);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -168,22 +165,18 @@ class MediaMapper extends DataMapperAbstract
|
|||
*
|
||||
* @param string $path Virtual path
|
||||
*
|
||||
* @return mixed
|
||||
* @return ReadMapper
|
||||
*
|
||||
* @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), '/');
|
||||
$name = \substr($path, \strripos($path, '/') + 1);
|
||||
|
||||
$depth = 3;
|
||||
$query = self::getQuery();
|
||||
$query->where(self::$table. '_d' . $depth . '.media_virtual', '=', $virtualPath)
|
||||
->andWhere(self::$table. '_d' . $depth . '.media_name', '=', $name);
|
||||
|
||||
$objs = self::getAllByQuery($query, RelationType::ALL, $depth);
|
||||
|
||||
return \count($objs) === 1 ? \reset($objs) : $objs;
|
||||
return self::get()
|
||||
->with('sources')
|
||||
->where('virtualPath', $virtualPath)
|
||||
->where('name', $name);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Modules\Media\Models;
|
||||
|
||||
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
||||
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||
|
||||
/**
|
||||
* Media type l11n mapper class.
|
||||
|
|
@ -24,7 +24,7 @@ use phpOMS\DataStorage\Database\DataMapperAbstract;
|
|||
* @link https://orange-management.org
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class MediaTypeL11nMapper extends DataMapperAbstract
|
||||
final class MediaTypeL11nMapper extends DataMapperFactory
|
||||
{
|
||||
/**
|
||||
* 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}>
|
||||
* @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_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'],
|
||||
|
|
@ -45,7 +45,7 @@ final class MediaTypeL11nMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $table = 'media_type_l11n';
|
||||
public const TABLE = 'media_type_l11n';
|
||||
|
||||
/**
|
||||
* Primary field name.
|
||||
|
|
@ -53,5 +53,5 @@ final class MediaTypeL11nMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $primaryField = 'media_type_l11n_id';
|
||||
public const PRIMARYFIELD ='media_type_l11n_id';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Modules\Media\Models;
|
||||
|
||||
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
||||
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||
|
||||
/**
|
||||
* Media type mapper class.
|
||||
|
|
@ -24,7 +24,7 @@ use phpOMS\DataStorage\Database\DataMapperAbstract;
|
|||
* @link https://orange-management.org
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class MediaTypeMapper extends DataMapperAbstract
|
||||
final class MediaTypeMapper extends DataMapperFactory
|
||||
{
|
||||
/**
|
||||
* 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}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static array $columns = [
|
||||
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'],
|
||||
|
|
@ -44,13 +44,12 @@ final class MediaTypeMapper extends DataMapperAbstract
|
|||
* @var array<string, array{mapper:string, table:string, self?:?string, external?:?string, column?:string}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static array $hasMany = [
|
||||
public const HAS_MANY = [
|
||||
'title' => [
|
||||
'mapper' => MediaTypeL11nMapper::class,
|
||||
'table' => 'media_type_l11n',
|
||||
'self' => 'media_type_l11n_type',
|
||||
'column' => 'title',
|
||||
'conditional' => true,
|
||||
'external' => null,
|
||||
],
|
||||
];
|
||||
|
|
@ -61,7 +60,7 @@ final class MediaTypeMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $model = MediaType::class;
|
||||
public const MODEL = MediaType::class;
|
||||
|
||||
/**
|
||||
* Primary table.
|
||||
|
|
@ -69,7 +68,7 @@ final class MediaTypeMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $table = 'media_type';
|
||||
public const TABLE = 'media_type';
|
||||
|
||||
/**
|
||||
* Primary field name.
|
||||
|
|
@ -77,5 +76,5 @@ final class MediaTypeMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $primaryField = 'media_type_id';
|
||||
public const PRIMARYFIELD ='media_type_id';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ require_once __DIR__ . '/../vendor/autoload.php';
|
|||
require_once __DIR__ . '/Autoloader.php';
|
||||
|
||||
use phpOMS\DataStorage\Database\DatabasePool;
|
||||
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
||||
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||
use phpOMS\DataStorage\Session\HttpSession;
|
||||
|
||||
$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('schema', $CONFIG['db']['core']['masters']['schema']);
|
||||
|
||||
DataMapperAbstract::setConnection($GLOBALS['dbpool']->get());
|
||||
DataMapperFactory::db($GLOBALS['dbpool']->get());
|
||||
|
||||
$GLOBALS['frameworkpath'] = '/phpOMS/';
|
||||
|
||||
|
|
|
|||
|
|
@ -142,7 +142,7 @@ trait ApiControllerCollectionTrait
|
|||
$media->size = 11;
|
||||
$media->extension = 'png';
|
||||
$media->name = 'Media for collection';
|
||||
$id = MediaMapper::create($media);
|
||||
$id = MediaMapper::create()->execute($media);
|
||||
|
||||
self::assertGreaterThan(0, $media->getId());
|
||||
self::assertEquals($id, $media->getId());
|
||||
|
|
|
|||
|
|
@ -231,7 +231,7 @@ trait ApiControllerMediaTrait
|
|||
$request->setData('content', 'Test Content');
|
||||
$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 Content', \file_get_contents(__DIR__ . '/../test/path/testFile1.txt'));
|
||||
|
||||
|
|
|
|||
|
|
@ -37,12 +37,12 @@ final class CollectionMapperTest extends \PHPUnit\Framework\TestCase
|
|||
$media->setVirtualPath('/some/path');
|
||||
$media->size = 11;
|
||||
$media->name = 'Collection';
|
||||
$id = CollectionMapper::create($media);
|
||||
$id = CollectionMapper::create()->execute($media);
|
||||
|
||||
self::assertGreaterThan(0, $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->createdBy->getId(), $mediaR->createdBy->getId());
|
||||
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->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)));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,12 +39,12 @@ final class MediaMapperTest extends \PHPUnit\Framework\TestCase
|
|||
$media->size = 11;
|
||||
$media->extension = 'png';
|
||||
$media->name = 'Image';
|
||||
$id = MediaMapper::create($media);
|
||||
$id = MediaMapper::create()->execute($media);
|
||||
|
||||
self::assertGreaterThan(0, $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->createdBy->getId(), $mediaR->createdBy->getId());
|
||||
self::assertEquals($media->description, $mediaR->description);
|
||||
|
|
@ -70,12 +70,12 @@ final class MediaMapperTest extends \PHPUnit\Framework\TestCase
|
|||
$media->size = 11;
|
||||
$media->extension = 'png';
|
||||
$media->name = 'Absolute path';
|
||||
$id = MediaMapper::create($media);
|
||||
$id = MediaMapper::create()->execute($media);
|
||||
|
||||
self::assertGreaterThan(0, $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->createdBy->getId(), $mediaR->createdBy->getId());
|
||||
self::assertEquals($media->description, $mediaR->description);
|
||||
|
|
@ -100,12 +100,12 @@ final class MediaMapperTest extends \PHPUnit\Framework\TestCase
|
|||
$media->size = 11;
|
||||
$media->extension = 'collection';
|
||||
$media->name = 'Directory';
|
||||
$id = MediaMapper::create($media);
|
||||
$id = MediaMapper::create()->execute($media);
|
||||
|
||||
self::assertGreaterThan(0, $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->createdBy->getId(), $mediaR->createdBy->getId());
|
||||
self::assertEquals($media->description, $mediaR->description);
|
||||
|
|
@ -131,12 +131,12 @@ final class MediaMapperTest extends \PHPUnit\Framework\TestCase
|
|||
$media->size = 11;
|
||||
$media->extension = 'png';
|
||||
$media->name = 'With virtual path';
|
||||
$id = MediaMapper::create($media);
|
||||
$id = MediaMapper::create()->execute($media);
|
||||
|
||||
self::assertGreaterThan(0, $media->getId());
|
||||
self::assertEquals($id, $media->getId());
|
||||
|
||||
$found = MediaMapper::getByVirtualPath($media->getVirtualPath());
|
||||
$found = MediaMapper::getByVirtualPath($media->getVirtualPath())->execute();
|
||||
$mediaR = \reset($found);
|
||||
self::assertEquals($media->createdAt->format('Y-m-d'), $mediaR->createdAt->format('Y-m-d'));
|
||||
self::assertEquals($media->createdBy->getId(), $mediaR->createdBy->getId());
|
||||
|
|
@ -162,7 +162,7 @@ final class MediaMapperTest extends \PHPUnit\Framework\TestCase
|
|||
$collection->setVirtualPath('/virtual/path');
|
||||
$collection->size = 11;
|
||||
$collection->name = 'Collection';
|
||||
$idCollection = CollectionMapper::create($collection);
|
||||
$idCollection = CollectionMapper::create()->execute($collection);
|
||||
|
||||
self::assertGreaterThan(0, $collection->getId());
|
||||
self::assertEquals($idCollection, $collection->getId());
|
||||
|
|
@ -176,12 +176,12 @@ final class MediaMapperTest extends \PHPUnit\Framework\TestCase
|
|||
$media->size = 11;
|
||||
$media->extension = 'png';
|
||||
$media->name = 'Absolute path';
|
||||
$idMedia = MediaMapper::create($media);
|
||||
$idMedia = MediaMapper::create()->execute($media);
|
||||
|
||||
self::assertGreaterThan(0, $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($collection->name, $collectionR->name);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user