new datamapper mostly implemented

This commit is contained in:
Dennis Eichhorn 2021-12-11 11:54:16 +01:00
parent ef32ccb6d7
commit ea2b0af46a
5 changed files with 24 additions and 28 deletions

View File

@ -93,7 +93,7 @@
},
"contractmgmt_contract_autorenewal": {
"name": "contractmgmt_contract_autorenewal",
"type": "INT",
"type": "TINYINT",
"null": false
},
"contractmgmt_contract_duration": {

View File

@ -55,18 +55,15 @@ final class BackendController extends Controller
if ($request->getData('ptype') === 'p') {
$view->setData('contracts',
ContractMapper::with('language', $response->getLanguage(), [ContractTypeL11n::class])
::getBeforePivot((int) ($request->getData('id') ?? 0), null, 25)
ContractMapper::getAll()->where('id', (int) ($request->getData('id') ?? 0), '<')->limit(25)->execute()
);
} elseif ($request->getData('ptype') === 'n') {
$view->setData('contracts',
ContractMapper::with('language', $response->getLanguage(), [ContractTypeL11n::class])
::getAfterPivot((int) ($request->getData('id') ?? 0), null, 25)
ContractMapper::getAll()->where('id', (int) ($request->getData('id') ?? 0), '>')->limit(25)->execute()
);
} else {
$view->setData('contracts',
ContractMapper::with('language', $response->getLanguage(), [ContractTypeL11n::class])
::getAfterPivot(0, null, 25)
ContractMapper::getAll()->where('id', 0, '>')->limit(25)->execute()
);
}
@ -92,7 +89,7 @@ final class BackendController extends Controller
$view->setTemplate('/Modules/ContractManagement/Theme/Backend/contract-single');
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1007901001, $request, $response));
$view->addData('contract', ContractMapper::get((int) $request->getData('id')));
$view->addData('contract', ContractMapper::get()->where('id', (int) $request->getData('id'))->execute());
$editor = new \Modules\Editor\Theme\Backend\Components\Editor\BaseView($this->app->l11nManager, $request, $response);
$view->addData('editor', $editor);

View File

