mirror of
https://github.com/Karaka-Management/oms-Marketing.git
synced 2026-02-08 14:38:40 +00:00
new datamapper mostly implemented
This commit is contained in:
parent
5353859c8b
commit
ef303e2eda
|
|
@ -55,7 +55,7 @@ final class BackendController extends Controller
|
|||
$view->setTemplate('/Modules/Marketing/Theme/Backend/promotion-list');
|
||||
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1001902001, $request, $response));
|
||||
|
||||
$promotions = PromotionMapper::getNewest(25);
|
||||
$promotions = PromotionMapper::getAll()->limit(25)->execute();
|
||||
$view->addData('promotions', $promotions);
|
||||
|
||||
return $view;
|
||||
|
|
@ -95,7 +95,7 @@ final class BackendController extends Controller
|
|||
$mediaListView->setTemplate('/Modules/Media/Theme/Backend/Components/Media/list');
|
||||
$view->addData('medialist', $mediaListView);
|
||||
|
||||
$promotion = PromotionMapper::get((int) $request->getData('id'));
|
||||
$promotion = PromotionMapper::get()->where('id', (int) $request->getData('id'))->execute();
|
||||
$view->addData('promotion', $promotion);
|
||||
|
||||
return $view;
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ declare(strict_types=1);
|
|||
namespace Modules\Marketing\Models;
|
||||
|
||||
use Modules\Admin\Models\AccountMapper;
|
||||
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
||||
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||
|
||||
/**
|
||||
* Mapper class.
|
||||
|
|
@ -25,7 +25,7 @@ use phpOMS\DataStorage\Database\DataMapperAbstract;
|
|||
* @link https://orange-management.org
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class AccountRelationMapper extends DataMapperAbstract
|
||||
final class AccountRelationMapper extends DataMapperFactory
|
||||
{
|
||||
/**
|
||||
* Columns.
|
||||
|
|
@ -33,7 +33,7 @@ final class AccountRelationMapper 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 = [
|
||||
'marketing_promotion_accountrel_id' => ['name' => 'marketing_promotion_accountrel_id', 'type' => 'int', 'internal' => 'id'],
|
||||
'marketing_promotion_accountrel_promotion' => ['name' => 'marketing_promotion_accountrel_promotion', 'type' => 'int', 'internal' => 'promotion'],
|
||||
'marketing_promotion_accountrel_type' => ['name' => 'marketing_promotion_accountrel_type', 'type' => 'int', 'internal' => 'type'],
|
||||
|
|
@ -45,7 +45,7 @@ final class AccountRelationMapper extends DataMapperAbstract
|
|||
* @var array<string, array{mapper:string, external:string, by?:string, column?:string, conditional?:bool}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static array $ownsOne = [
|
||||
public const OWNS_ONE = [
|
||||
'account' => [
|
||||
'mapper' => AccountMapper::class,
|
||||
'external' => 'marketing_promotion_accountrel_account',
|
||||
|
|
@ -58,7 +58,7 @@ final class AccountRelationMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $table = 'marketing_promotion_accountrel';
|
||||
public const TABLE = 'marketing_promotion_accountrel';
|
||||
|
||||
/**
|
||||
* Primary field name.
|
||||
|
|
@ -66,5 +66,5 @@ final class AccountRelationMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $primaryField = 'marketing_promotion_accountrel_id';
|
||||
public const PRIMARYFIELD ='marketing_promotion_accountrel_id';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Modules\Marketing\Models;
|
||||
|
||||
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
||||
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||
|
||||
/**
|
||||
* Promotion mapper class.
|
||||
|
|
@ -24,7 +24,7 @@ use phpOMS\DataStorage\Database\DataMapperAbstract;
|
|||
* @link https://orange-management.org
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class PromotionAttributeMapper extends DataMapperAbstract
|
||||
final class PromotionAttributeMapper extends DataMapperFactory
|
||||
{
|
||||
/**
|
||||
* Columns.
|
||||
|
|
@ -32,7 +32,7 @@ final class PromotionAttributeMapper 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 = [
|
||||
'marketing_promotion_attr_id' => ['name' => 'marketing_promotion_attr_id', 'type' => 'int', 'internal' => 'id'],
|
||||
'marketing_promotion_attr_promotion' => ['name' => 'marketing_promotion_attr_promotion', 'type' => 'int', 'internal' => 'promotion'],
|
||||
'marketing_promotion_attr_type' => ['name' => 'marketing_promotion_attr_type', 'type' => 'int', 'internal' => 'type'],
|
||||
|
|
@ -45,7 +45,7 @@ final class PromotionAttributeMapper extends DataMapperAbstract
|
|||
* @var array<string, array{mapper:string, external:string, by?:string, column?:string, conditional?:bool}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static array $ownsOne = [
|
||||
public const OWNS_ONE = [
|
||||
'type' => [
|
||||
'mapper' => PromotionAttributeTypeMapper::class,
|
||||
'external' => 'marketing_promotion_attr_type',
|
||||
|
|
@ -62,7 +62,7 @@ final class PromotionAttributeMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $table = 'marketing_promotion_attr';
|
||||
public const TABLE = 'marketing_promotion_attr';
|
||||
|
||||
/**
|
||||
* Primary field name.
|
||||
|
|
@ -70,5 +70,5 @@ final class PromotionAttributeMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $primaryField = 'marketing_promotion_attr_id';
|
||||
public const PRIMARYFIELD ='marketing_promotion_attr_id';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Modules\Marketing\Models;
|
||||
|
||||
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
||||
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||
|
||||
/**
|
||||
* Promotion mapper class.
|
||||
|
|
@ -24,7 +24,7 @@ use phpOMS\DataStorage\Database\DataMapperAbstract;
|
|||
* @link https://orange-management.org
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class PromotionAttributeTypeL11nMapper extends DataMapperAbstract
|
||||
final class PromotionAttributeTypeL11nMapper extends DataMapperFactory
|
||||
{
|
||||
/**
|
||||
* Columns.
|
||||
|
|
@ -32,7 +32,7 @@ final class PromotionAttributeTypeL11nMapper 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 = [
|
||||
'marketing_promotion_attr_type_l11n_id' => ['name' => 'marketing_promotion_attr_type_l11n_id', 'type' => 'int', 'internal' => 'id'],
|
||||
'marketing_promotion_attr_type_l11n_title' => ['name' => 'marketing_promotion_attr_type_l11n_title', 'type' => 'string', 'internal' => 'title', 'autocomplete' => true],
|
||||
'marketing_promotion_attr_type_l11n_type' => ['name' => 'marketing_promotion_attr_type_l11n_type', 'type' => 'int', 'internal' => 'type'],
|
||||
|
|
@ -45,7 +45,7 @@ final class PromotionAttributeTypeL11nMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $table = 'marketing_promotion_attr_type_l11n';
|
||||
public const TABLE = 'marketing_promotion_attr_type_l11n';
|
||||
|
||||
/**
|
||||
* Primary field name.
|
||||
|
|
@ -53,5 +53,5 @@ final class PromotionAttributeTypeL11nMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $primaryField = 'marketing_promotion_attr_type_l11n_id';
|
||||
public const PRIMARYFIELD ='marketing_promotion_attr_type_l11n_id';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Modules\Marketing\Models;
|
||||
|
||||
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
||||
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||
|
||||
/**
|
||||
* Promotion mapper class.
|
||||
|
|
@ -24,7 +24,7 @@ use phpOMS\DataStorage\Database\DataMapperAbstract;
|
|||
* @link https://orange-management.org
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class PromotionAttributeTypeMapper extends DataMapperAbstract
|
||||
final class PromotionAttributeTypeMapper extends DataMapperFactory
|
||||
{
|
||||
/**
|
||||
* Columns.
|
||||
|
|
@ -32,7 +32,7 @@ final class PromotionAttributeTypeMapper 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 = [
|
||||
'marketing_promotion_attr_type_id' => ['name' => 'marketing_promotion_attr_type_id', 'type' => 'int', 'internal' => 'id'],
|
||||
'marketing_promotion_attr_type_name' => ['name' => 'marketing_promotion_attr_type_name', 'type' => 'string', 'internal' => 'name', 'autocomplete' => true],
|
||||
'marketing_promotion_attr_type_fields' => ['name' => 'marketing_promotion_attr_type_fields', 'type' => 'int', 'internal' => 'fields'],
|
||||
|
|
@ -47,21 +47,19 @@ final class PromotionAttributeTypeMapper 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 = [
|
||||
'l11n' => [
|
||||
'mapper' => PromotionAttributeTypeL11nMapper::class,
|
||||
'table' => 'marketing_promotion_attr_type_l11n',
|
||||
'self' => 'marketing_promotion_attr_type_l11n_type',
|
||||
'column' => 'title',
|
||||
'conditional' => true,
|
||||
'external' => null,
|
||||
],
|
||||
'defaults' => [
|
||||
'mapper' => PromotionAttributeValueMapper::class,
|
||||
'table' => 'marketing_promotion_attr_default',
|
||||
'self' => 'marketing_promotion_attr_default_type',
|
||||
'external' => 'marketing_promotion_attr_default_value',
|
||||
'conditional' => false,
|
||||
'external' => 'marketing_promotion_attr_default_value'
|
||||
],
|
||||
];
|
||||
|
||||
|
|
@ -71,7 +69,7 @@ final class PromotionAttributeTypeMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $table = 'marketing_promotion_attr_type';
|
||||
public const TABLE = 'marketing_promotion_attr_type';
|
||||
|
||||
/**
|
||||
* Primary field name.
|
||||
|
|
@ -79,5 +77,5 @@ final class PromotionAttributeTypeMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $primaryField = 'marketing_promotion_attr_type_id';
|
||||
public const PRIMARYFIELD ='marketing_promotion_attr_type_id';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Modules\Marketing\Models;
|
||||
|
||||
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
||||
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||
|
||||
/**
|
||||
* Promotion mapper class.
|
||||
|
|
@ -24,7 +24,7 @@ use phpOMS\DataStorage\Database\DataMapperAbstract;
|
|||
* @link https: //orange-management.org
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class PromotionAttributeValueMapper extends DataMapperAbstract
|
||||
final class PromotionAttributeValueMapper extends DataMapperFactory
|
||||
{
|
||||
/**
|
||||
* Columns.
|
||||
|
|
@ -32,7 +32,7 @@ final class PromotionAttributeValueMapper 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 = [
|
||||
'marketing_promotion_attr_value_id' => ['name' => 'marketing_promotion_attr_value_id', 'type' => 'int', 'internal' => 'id'],
|
||||
'marketing_promotion_attr_value_default' => ['name' => 'marketing_promotion_attr_value_default', 'type' => 'bool', 'internal' => 'isDefault'],
|
||||
'marketing_promotion_attr_value_type' => ['name' => 'marketing_promotion_attr_value_type', 'type' => 'int', 'internal' => 'type'],
|
||||
|
|
@ -50,7 +50,7 @@ final class PromotionAttributeValueMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $table = 'marketing_promotion_attr_value';
|
||||
public const TABLE = 'marketing_promotion_attr_value';
|
||||
|
||||
/**
|
||||
* Primary field name.
|
||||
|
|
@ -58,5 +58,5 @@ final class PromotionAttributeValueMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $primaryField = 'marketing_promotion_attr_value_id';
|
||||
public const PRIMARYFIELD ='marketing_promotion_attr_value_id';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ use Modules\Admin\Models\AccountMapper;
|
|||
use Modules\Calendar\Models\CalendarMapper;
|
||||
use Modules\Media\Models\MediaMapper;
|
||||
use Modules\Tasks\Models\TaskMapper;
|
||||
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
||||
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||
|
||||
/**
|
||||
* Mapper class.
|
||||
|
|
@ -28,7 +28,7 @@ use phpOMS\DataStorage\Database\DataMapperAbstract;
|
|||
* @link https://orange-management.org
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class PromotionMapper extends DataMapperAbstract
|
||||
final class PromotionMapper extends DataMapperFactory
|
||||
{
|
||||
/**
|
||||
* Columns.
|
||||
|
|
@ -36,7 +36,7 @@ final class PromotionMapper 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 = [
|
||||
'marketing_promotion_id' => ['name' => 'marketing_promotion_id', 'type' => 'int', 'internal' => 'id'],
|
||||
'marketing_promotion_name' => ['name' => 'marketing_promotion_name', 'type' => 'string', 'internal' => 'name'],
|
||||
'marketing_promotion_description' => ['name' => 'marketing_promotion_description', 'type' => 'string', 'internal' => 'description'],
|
||||
|
|
@ -59,7 +59,7 @@ final class PromotionMapper 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 = [
|
||||
'tasks' => [
|
||||
'mapper' => TaskMapper::class,
|
||||
'table' => 'marketing_promotion_task_relation',
|
||||
|
|
@ -93,7 +93,7 @@ final class PromotionMapper extends DataMapperAbstract
|
|||
* @var array<string, array{mapper:string, external:string, by?:string, column?:string, conditional?:bool}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static array $ownsOne = [
|
||||
public const OWNS_ONE = [
|
||||
'calendar' => [
|
||||
'mapper' => CalendarMapper::class,
|
||||
'external' => 'marketing_promotion_calendar',
|
||||
|
|
@ -106,7 +106,7 @@ final class PromotionMapper 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' => 'marketing_promotion_created_by',
|
||||
|
|
@ -119,7 +119,7 @@ final class PromotionMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $table = 'marketing_promotion';
|
||||
public const TABLE = 'marketing_promotion';
|
||||
|
||||
/**
|
||||
* Created at.
|
||||
|
|
@ -127,7 +127,7 @@ final class PromotionMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $createdAt = 'marketing_promotion_created_at';
|
||||
public const CREATED_AT = 'marketing_promotion_created_at';
|
||||
|
||||
/**
|
||||
* Primary field name.
|
||||
|
|
@ -135,5 +135,5 @@ final class PromotionMapper extends DataMapperAbstract
|
|||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $primaryField = 'marketing_promotion_id';
|
||||
public const PRIMARYFIELD ='marketing_promotion_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/';
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ use Modules\Marketing\Models\Promotion;
|
|||
use Modules\Marketing\Models\PromotionMapper;
|
||||
use Modules\Media\Models\Media;
|
||||
use Modules\Tasks\Models\Task;
|
||||
use phpOMS\DataStorage\Database\Query\OrderType;
|
||||
use phpOMS\Localization\Money;
|
||||
|
||||
/**
|
||||
|
|
@ -72,11 +73,14 @@ final class PromotionMapperTest extends \PHPUnit\Framework\TestCase
|
|||
$media->name = 'Event Media';
|
||||
$promotion->addMedia($media);
|
||||
|
||||
$id = PromotionMapper::create($promotion);
|
||||
$id = PromotionMapper::create()->execute($promotion);
|
||||
self::assertGreaterThan(0, $promotion->getId());
|
||||
self::assertEquals($id, $promotion->getId());
|
||||
|
||||
$promotionR = PromotionMapper::get($promotion->getId());
|
||||
$promotionR = PromotionMapper::get()
|
||||
->with('tasks')
|
||||
->with('media')
|
||||
->where('id', $promotion->getId())->execute();
|
||||
|
||||
self::assertEquals($promotion->name, $promotionR->name);
|
||||
self::assertEquals($promotion->description, $promotionR->description);
|
||||
|
|
@ -102,7 +106,7 @@ final class PromotionMapperTest extends \PHPUnit\Framework\TestCase
|
|||
*/
|
||||
public function testNewest() : void
|
||||
{
|
||||
$newest = PromotionMapper::getNewest(1);
|
||||
$newest = PromotionMapper::getAll()->sort('id', OrderType::DESC)->limit(1)->execute();
|
||||
|
||||
self::assertCount(1, $newest);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user