remove some getter/setter

This commit is contained in:
Dennis Eichhorn 2020-11-24 17:31:19 +01:00
parent 14454b576c
commit f4d3bf2d4a
7 changed files with 79 additions and 124 deletions

View File

@ -52,13 +52,13 @@ final class ApiController extends Controller
{
if (!empty($val = $this->validateClientCreate($request))) {
$response->set('client_create', new FormValidation($val));
$response->getHeader()->setStatusCode(RequestStatusCode::R_400);
$response->header->status = RequestStatusCode::R_400;
return;
}
$client = $this->createClientFromRequest($request);
$this->createModel($request->getHeader()->getAccount(), $client, ClientMapper::class, 'client', $request->getOrigin());
$this->createModel($request->header->account, $client, ClientMapper::class, 'client', $request->getOrigin());
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Client', 'Client successfully created', $client);
}
@ -74,21 +74,21 @@ final class ApiController extends Controller
private function createClientFromRequest(RequestAbstract $request) : Client
{
$account = new Account();
$account->setName1($request->getData('name1') ?? '');
$account->setName2($request->getData('name2') ?? '');
$account->name1 = $request->getData('name1') ?? '';
$account->name2 = $request->getData('name2') ?? '';
$profile = new Profile($account);
$client = new Client();
$client->setNumber($request->getData('number') ?? '');
$client->setProfile($profile);
$client->number = $request->getData('number') ?? '';
$client->profile = $profile;
$addr = new Address();
$addr->setAddress($request->getData('address') ?? '');
$addr->setPostal($request->getData('postal') ?? '');
$addr->setCity($request->getData('city') ?? '');
$addr->address = $request->getData('address') ?? '';
$addr->postal = $request->getData('postal') ?? '';
$addr->city = $request->getData('city') ?? '';
$addr->setCountry($request->getData('country') ?? '');
$addr->setState($request->getData('state') ?? '');
$addr->state = $request->getData('state') ?? '';
$client->setMainAddress($addr);
return $client;
@ -134,16 +134,16 @@ final class ApiController extends Controller
if (!empty($val = $profileModule->validateContactElementCreate($request))) {
$response->set('contact_element_create', new FormValidation($val));
$response->getHeader()->setStatusCode(RequestStatusCode::R_400);
$response->header->status = RequestStatusCode::R_400;
return;
}
$contactElement = $profileModule->createContactElementFromRequest($request);
$this->createModel($request->getHeader()->getAccount(), $contactElement, ContactElementMapper::class, 'client-contactElement', $request->getOrigin());
$this->createModel($request->header->account, $contactElement, ContactElementMapper::class, 'client-contactElement', $request->getOrigin());
$this->createModelRelation(
$request->getHeader()->getAccount(),
$request->header->account,
(int) $request->getData('client'),
$contactElement->getId(),
ClientMapper::class, 'contactElements', '', $request->getOrigin()

View File

@ -102,4 +102,23 @@ final class BackendController extends Controller
return $view;
}
/**
* Routing end-point for application behaviour.
*
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
* @param mixed $data Generic data
*
* @return RenderableInterface
*
* @since 1.0.0
* @codeCoverageIgnore
*/
public function viewClientManagementClientAnalysis(RequestAbstract $request, ResponseAbstract $response, $data = null) : RenderableInterface
{
$view = new View($this->app->l11nManager, $request, $response);
return $view;
}
}

View File

