Initial xentral_oss_20.3.c9ffacf
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Modules\ImportTemplate\Service;
|
||||
|
||||
use Xentral\Components\Database\Database;
|
||||
use Xentral\Modules\ImportTemplate\Exception\ImportTemplateNotFoundException;
|
||||
|
||||
class ImportTemplateGateway
|
||||
{
|
||||
/** @var Database $db */
|
||||
private $db;
|
||||
|
||||
/**
|
||||
* @param Database $db
|
||||
*/
|
||||
public function __construct(Database $db)
|
||||
{
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $importTemplateId
|
||||
*
|
||||
* @throws ImportTemplateNotFoundException
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getImportTemplateById($importTemplateId)
|
||||
{
|
||||
$importTemplateData = $this->db->fetchRow(
|
||||
'SELECT
|
||||
i.id,
|
||||
i.bezeichnung AS `label`,
|
||||
i.ziel AS `target`,
|
||||
i.internebemerkung AS `internalnote`,
|
||||
i.fields AS `fields`,
|
||||
i.importtrennzeichen AS `delimiter`,
|
||||
i.importerstezeilenummer AS `linenumber`,
|
||||
i.importdatenmaskierung AS `masking`,
|
||||
i.importzeichensatz AS `importcharset`,
|
||||
i.utf8decode AS `utf8decode`,
|
||||
i.charset AS `charset`
|
||||
FROM `importvorlage` AS `i`
|
||||
WHERE i.id = :id',
|
||||
['id' => $importTemplateId]
|
||||
);
|
||||
|
||||
if (empty($importTemplateData)) {
|
||||
throw new ImportTemplateNotFoundException('ImportTemplateId not found: ID ' . $importTemplateId);
|
||||
}
|
||||
|
||||
return $importTemplateData;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Modules\ImportTemplate\Service;
|
||||
|
||||
use RuntimeException;
|
||||
use Xentral\Modules\ImportTemplate\Data\ImportTemplate;
|
||||
use Xentral\Modules\ImportTemplate\Exception\ImportTemplateNotFoundException;
|
||||
use Xentral\Modules\ImportTemplate\Exception\InvalidTemplateDataException;
|
||||
|
||||
final class ImportTemplateJsonService
|
||||
{
|
||||
/** @var ImportTemplateService $importTemplateService */
|
||||
private $importTemplateService;
|
||||
|
||||
/** @var ImportTemplateGateway $importTemplateGateway */
|
||||
private $importTemplateGateway;
|
||||
|
||||
/**
|
||||
* @param ImportTemplateService $importTemplateService
|
||||
* @param ImportTemplateGateway $importTemplateGateway
|
||||
*/
|
||||
public function __construct(
|
||||
ImportTemplateService $importTemplateService,
|
||||
ImportTemplateGateway $importTemplateGateway
|
||||
) {
|
||||
$this->importTemplateService = $importTemplateService;
|
||||
$this->importTemplateGateway = $importTemplateGateway;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $templateData
|
||||
*
|
||||
* @throws InvalidTemplateDataException
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function insertAndValidateImportTemplate($templateData)
|
||||
{
|
||||
$validData = ImportTemplate::fromArray($templateData);
|
||||
|
||||
return $this->insertImportTemplate($validData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ImportTemplate $importTemplate
|
||||
*
|
||||
* @throws RuntimeException
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function insertImportTemplate(ImportTemplate $importTemplate)
|
||||
{
|
||||
return $this->importTemplateService->insertImportTemplate($importTemplate);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $importTemplateId
|
||||
*
|
||||
* @throws ImportTemplateNotFoundException
|
||||
*
|
||||
* @return ImportTemplate
|
||||
*/
|
||||
public function getImportTemplate($importTemplateId)
|
||||
{
|
||||
$importTemplateData = $this->importTemplateGateway->getImportTemplateById($importTemplateId);
|
||||
$importTemplate = ImportTemplate::fromDbState($importTemplateData);
|
||||
|
||||
return $importTemplate;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace Xentral\Modules\ImportTemplate\Service;
|
||||
|
||||
use RuntimeException;
|
||||
use Xentral\Modules\ImportTemplate\Data\ImportTemplate;
|
||||
use Xentral\Components\Database\Database;
|
||||
|
||||
class ImportTemplateService
|
||||
{
|
||||
/** @var Database $db */
|
||||
private $db;
|
||||
|
||||
public function __construct(Database $db)
|
||||
{
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ImportTemplate $importTemplate
|
||||
*
|
||||
* @throws RuntimeException
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function insertImportTemplate(ImportTemplate $importTemplate)
|
||||
{
|
||||
$sql = 'INSERT INTO `importvorlage`
|
||||
(
|
||||
`bezeichnung`,
|
||||
`ziel`,
|
||||
`internebemerkung`,
|
||||
`fields`,
|
||||
`importtrennzeichen`,
|
||||
`importerstezeilenummer`,
|
||||
`importdatenmaskierung`,
|
||||
`importzeichensatz`,
|
||||
`utf8decode`,
|
||||
`charset`
|
||||
|
||||
)
|
||||
VALUES (
|
||||
:bezeichnung,
|
||||
:ziel,
|
||||
:internebemerkung,
|
||||
:fields,
|
||||
:importtrennzeichen,
|
||||
:importerstezeilenummer,
|
||||
:importdatenmaskierung,
|
||||
:importzeichensatz,
|
||||
:utf8decode,
|
||||
:charset
|
||||
)';
|
||||
|
||||
$values = [
|
||||
'bezeichnung' => $importTemplate->getLabel(),
|
||||
'ziel' => $importTemplate->getTarget(),
|
||||
'internebemerkung' => $importTemplate->getInternalNote(),
|
||||
'fields' => $importTemplate->getFields(),
|
||||
'importtrennzeichen' => $importTemplate->getDelimiter(),
|
||||
'importerstezeilenummer' => $importTemplate->getLineNumber(),
|
||||
'importdatenmaskierung' => $importTemplate->getMasking(),
|
||||
'importzeichensatz' => $importTemplate->getImportCharSet(),
|
||||
'utf8decode' => $importTemplate->getUtf8decode(),
|
||||
'charset' => $importTemplate->getCharset(),
|
||||
];
|
||||
$this->db->perform($sql, $values);
|
||||
$insertId = $this->db->lastInsertId();
|
||||
if ($insertId === 0) {
|
||||
throw new RuntimeException('Import template could not be created.');
|
||||
}
|
||||
|
||||
return $insertId;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user