forked from cbdb-project/cbdb-online-main-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextCreateHandler.php
More file actions
59 lines (47 loc) · 1.55 KB
/
Copy pathTextCreateHandler.php
File metadata and controls
59 lines (47 loc) · 1.55 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
<?php
namespace App\Services\Mutations;
use App\Repositories\OperationRepository;
use App\Services\AuditLogService;
class TextCreateHandler extends AbstractPersonSubresourceCreateHandler {
public function __construct(
OperationRepository $operationRepository,
AuditLogService $auditLogService
) {
parent::__construct($operationRepository, $auditLogService);
}
protected function resourceName(): string {
return 'texts';
}
protected function tableName(): string {
return 'BIOG_TEXT_DATA';
}
protected function displayName(): string {
return '著述';
}
protected function resourceAliases(): array {
return ['texts', 'text', 'biog_text_data', 'text_data'];
}
protected function keyColumns(): array {
return ['c_personid', 'c_textid', 'c_role_id'];
}
protected function allowedFields(): array {
return [
'c_personid',
'c_textid',
'c_role_id',
'c_source',
'c_pages',
'c_notes',
];
}
protected function preprocessCreateData(array $data): array {
$data = $this->normalizeSentinelValues($data, ['c_textid', 'c_source']);
// 對齊 legacy emptyToSentinel:著述/出處清空時正規化為 '0'(不可 NULL)。
foreach (['c_textid', 'c_source'] as $f) {
if (array_key_exists($f, $data) && ($data[$f] === null || $data[$f] === '')) {
$data[$f] = '0';
}
}
return $data;
}
}