@ -33,7 +33,7 @@ class Client
{
protected int $id = 0;
private string $number = '';
public string $number = '';
private string $numberReverse = '';
@ -45,9 +45,9 @@ class Client
private string $info = '';
private \DateTimeImmutable $createdAt;
public \DateTimeImmutable $createdAt;
private Profile $profile;
public Profile $profile;
private array $files = [];
@ -91,32 +91,6 @@ class Client
return $this->id;
}
/**
* Get number.
*
* @return string
*
* @since 1.0.0
*/
public function getNumber() : string
{
return $this->number;
}
/**
* Set number.
*
* @param string $number Number
*
* @return void
*
* @since 1.0.0
*/
public function setNumber(string $number) : void
{
$this->number = $number;
}
/**
* Get reverse number.
*
@ -303,44 +277,6 @@ class Client
$this->info = $info;
}
/**
* Get created at date time
*
* @return \DateTimeImmutable
*
* @since 1.0.0
*/
public function getCreatedAt() : \DateTimeImmutable
{
return $this->createdAt;
}
/**
* Get profile.
*
* @return Profile
*
* @since 1.0.0
*/
public function getProfile() : Profile
{
return $this->profile;
}
/**
* Set profile.
*
* @param Profile $profile Profile
*
* @return void
*
* @since 1.0.0
*/
public function setProfile(Profile $profile) : void
{
$this->profile = $profile;
}
/**
* Set main address
*

View File

@ -32,7 +32,7 @@ echo $this->getData('nav')->render(); ?>
</ul>
</div>
<div class="tab-content">
<input type="radio" id="c-tab-1" name="tabular-2"<?= $this->request->getUri()->getFragment() === 'c-tab-1' ? ' checked' : ''; ?>>
<input type="radio" id="c-tab-1" name="tabular-2"<?= $this->request->uri->fragment === 'c-tab-1' ? ' checked' : ''; ?>>
<div class="tab">
<div class="row">
<div class="col-xs-12 col-md-6 col-lg-4">
@ -57,7 +57,7 @@ echo $this->getData('nav')->render(); ?>
</div>
</div>
</div>
<input type="radio" id="c-tab-2" name="tabular-2"<?= $this->request->getUri()->getFragment() === 'c-tab-2' ? ' checked' : ''; ?>>
<input type="radio" id="c-tab-2" name="tabular-2"<?= $this->request->uri->fragment === 'c-tab-2' ? ' checked' : ''; ?>>
<div class="tab">
<div class="row">
<div class="col-xs-12 col-md-6 col-lg-4">
@ -92,7 +92,7 @@ echo $this->getData('nav')->render(); ?>
</div>
</div>
</div>
<input type="radio" id="c-tab-3" name="tabular-2"<?= $this->request->getUri()->getFragment() === 'c-tab-3' ? ' checked' : ''; ?>>
<input type="radio" id="c-tab-3" name="tabular-2"<?= $this->request->uri->fragment === 'c-tab-3' ? ' checked' : ''; ?>>
<div class="tab">
<div class="row">
<div class="col-xs-12 col-md-6 col-lg-4">
@ -124,7 +124,7 @@ echo $this->getData('nav')->render(); ?>
</div>
</div>
</div>
<input type="radio" id="c-tab-4" name="tabular-2"<?= $this->request->getUri()->getFragment() === 'c-tab-4' ? ' checked' : ''; ?>>
<input type="radio" id="c-tab-4" name="tabular-2"<?= $this->request->uri->fragment === 'c-tab-4' ? ' checked' : ''; ?>>
<div class="tab">
<div class="row">
<div class="col-xs-12 col-md-6 col-lg-4">
@ -156,7 +156,7 @@ echo $this->getData('nav')->render(); ?>
</div>
</div>
</div>
<input type="radio" id="c-tab-5" name="tabular-2"<?= $this->request->getUri()->getFragment() === 'c-tab-5' ? ' checked' : ''; ?>>
<input type="radio" id="c-tab-5" name="tabular-2"<?= $this->request->uri->fragment === 'c-tab-5' ? ' checked' : ''; ?>>
<div class="tab">
<div class="row">
<div class="col-xs-12 col-md-6 col-lg-4">
@ -178,7 +178,7 @@ echo $this->getData('nav')->render(); ?>
</div>
</div>
</div>
<input type="radio" id="c-tab-6" name="tabular-2"<?= $this->request->getUri()->getFragment() === 'c-tab-6' ? ' checked' : ''; ?>>
<input type="radio" id="c-tab-6" name="tabular-2"<?= $this->request->uri->fragment === 'c-tab-6' ? ' checked' : ''; ?>>
<div class="tab">
<div class="row">
<div class="col-xs-12 col-md-6 col-lg-4">
@ -220,7 +220,7 @@ echo $this->getData('nav')->render(); ?>
</div>
</div>
</div>
<input type="radio" id="c-tab-7" name="tabular-2"<?= $this->request->getUri()->getFragment() === 'c-tab-7' ? ' checked' : ''; ?>>
<input type="radio" id="c-tab-7" name="tabular-2"<?= $this->request->uri->fragment === 'c-tab-7' ? ' checked' : ''; ?>>
<div class="tab">
<div class="row">
<div class="col-xs-12 col-md-6 col-lg-4">
@ -250,10 +250,10 @@ echo $this->getData('nav')->render(); ?>
</div>
</div>
</div>
<input type="radio" id="c-tab-8" name="tabular-2"<?= $this->request->getUri()->getFragment() === 'c-tab-8' ? ' checked' : ''; ?>>
<input type="radio" id="c-tab-8" name="tabular-2"<?= $this->request->uri->fragment === 'c-tab-8' ? ' checked' : ''; ?>>
<div class="tab">
</div>
<input type="radio" id="c-tab-9" name="tabular-2"<?= $this->request->getUri()->getFragment() === 'c-tab-9' ? ' checked' : ''; ?>>
<input type="radio" id="c-tab-9" name="tabular-2"<?= $this->request->uri->fragment === 'c-tab-9' ? ' checked' : ''; ?>>
<div class="tab">
<div class="row">
<div class="col-xs-12">
@ -279,8 +279,8 @@ echo $this->getData('nav')->render(); ?>
<tbody>
<tr>
<td><?= $this->printHtml($this->request->getOrigin()); ?>
<td><?= $this->printHtml($this->request->getHeader()->getAccount()); ?>
<td><?= $this->printHtml($this->request->getHeader()->getAccount()); ?>
<td><?= $this->printHtml($this->request->header->account); ?>
<td><?= $this->printHtml($this->request->header->account); ?>
<td>Creating customer
<td><?= $this->printHtml((new \DateTime('now'))->format('Y-m-d H:i:s')); ?>
</table>

View File

@ -48,11 +48,11 @@ echo $this->getData('nav')->render(); ?>
<?php $count = 0; foreach ($clients as $key => $value) : ++$count;
$url = UriFactory::build('{/prefix}sales/client/profile?{?}&id=' . $value->getId()); ?>
<tr data-href="<?= $url; ?>">
<td data-label="<?= $this->getHtml('ID', '0', '0'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->getNumber()); ?></a>
<td data-label="<?= $this->getHtml('Name'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->getProfile()->getAccount()->getName1()); ?> <?= $this->printHtml($value->getProfile()->getAccount()->getName2()); ?></a>
<td data-label="<?= $this->getHtml('City'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->getMainAddress()->getCity()); ?></a>
<td data-label="<?= $this->getHtml('Zip'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->getMainAddress()->getPostal()); ?></a>
<td data-label="<?= $this->getHtml('Address'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->getMainAddress()->getAddress()); ?></a>
<td data-label="<?= $this->getHtml('ID', '0', '0'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->number); ?></a>
<td data-label="<?= $this->getHtml('Name'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->profile->account->name1); ?> <?= $this->printHtml($value->profile->account->name2); ?></a>
<td data-label="<?= $this->getHtml('City'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->getMainAddress()->city); ?></a>
<td data-label="<?= $this->getHtml('Zip'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->getMainAddress()->postal); ?></a>
<td data-label="<?= $this->getHtml('Address'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->getMainAddress()->address); ?></a>
<td data-label="<?= $this->getHtml('Country'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->getMainAddress()->getCountry()); ?></a>
<?php endforeach; ?>
<?php if ($count === 0) : ?>

View File

@ -53,7 +53,7 @@ echo $this->getData('nav')->render();
</ul>
</div>
<div class="tab-content">
<input type="radio" id="c-tab-1" name="tabular-2"<?= $this->request->getUri()->getFragment() === 'c-tab-1' ? ' checked' : ''; ?>>
<input type="radio" id="c-tab-1" name="tabular-2"<?= $this->request->uri->fragment === 'c-tab-1' ? ' checked' : ''; ?>>
<div class="tab">
<div class="row">
<div class="col-xs-12 col-lg-3 last-lg">
@ -62,13 +62,13 @@ echo $this->getData('nav')->render();
<div class="portlet-body">
<table class="layout wf-100">
<tr><td><label for="iId"><?= $this->getHtml('ID', '0', '0'); ?></label>
<tr><td><span class="input"><button type="button" formaction=""><i class="fa fa-book"></i></button><input type="number" id="iId" min="1" name="id" value="<?= $this->printHtml($client->getNumber()); ?>" disabled></span>
<tr><td><span class="input"><button type="button" formaction=""><i class="fa fa-book"></i></button><input type="number" id="iId" min="1" name="id" value="<?= $this->printHtml($client->number); ?>" disabled></span>
<tr><td><label for="iName1"><?= $this->getHtml('Name1'); ?></label>
<tr><td><input type="text" id="iName1" name="name1" value="<?= $this->printHtml($client->getProfile()->getAccount()->getName1()); ?>" required>
<tr><td><input type="text" id="iName1" name="name1" value="<?= $this->printHtml($client->profile->account->name1); ?>" required>
<tr><td><label for="iName2"><?= $this->getHtml('Name2'); ?></label>
<tr><td><input type="text" id="iName2" name="name2" value="<?= $this->printHtml($client->getProfile()->getAccount()->getName2()); ?>">
<tr><td><input type="text" id="iName2" name="name2" value="<?= $this->printHtml($client->profile->account->name2); ?>">
<tr><td><label for="iName3"><?= $this->getHtml('Name3'); ?></label>
<tr><td><input type="text" id="iName3" name="name3" value="<?= $this->printHtml($client->getProfile()->getAccount()->getName3()); ?>">
<tr><td><input type="text" id="iName3" name="name3" value="<?= $this->printHtml($client->profile->account->name3); ?>">
</table>
</div>
<div class="portlet-foot">
@ -95,16 +95,16 @@ echo $this->getData('nav')->render();
<div class="portlet-head"><?= $this->getHtml('Address'); ?></div>
<div class="portlet-body">
<table class="layout wf-100">
<?php if (!empty($client->getMainAddress()->getAddition())) : ?>
<?php if (!empty($client->getMainAddress()->addition)) : ?>
<tr><td><label for="iName1"><?= $this->getHtml('Addition'); ?></label>
<tr><td><input type="text" id="iName1" name="name1" value="<?= $this->printHtml($client->getMainAddress()->getAddition()); ?>">
<tr><td><input type="text" id="iName1" name="name1" value="<?= $this->printHtml($client->getMainAddress()->addition); ?>">
<?php endif; ?>
<tr><td><label for="iName1"><?= $this->getHtml('Address'); ?></label>
<tr><td><input type="text" id="iName1" name="name1" value="<?= $this->printHtml($client->getMainAddress()->getAddress()); ?>" required>
<tr><td><input type="text" id="iName1" name="name1" value="<?= $this->printHtml($client->getMainAddress()->address); ?>" required>
<tr><td><label for="iName1"><?= $this->getHtml('Postal'); ?></label>
<tr><td><input type="text" id="iName1" name="name1" value="<?= $this->printHtml($client->getMainAddress()->getPostal()); ?>" required>
<tr><td><input type="text" id="iName1" name="name1" value="<?= $this->printHtml($client->getMainAddress()->postal); ?>" required>
<tr><td><label for="iName1"><?= $this->getHtml('City'); ?></label>
<tr><td><input type="text" id="iName1" name="name1" value="<?= $this->printHtml($client->getMainAddress()->getCity()); ?>" required>
<tr><td><input type="text" id="iName1" name="name1" value="<?= $this->printHtml($client->getMainAddress()->city); ?>" required>
<tr><td><label for="iName1"><?= $this->getHtml('Country'); ?></label>
<tr><td><select>
<?php foreach ($countryCodes as $code3 => $code2) : ?>
@ -219,7 +219,7 @@ echo $this->getData('nav')->render();
</div>
</div>
</div>
<input type="radio" id="c-tab-2" name="tabular-2"<?= $this->request->getUri()->getFragment() === 'c-tab-2' ? ' checked' : ''; ?>>
<input type="radio" id="c-tab-2" name="tabular-2"<?= $this->request->uri->fragment === 'c-tab-2' ? ' checked' : ''; ?>>
<div class="tab">
<div class="row">
<div class="col-xs-12 col-md-6 col-lg-4">
@ -254,7 +254,7 @@ echo $this->getData('nav')->render();
</div>
</div>
</div>
<input type="radio" id="c-tab-3" name="tabular-2"<?= $this->request->getUri()->getFragment() === 'c-tab-3' ? ' checked' : ''; ?>>
<input type="radio" id="c-tab-3" name="tabular-2"<?= $this->request->uri->fragment === 'c-tab-3' ? ' checked' : ''; ?>>
<div class="tab">
<div class="row">
<div class="col-xs-12 col-md-6 col-lg-4">
@ -286,7 +286,7 @@ echo $this->getData('nav')->render();
</div>
</div>
</div>
<input type="radio" id="c-tab-4" name="tabular-2"<?= $this->request->getUri()->getFragment() === 'c-tab-4' ? ' checked' : ''; ?>>
<input type="radio" id="c-tab-4" name="tabular-2"<?= $this->request->uri->fragment === 'c-tab-4' ? ' checked' : ''; ?>>
<div class="tab">
<div class="row">
<div class="col-xs-12 col-md-6 col-lg-4">
@ -318,7 +318,7 @@ echo $this->getData('nav')->render();
</div>
</div>
</div>
<input type="radio" id="c-tab-5" name="tabular-2"<?= $this->request->getUri()->getFragment() === 'c-tab-5' ? ' checked' : ''; ?>>
<input type="radio" id="c-tab-5" name="tabular-2"<?= $this->request->uri->fragment === 'c-tab-5' ? ' checked' : ''; ?>>
<div class="tab">
<div class="row">
<div class="col-xs-12 col-md-6 col-lg-4">
@ -340,7 +340,7 @@ echo $this->getData('nav')->render();
</div>
</div>
</div>
<input type="radio" id="c-tab-6" name="tabular-2"<?= $this->request->getUri()->getFragment() === 'c-tab-6' ? ' checked' : ''; ?>>
<input type="radio" id="c-tab-6" name="tabular-2"<?= $this->request->uri->fragment === 'c-tab-6' ? ' checked' : ''; ?>>
<div class="tab">
<div class="row">
<div class="col-xs-12 col-md-6 col-lg-4">
@ -382,7 +382,7 @@ echo $this->getData('nav')->render();
</div>
</div>
</div>
<input type="radio" id="c-tab-7" name="tabular-2"<?= $this->request->getUri()->getFragment() === 'c-tab-7' ? ' checked' : ''; ?>>
<input type="radio" id="c-tab-7" name="tabular-2"<?= $this->request->uri->fragment === 'c-tab-7' ? ' checked' : ''; ?>>
<div class="tab">
<div class="row">
<div class="col-xs-12 col-md-6 col-lg-4">
@ -412,10 +412,10 @@ echo $this->getData('nav')->render();
</div>
</div>
</div>
<input type="radio" id="c-tab-8" name="tabular-2"<?= $this->request->getUri()->getFragment() === 'c-tab-8' ? ' checked' : ''; ?>>
<input type="radio" id="c-tab-8" name="tabular-2"<?= $this->request->uri->fragment === 'c-tab-8' ? ' checked' : ''; ?>>
<div class="tab">
</div>
<input type="radio" id="c-tab-9" name="tabular-2"<?= $this->request->getUri()->getFragment() === 'c-tab-9' ? ' checked' : ''; ?>>
<input type="radio" id="c-tab-9" name="tabular-2"<?= $this->request->uri->fragment === 'c-tab-9' ? ' checked' : ''; ?>>
<div class="tab">
<div class="row">
<div class="col-xs-12">
@ -441,8 +441,8 @@ echo $this->getData('nav')->render();
<tbody>
<tr>
<td><?= $this->printHtml($this->request->getOrigin()); ?>
<td><?= $this->printHtml($this->request->getHeader()->getAccount()); ?>
<td><?= $this->printHtml($this->request->getHeader()->getAccount()); ?>
<td><?= $this->printHtml($this->request->header->account); ?>
<td><?= $this->printHtml($this->request->header->account); ?>
<td>Creating customer
<td><?= $this->printHtml((new \DateTime('now'))->format('Y-m-d H:i:s')); ?>
</table>

View File

@ -33,17 +33,17 @@ class ClientMapperTest extends \PHPUnit\Framework\TestCase
public function testCR() : void
{
$client = new Client();
$client->setNumber('123456789');
$client->number = '123456789';
// This is required because by default a NullAccount without an ID is created in the Profile model
// but NullModels without ids are handled like "null" values which are not allowed for Accounts.
$profile = ProfileMapper::getFor(1, 'account');
$profile = $profile instanceof NullProfile ? new Profile() : $profile;
if ($profile->getAccount()->getId() === 0) {
$profile->setAccount(new NullAccount(1));
if ($profile->account->getId() === 0) {
$profile->account = new NullAccount(1);
}
$client->setProfile($profile);
$client->profile = $profile;
$id = ClientMapper::create($client);
self::assertGreaterThan(0, $client->getId());
@ -59,15 +59,15 @@ class ClientMapperTest extends \PHPUnit\Framework\TestCase
{
$profile = ProfileMapper::getFor(1, 'account');
$profile = $profile instanceof NullProfile ? new Profile() : $profile;
if ($profile->getAccount()->getId() === 0) {
$profile->setAccount(new NullAccount(1));
if ($profile->account->getId() === 0) {
$profile->account = new NullAccount(1);
}
for ($i = 0; $i < 100; ++$i) {
$client = new Client();
$client->setNumber((string) \mt_rand(100000, 999999));
$client->number = (string) \mt_rand(100000, 999999);
$client->setProfile($profile);
$client->profile = $profile;
ClientMapper::create($client);
}
}