new datamapper mostly implemented

This commit is contained in:
Dennis Eichhorn 2021-12-11 11:54:17 +01:00
parent c1e0f84592
commit f1e7cac376
11 changed files with 76 additions and 71 deletions

View File

@ -23,6 +23,9 @@ use Modules\HumanResourceManagement\Models\EmployeeHistoryMapper;
use Modules\HumanResourceManagement\Models\EmployeeMapper; use Modules\HumanResourceManagement\Models\EmployeeMapper;
use Modules\HumanResourceManagement\Models\EmployeeWorkHistory; use Modules\HumanResourceManagement\Models\EmployeeWorkHistory;
use Modules\HumanResourceManagement\Models\EmployeeWorkHistoryMapper; use Modules\HumanResourceManagement\Models\EmployeeWorkHistoryMapper;
use Modules\Organization\Models\NullDepartment;
use Modules\Organization\Models\NullPosition;
use Modules\Organization\Models\NullUnit;
use Modules\Profile\Models\Profile; use Modules\Profile\Models\Profile;
use Modules\Profile\Models\ProfileMapper; use Modules\Profile\Models\ProfileMapper;
use phpOMS\Message\Http\RequestStatusCode; use phpOMS\Message\Http\RequestStatusCode;
@ -128,7 +131,7 @@ final class ApiController extends Controller
foreach ($accounts as $account) { foreach ($accounts as $account) {
/** @var Profile $profile Profile */ /** @var Profile $profile Profile */
$profile = ProfileMapper::getFor((int) $account, 'account'); $profile = ProfileMapper::get()->where('account', (int) $account)->execute();
$employees[] = new Employee($profile); $employees[] = new Employee($profile);
} }
@ -269,9 +272,9 @@ final class ApiController extends Controller
private function createEmployeeHistoryFromRequest(RequestAbstract $request) : EmployeeHistory private function createEmployeeHistoryFromRequest(RequestAbstract $request) : EmployeeHistory
{ {
$history = new EmployeeHistory((int) ($request->getData('employee') ?? 0)); $history = new EmployeeHistory((int) ($request->getData('employee') ?? 0));
$history->unit = (int) ($request->getData('unit') ?? 0); $history->unit = new NullUnit((int) ($request->getData('unit') ?? 0));
$history->department = (int) ($request->getData('department') ?? 0); $history->department = new NullDepartment((int) ($request->getData('department') ?? 0));
$history->position = (int) ($request->getData('position') ?? 0); $history->position = new NullPosition((int) ($request->getData('position') ?? 0));
$history->start = new \DateTime($request->getData('start') ?? 'now'); $history->start = new \DateTime($request->getData('start') ?? 'now');
if (!empty($request->getData('end'))) { if (!empty($request->getData('end'))) {

View File

@ -50,7 +50,13 @@ final class BackendController extends Controller
$view->setTemplate('/Modules/HumanResourceManagement/Theme/Backend/staff-list'); $view->setTemplate('/Modules/HumanResourceManagement/Theme/Backend/staff-list');
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1002402001, $request, $response)); $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1002402001, $request, $response));
$view->setData('employees', EmployeeMapper::getAll(depth: 4)); $view->setData('employees', EmployeeMapper::getAll()
->with('profile')
->with('profile/account')
->with('companyHistory')
->with('companyHistory/unit')
->execute()
);
return $view; return $view;
} }
@ -97,7 +103,7 @@ final class BackendController extends Controller
$view->setTemplate('/Modules/HumanResourceManagement/Theme/Backend/staff-single'); $view->setTemplate('/Modules/HumanResourceManagement/Theme/Backend/staff-single');
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1002402001, $request, $response)); $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1002402001, $request, $response));
$employee = EmployeeMapper::get((int) $request->getData('id')); $employee = EmployeeMapper::get()->where('id', (int) $request->getData('id'))->execute();
$view->addData('employee', $employee); $view->addData('employee', $employee);

View File

