-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserDataLoader.php
More file actions
69 lines (57 loc) · 1.85 KB
/
Copy pathUserDataLoader.php
File metadata and controls
69 lines (57 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
namespace Fab\Formule\Loader;
/*
* This file is part of the Fab/Formule project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use Fab\Formule\Service\TemplateService;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Class UserDataLoader
* Only an example class to be copy / pasted and adjusted!!!
*/
class UserDataLoader extends AbstractLoader
{
/**
* @param array $values
* @return array
*/
public function load(array $values): array
{
$identifierField = $this->getTemplateService()->getIdentifierField();
$identifierValue = $GLOBALS['TYPO3_REQUEST']->getParsedBody()[$identifierField] ?? $GLOBALS['TYPO3_REQUEST']->getQueryParams()[$identifierField] ?? null;
$tableName = $this->getTemplateService()->getPersistingTableName();
/** @var QueryBuilder $query */
$query = $this->getQueryBuilder($tableName);
$query->select('*')
->from($tableName)
->where(
$query->expr()->eq(
$identifierField,
$query->expr()->literal($identifierValue)
)
);
$record = $query
->executeQuery()
->fetchAssociative();
$fields = $this->getTemplateService()->getFields();
// is mapping necessary here?
foreach ($fields as $field) {
if (isset($record[$field])) {
$values[$field] = $record[$field];
}
}
$values['uid'] = $record['uid'];
return $values;
}
/**
* @return TemplateService|object
*/
protected function getTemplateService()
{
return GeneralUtility::makeInstance(TemplateService::class);
}
}