@ -19,7 +19,7 @@ namespace Modules\ContractManagement\Models;
use Modules\Admin\Models\AccountMapper;
use Modules\Media\Models\MediaMapper;
use Modules\Organization\Models\UnitMapper;
use phpOMS\DataStorage\Database\DataMapperAbstract;
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
/**
* Contract mapper class.
@ -29,7 +29,7 @@ use phpOMS\DataStorage\Database\DataMapperAbstract;
* @link https://orange-management.org
* @since 1.0.0
*/
final class ContractMapper extends DataMapperAbstract
final class ContractMapper extends DataMapperFactory
{
/**
* Columns.
@ -37,7 +37,7 @@ final class ContractMapper 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 = [
'contractmgmt_contract_id' => ['name' => 'contractmgmt_contract_id', 'type' => 'int', 'internal' => 'id'],
'contractmgmt_contract_title' => ['name' => 'contractmgmt_contract_title', 'type' => 'string', 'internal' => 'title', 'autocomplete' => true],
'contractmgmt_contract_description' => ['name' => 'contractmgmt_contract_description', 'type' => 'string', 'internal' => 'description'],
@ -61,7 +61,7 @@ final class ContractMapper extends DataMapperAbstract
* @var string
* @since 1.0.0
*/
protected static string $table = 'contractmgmt_contract';
public const TABLE = 'contractmgmt_contract';
/**
* Primary field name.
@ -69,7 +69,7 @@ final class ContractMapper extends DataMapperAbstract
* @var string
* @since 1.0.0
*/
protected static string $primaryField = 'contractmgmt_contract_id';
public const PRIMARYFIELD ='contractmgmt_contract_id';
/**
* Created at.
@ -77,7 +77,7 @@ final class ContractMapper extends DataMapperAbstract
* @var string
* @since 1.0.0
*/
protected static string $createdAt = 'contractmgmt_contract_created_at';
public const CREATED_AT = 'contractmgmt_contract_created_at';
/**
* Has one relation.
@ -85,7 +85,7 @@ final class ContractMapper 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' => ContractTypeMapper::class,
'external' => 'contractmgmt_contract_type',
@ -106,7 +106,7 @@ final class ContractMapper 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 = [
'files' => [
'mapper' => MediaMapper::class, /* mapper of the related object */
'table' => 'contractmgmt_contract_media', /* table of the related object, null if no relation table is used (many->1) */

View File

@ -14,7 +14,7 @@ declare(strict_types=1);
namespace Modules\ContractManagement\Models;
use phpOMS\DataStorage\Database\DataMapperAbstract;
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
/**
* Contract type l11n mapper class.
@ -24,7 +24,7 @@ use phpOMS\DataStorage\Database\DataMapperAbstract;
* @link https://orange-management.org
* @since 1.0.0
*/
final class ContractTypeL11nMapper extends DataMapperAbstract
final class ContractTypeL11nMapper extends DataMapperFactory
{
/**
* Columns.
@ -32,7 +32,7 @@ final class ContractTypeL11nMapper 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 = [
'contractmgmt_type_l11n_id' => ['name' => 'contractmgmt_type_l11n_id', 'type' => 'int', 'internal' => 'id'],
'contractmgmt_type_l11n_title' => ['name' => 'contractmgmt_type_l11n_title', 'type' => 'string', 'internal' => 'title', 'autocomplete' => true],
'contractmgmt_type_l11n_type' => ['name' => 'contractmgmt_type_l11n_type', 'type' => 'int', 'internal' => 'type'],
@ -45,7 +45,7 @@ final class ContractTypeL11nMapper extends DataMapperAbstract
* @var string
* @since 1.0.0
*/
protected static string $table = 'contractmgmt_type_l11n';
public const TABLE = 'contractmgmt_type_l11n';
/**
* Primary field name.
@ -53,5 +53,5 @@ final class ContractTypeL11nMapper extends DataMapperAbstract
* @var string
* @since 1.0.0
*/
protected static string $primaryField = 'contractmgmt_type_l11n_id';
public const PRIMARYFIELD ='contractmgmt_type_l11n_id';
}

View File

@ -14,7 +14,7 @@ declare(strict_types=1);
namespace Modules\ContractManagement\Models;
use phpOMS\DataStorage\Database\DataMapperAbstract;
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
/**
* Contract type mapper class.
@ -24,7 +24,7 @@ use phpOMS\DataStorage\Database\DataMapperAbstract;
* @link https://orange-management.org
* @since 1.0.0
*/
final class ContractTypeMapper extends DataMapperAbstract
final class ContractTypeMapper extends DataMapperFactory
{
/**
* Columns.
@ -32,7 +32,7 @@ final class ContractTypeMapper 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 = [
'contractmgmt_type_id' => ['name' => 'contractmgmt_type_id', 'type' => 'int', 'internal' => 'id'],
];
@ -42,13 +42,12 @@ final class ContractTypeMapper 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' => ContractTypeL11nMapper::class,
'table' => 'contractmgmt_type_l11n',
'self' => 'contractmgmt_type_l11n_type',
'column' => 'title',
'conditional' => true,
'external' => null,
],
];
@ -59,7 +58,7 @@ final class ContractTypeMapper extends DataMapperAbstract
* @var string
* @since 1.0.0
*/
protected static string $table = 'contractmgmt_type';
public const TABLE = 'contractmgmt_type';
/**
* Primary field name.
@ -67,5 +66,5 @@ final class ContractTypeMapper extends DataMapperAbstract
* @var string
* @since 1.0.0
*/
protected static string $primaryField = 'contractmgmt_type_id';
public const PRIMARYFIELD ='contractmgmt_type_id';
}