@ -15,7 +15,7 @@ declare(strict_types=1);
namespace Modules\HumanResourceManagement\Models; namespace Modules\HumanResourceManagement\Models;
use Modules\Media\Models\MediaMapper; use Modules\Media\Models\MediaMapper;
use phpOMS\DataStorage\Database\DataMapperAbstract; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
/** /**
* EmployeHistory mapper class. * EmployeHistory mapper class.
@ -25,7 +25,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 EmployeeEducationHistoryMapper extends DataMapperAbstract final class EmployeeEducationHistoryMapper extends DataMapperFactory
{ {
/** /**
* Columns. * Columns.
@ -33,7 +33,7 @@ final class EmployeeEducationHistoryMapper 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 = [
'hr_staff_education_history_id' => ['name' => 'hr_staff_education_history_id', 'type' => 'int', 'internal' => 'id'], 'hr_staff_education_history_id' => ['name' => 'hr_staff_education_history_id', 'type' => 'int', 'internal' => 'id'],
'hr_staff_education_history_staff' => ['name' => 'hr_staff_education_history_staff', 'type' => 'int', 'internal' => 'employee'], 'hr_staff_education_history_staff' => ['name' => 'hr_staff_education_history_staff', 'type' => 'int', 'internal' => 'employee'],
'hr_staff_education_history_address' => ['name' => 'hr_staff_education_history_address', 'type' => 'Serializable', 'internal' => 'address'], 'hr_staff_education_history_address' => ['name' => 'hr_staff_education_history_address', 'type' => 'Serializable', 'internal' => 'address'],
@ -50,7 +50,7 @@ final class EmployeeEducationHistoryMapper 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 = [
'employee' => [ 'employee' => [
'mapper' => EmployeeMapper::class, 'mapper' => EmployeeMapper::class,
'external' => 'hr_staff_education_history_staff', 'external' => 'hr_staff_education_history_staff',
@ -63,7 +63,7 @@ final class EmployeeEducationHistoryMapper 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 = [
'files' => [ 'files' => [
'mapper' => MediaMapper::class, /* mapper of the related object */ 'mapper' => MediaMapper::class, /* mapper of the related object */
'table' => 'hr_staff_work_history_media', /* table of the related object, null if no relation table is used (many->1) */ 'table' => 'hr_staff_work_history_media', /* table of the related object, null if no relation table is used (many->1) */
@ -78,7 +78,7 @@ final class EmployeeEducationHistoryMapper extends DataMapperAbstract
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
protected static string $primaryField = 'hr_staff_education_history_id'; public const PRIMARYFIELD ='hr_staff_education_history_id';
/** /**
* Primary table. * Primary table.
@ -86,5 +86,5 @@ final class EmployeeEducationHistoryMapper extends DataMapperAbstract
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
protected static string $table = 'hr_staff_education_history'; public const TABLE = 'hr_staff_education_history';
} }

View File

@ -16,6 +16,9 @@ namespace Modules\HumanResourceManagement\Models;
use Modules\Media\Models\Media; use Modules\Media\Models\Media;
use Modules\Organization\Models\Department; use Modules\Organization\Models\Department;
use Modules\Organization\Models\NullDepartment;
use Modules\Organization\Models\NullPosition;
use Modules\Organization\Models\NullUnit;
use Modules\Organization\Models\Position; use Modules\Organization\Models\Position;
use Modules\Organization\Models\Unit; use Modules\Organization\Models\Unit;
use phpOMS\Contract\ArrayableInterface; use phpOMS\Contract\ArrayableInterface;
@ -49,26 +52,26 @@ class EmployeeHistory implements \JsonSerializable, ArrayableInterface
/** /**
* Unit * Unit
* *
* @var null|int|Unit * @var Unit
* @since 1.0.0 * @since 1.0.0
*/ */
public $unit = null; public Unit $unit;
/** /**
* Department * Department
* *
* @var null|int|Department * @var Department
* @since 1.0.0 * @since 1.0.0
*/ */
public $department = null; public Department $department;
/** /**
* Position * Position
* *
* @var null|int|Position * @var Position
* @since 1.0.0 * @since 1.0.0
*/ */
public $position = null; public Position $position;
/** /**
* Files. * Files.
@ -105,6 +108,9 @@ class EmployeeHistory implements \JsonSerializable, ArrayableInterface
{ {
$this->employee = $employee; $this->employee = $employee;
$this->start = new \DateTime('now'); $this->start = new \DateTime('now');
$this->unit = new NullUnit();
$this->department = new NullDepartment();
$this->position = new NullPosition();
} }
/** /**

View File

@ -18,7 +18,7 @@ use Modules\Media\Models\MediaMapper;
use Modules\Organization\Models\DepartmentMapper; use Modules\Organization\Models\DepartmentMapper;
use Modules\Organization\Models\PositionMapper; use Modules\Organization\Models\PositionMapper;
use Modules\Organization\Models\UnitMapper; use Modules\Organization\Models\UnitMapper;
use phpOMS\DataStorage\Database\DataMapperAbstract; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
/** /**
* EmployeHistory mapper class. * EmployeHistory mapper class.
@ -28,7 +28,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 EmployeeHistoryMapper extends DataMapperAbstract final class EmployeeHistoryMapper extends DataMapperFactory
{ {
/** /**
* Columns. * Columns.
@ -36,7 +36,7 @@ final class EmployeeHistoryMapper 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 = [
'hr_staff_history_id' => ['name' => 'hr_staff_history_id', 'type' => 'int', 'internal' => 'id'], 'hr_staff_history_id' => ['name' => 'hr_staff_history_id', 'type' => 'int', 'internal' => 'id'],
'hr_staff_history_staff' => ['name' => 'hr_staff_history_staff', 'type' => 'int', 'internal' => 'employee'], 'hr_staff_history_staff' => ['name' => 'hr_staff_history_staff', 'type' => 'int', 'internal' => 'employee'],
'hr_staff_history_unit' => ['name' => 'hr_staff_history_unit', 'type' => 'int', 'internal' => 'unit'], 'hr_staff_history_unit' => ['name' => 'hr_staff_history_unit', 'type' => 'int', 'internal' => 'unit'],
@ -52,7 +52,7 @@ final class EmployeeHistoryMapper 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 = [
'unit' => [ 'unit' => [
'mapper' => UnitMapper::class, 'mapper' => UnitMapper::class,
'external' => 'hr_staff_history_unit', 'external' => 'hr_staff_history_unit',
@ -77,7 +77,7 @@ final class EmployeeHistoryMapper 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 = [
'files' => [ 'files' => [
'mapper' => MediaMapper::class, /* mapper of the related object */ 'mapper' => MediaMapper::class, /* mapper of the related object */
'table' => 'hr_staff_work_history_media', /* table of the related object, null if no relation table is used (many->1) */ 'table' => 'hr_staff_work_history_media', /* table of the related object, null if no relation table is used (many->1) */
@ -92,7 +92,7 @@ final class EmployeeHistoryMapper extends DataMapperAbstract
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
protected static string $primaryField = 'hr_staff_history_id'; public const PRIMARYFIELD ='hr_staff_history_id';
/** /**
* Primary table. * Primary table.
@ -100,5 +100,5 @@ final class EmployeeHistoryMapper extends DataMapperAbstract
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
protected static string $table = 'hr_staff_history'; public const TABLE = 'hr_staff_history';
} }

View File

@ -14,11 +14,10 @@ declare(strict_types=1);
namespace Modules\HumanResourceManagement\Models; namespace Modules\HumanResourceManagement\Models;
use Modules\Admin\Models\AccountMapper;
use Modules\Media\Models\MediaMapper; use Modules\Media\Models\MediaMapper;
use Modules\Profile\Models\ProfileMapper; use Modules\Profile\Models\ProfileMapper;
use phpOMS\DataStorage\Database\DataMapperAbstract; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
use phpOMS\DataStorage\Database\Query\Builder; use phpOMS\DataStorage\Database\Mapper\ReadMapper;
/** /**
* Employe mapper class. * Employe mapper class.
@ -28,7 +27,7 @@ use phpOMS\DataStorage\Database\Query\Builder;
* @link https://orange-management.org * @link https://orange-management.org
* @since 1.0.0 * @since 1.0.0
*/ */
final class EmployeeMapper extends DataMapperAbstract final class EmployeeMapper extends DataMapperFactory
{ {
/** /**
* Columns. * Columns.
@ -36,7 +35,7 @@ final class EmployeeMapper 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 = [
'hr_staff_id' => ['name' => 'hr_staff_id', 'type' => 'int', 'internal' => 'id'], 'hr_staff_id' => ['name' => 'hr_staff_id', 'type' => 'int', 'internal' => 'id'],
'hr_staff_profile' => ['name' => 'hr_staff_profile', 'type' => 'int', 'internal' => 'profile'], 'hr_staff_profile' => ['name' => 'hr_staff_profile', 'type' => 'int', 'internal' => 'profile'],
'hr_staff_smiPHash' => ['name' => 'hr_staff_smiPHash', 'type' => 'string', 'internal' => 'semiPrivateHash'], 'hr_staff_smiPHash' => ['name' => 'hr_staff_smiPHash', 'type' => 'string', 'internal' => 'semiPrivateHash'],
@ -49,7 +48,7 @@ final class EmployeeMapper 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 = [
'profile' => [ 'profile' => [
'mapper' => ProfileMapper::class, 'mapper' => ProfileMapper::class,
'external' => 'hr_staff_profile', 'external' => 'hr_staff_profile',
@ -62,7 +61,7 @@ final class EmployeeMapper extends DataMapperAbstract
* @var array<string, array{mapper:string, external:string, by?:string, column?:string, conditional?:bool}> * @var array<string, array{mapper:string, external:string, by?:string, column?:string, conditional?:bool}>
* @since 1.0.0 * @since 1.0.0
*/ */
protected static array $ownsOne = [ public const OWNS_ONE = [
'image' => [ 'image' => [
'mapper' => MediaMapper::class, 'mapper' => MediaMapper::class,
'external' => 'hr_staff_image', 'external' => 'hr_staff_image',
@ -75,7 +74,7 @@ final class EmployeeMapper 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 = [
'files' => [ 'files' => [
'mapper' => MediaMapper::class, /* mapper of the related object */ 'mapper' => MediaMapper::class, /* mapper of the related object */
'table' => 'hr_staff_media', /* table of the related object, null if no relation table is used (many->1) */ 'table' => 'hr_staff_media', /* table of the related object, null if no relation table is used (many->1) */
@ -108,7 +107,7 @@ final class EmployeeMapper extends DataMapperAbstract
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
protected static string $table = 'hr_staff'; public const TABLE = 'hr_staff';
/** /**
* Primary field name. * Primary field name.
@ -116,31 +115,22 @@ final class EmployeeMapper extends DataMapperAbstract
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
protected static string $primaryField = 'hr_staff_id'; public const PRIMARYFIELD ='hr_staff_id';
/** /**
* Get the employee from an account * Get the employee from an account
* *
* @param int $account Account to get the employee for * @param int $account Account to get the employee for
* *
* @return Employee * @return ReadMapper
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public static function getFromAccount(int $account) : Employee public static function getFromAccount(int $account) : ReadMapper
{ {
$depth = 3; return self::get()
$query = new Builder(self::$db); ->with('profile')
$query = self::getQuery($query) ->with('profile/account')
->innerJoin(ProfileMapper::getTable()) ->where('profile/account', $account);
->on(self::$table . '_d' . $depth . '.hr_staff_profile', '=', ProfileMapper::getTable() . '.' . ProfileMapper::getPrimaryField())
->innerJoin(AccountMapper::getTable())
->on(ProfileMapper::getTable() . '.profile_account_account', '=', AccountMapper::getTable() . '.' . AccountMapper::getPrimaryField())
->where(AccountMapper::getTable() . '.' . AccountMapper::getPrimaryField(), '=', $account)
->limit(1);
$employee = self::getAllByQuery($query);
return empty($employee) ? new NullEmployee() : \end($employee);
} }
} }

View File

@ -15,7 +15,7 @@ declare(strict_types=1);
namespace Modules\HumanResourceManagement\Models; namespace Modules\HumanResourceManagement\Models;
use Modules\Media\Models\MediaMapper; use Modules\Media\Models\MediaMapper;
use phpOMS\DataStorage\Database\DataMapperAbstract; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
/** /**
* EmployeHistory mapper class. * EmployeHistory mapper class.
@ -25,7 +25,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 EmployeeWorkHistoryMapper extends DataMapperAbstract final class EmployeeWorkHistoryMapper extends DataMapperFactory
{ {
/** /**
* Columns. * Columns.
@ -33,7 +33,7 @@ final class EmployeeWorkHistoryMapper 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 = [
'hr_staff_work_history_id' => ['name' => 'hr_staff_work_history_id', 'type' => 'int', 'internal' => 'id'], 'hr_staff_work_history_id' => ['name' => 'hr_staff_work_history_id', 'type' => 'int', 'internal' => 'id'],
'hr_staff_work_history_staff' => ['name' => 'hr_staff_work_history_staff', 'type' => 'int', 'internal' => 'employee'], 'hr_staff_work_history_staff' => ['name' => 'hr_staff_work_history_staff', 'type' => 'int', 'internal' => 'employee'],
'hr_staff_work_history_address' => ['name' => 'hr_staff_work_history_address', 'type' => 'Serializable', 'internal' => 'address'], 'hr_staff_work_history_address' => ['name' => 'hr_staff_work_history_address', 'type' => 'Serializable', 'internal' => 'address'],
@ -48,7 +48,7 @@ final class EmployeeWorkHistoryMapper 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 = [
'employee' => [ 'employee' => [
'mapper' => EmployeeMapper::class, 'mapper' => EmployeeMapper::class,
'external' => 'hr_staff_work_history_staff', 'external' => 'hr_staff_work_history_staff',
@ -61,7 +61,7 @@ final class EmployeeWorkHistoryMapper 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 = [
'files' => [ 'files' => [
'mapper' => MediaMapper::class, /* mapper of the related object */ 'mapper' => MediaMapper::class, /* mapper of the related object */
'table' => 'hr_staff_work_history_media', /* table of the related object, null if no relation table is used (many->1) */ 'table' => 'hr_staff_work_history_media', /* table of the related object, null if no relation table is used (many->1) */
@ -76,7 +76,7 @@ final class EmployeeWorkHistoryMapper extends DataMapperAbstract
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
protected static string $primaryField = 'hr_staff_work_history_id'; public const PRIMARYFIELD ='hr_staff_work_history_id';
/** /**
* Primary table. * Primary table.
@ -84,5 +84,5 @@ final class EmployeeWorkHistoryMapper extends DataMapperAbstract
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
protected static string $table = 'hr_staff_work_history'; public const TABLE = 'hr_staff_work_history';
} }

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

@ -61,12 +61,12 @@ final class ApiControllerTest extends \PHPUnit\Framework\TestCase
$department->name = 'HRMgmtDepartmentTest'; $department->name = 'HRMgmtDepartmentTest';
$department->description = 'Description'; $department->description = 'Description';
$department->unit = new NullUnit(1); $department->unit = new NullUnit(1);
DepartmentMapper::create($department); DepartmentMapper::create()->execute($department);
$position = new Position(); $position = new Position();
$position->name = 'HRMgmtPositionTest'; $position->name = 'HRMgmtPositionTest';
$position->description = 'Description'; $position->description = 'Description';
PositionMapper::create($position); PositionMapper::create()->execute($position);
} }
/** /**

View File

@ -30,15 +30,15 @@ final class EmployeeHistoryMapperTest extends \PHPUnit\Framework\TestCase
*/ */
public function testCRUD() : void public function testCRUD() : void
{ {
$employee = new Employee(ProfileMapper::get(1)); $employee = new Employee(ProfileMapper::get()->where('id', 1)->execute());
$history = new EmployeeHistory($employee); $history = new EmployeeHistory($employee);
$id = EmployeeHistoryMapper::create($history); $id = EmployeeHistoryMapper::create()->execute($history);
self::assertGreaterThan(0, $history->getId()); self::assertGreaterThan(0, $history->getId());
self::assertEquals($id, $history->getId()); self::assertEquals($id, $history->getId());
$historyR = EmployeeHistoryMapper::get($history->getId()); $historyR = EmployeeHistoryMapper::get()->where('id', $history->getId())->execute();
self::assertEquals($history->employee->getId(), $historyR->employee->getId()); self::assertEquals($history->employee->getId(), $historyR->employee->getId());
} }
} }

View File

@ -31,23 +31,23 @@ final class EmployeeMapperTest extends \PHPUnit\Framework\TestCase
*/ */
public function testCR() : void public function testCR() : void
{ {
if (($profile = ProfileMapper::getFor(1, 'account'))->getId() === 0) { if (($profile = ProfileMapper::get()->where('account', 1)->execute())->getId() === 0) {
$profile = new Profile(); $profile = new Profile();
$profile->account = AccountMapper::get(1); $profile->account = AccountMapper::get()->where('id', 1)->execute();
$profile->birthday = ($date = new \DateTime('now')); $profile->birthday = ($date = new \DateTime('now'));
$id = ProfileMapper::create($profile); $id = ProfileMapper::create()->execute($profile);
} }
$employee = new Employee($profile); $employee = new Employee($profile);
$id = EmployeeMapper::create($employee); $id = EmployeeMapper::create()->execute($employee);
self::assertGreaterThan(0, $employee->getId()); self::assertGreaterThan(0, $employee->getId());
self::assertEquals($id, $employee->getId()); self::assertEquals($id, $employee->getId());
$employeeR = EmployeeMapper::get($employee->getId()); $employeeR = EmployeeMapper::get()->where('id', $employee->getId())->execute();
self::assertEquals($employee->profile->getId(), $employeeR->profile->getId()); self::assertEquals($employee->profile->getId(), $employeeR->profile->getId());
self::assertGreaterThan(0, EmployeeMapper::getFromAccount(1)->getId()); self::assertGreaterThan(0, EmployeeMapper::getFromAccount(1)->limit(1)->execute()->getId());
} }
} }