|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* (c) Kitodo. Key to digital objects e.V. <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* This file is part of the Kitodo and TYPO3 projects. |
|
7
|
|
|
* |
|
8
|
|
|
* @license GNU General Public License version 3 or later. |
|
9
|
|
|
* For the full copyright and license information, please read the |
|
10
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
11
|
|
|
*/ |
|
12
|
|
|
namespace Kitodo\Dlf\Task; |
|
13
|
|
|
|
|
14
|
|
|
use TYPO3\CMS\Core\Database\Connection; |
|
15
|
|
|
use TYPO3\CMS\Core\Database\ConnectionPool; |
|
16
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
17
|
|
|
use TYPO3\CMS\Scheduler\Controller\SchedulerModuleController; |
|
18
|
|
|
use TYPO3\CMS\Scheduler\Task\Enumeration\Action; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Additional fields for harvest documents task. |
|
22
|
|
|
* |
|
23
|
|
|
* @package TYPO3 |
|
24
|
|
|
* @subpackage dlf |
|
25
|
|
|
* |
|
26
|
|
|
* @access public |
|
27
|
|
|
*/ |
|
28
|
|
|
class HarvestAdditionalFieldProvider extends BaseAdditionalFieldProvider |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* Gets additional fields to render in the form to add/edit a task |
|
32
|
|
|
* |
|
33
|
|
|
* @param array $taskInfo Values of the fields from the add/edit task form |
|
34
|
|
|
* @param BaseTask $task The task object being edited. Null when adding a task! |
|
35
|
|
|
* @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $schedulerModule Reference to the scheduler backend module |
|
36
|
|
|
* @return array A two dimensional array, array('Identifier' => array('fieldId' => array('code' => '', 'label' => '', 'cshKey' => '', 'cshLabel' => '')) |
|
37
|
|
|
*/ |
|
38
|
|
|
public function getAdditionalFields(array &$taskInfo, $task, SchedulerModuleController $schedulerModule) |
|
39
|
|
|
{ |
|
40
|
|
|
$currentSchedulerModuleAction = $schedulerModule->getCurrentAction(); |
|
41
|
|
|
|
|
42
|
|
|
/** @var BaseTask $task */ |
|
43
|
|
|
if ($currentSchedulerModuleAction->equals(Action::EDIT)) { |
|
44
|
|
|
$taskInfo['dryRun'] = $task->isDryRun(); |
|
45
|
|
|
$taskInfo['lib'] = $task->getLib(); |
|
46
|
|
|
$taskInfo['pid'] = $task->getPid(); |
|
47
|
|
|
$taskInfo['solr'] = $task->getSolr(); |
|
48
|
|
|
$taskInfo['from'] = $task->getFrom(); |
|
49
|
|
|
$taskInfo['until'] = $task->getUntil(); |
|
50
|
|
|
$taskInfo['set'] = $task->getSet(); |
|
51
|
|
|
} else { |
|
52
|
|
|
$taskInfo['dryRun'] = false; |
|
53
|
|
|
$taskInfo['lib'] = - 1; |
|
54
|
|
|
$taskInfo['pid'] = - 1; |
|
55
|
|
|
$taskInfo['solr'] = - 1; |
|
56
|
|
|
$taskInfo['from'] = ''; |
|
57
|
|
|
$taskInfo['until'] = ''; |
|
58
|
|
|
$taskInfo['set'] = ''; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
$additionalFields = []; |
|
62
|
|
|
|
|
63
|
|
|
// Checkbox for dry-run |
|
64
|
|
|
$additionalFields['dryRun'] = $this->getDryRunField($taskInfo['dryRun']); |
|
65
|
|
|
|
|
66
|
|
|
// Text field for library |
|
67
|
|
|
$fieldName = 'lib'; |
|
68
|
|
|
$fieldId = 'task_' . $fieldName; |
|
69
|
|
|
|
|
70
|
|
|
$allLibraries = $this->getLibraries($taskInfo['pid']); |
|
71
|
|
|
$options = []; |
|
72
|
|
|
$options[] = '<option value="-1"></option>'; |
|
73
|
|
|
foreach ($allLibraries as $label => $uid) { |
|
74
|
|
|
$options[] = '<option value="' . $uid . '" ' . ($taskInfo['lib'] == $uid ? 'selected' : '') . ' >' . $label . '</option>'; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
$fieldHtml = '<select name="tx_scheduler[' . $fieldName . ']" id="' . $fieldId . '">' . implode("\n", $options) . '</select>'; |
|
78
|
|
|
$additionalFields[$fieldId] = [ |
|
79
|
|
|
'code' => $fieldHtml, |
|
80
|
|
|
'label' => 'LLL:EXT:dlf/Resources/Private/Language/locallang_tasks.xlf:additionalFields.lib', |
|
81
|
|
|
'cshKey' => '_MOD_system_txschedulerM1', |
|
82
|
|
|
'cshLabel' => $fieldId |
|
83
|
|
|
]; |
|
84
|
|
|
|
|
85
|
|
|
// DropDown for Pid |
|
86
|
|
|
$additionalFields['pid'] = $this->getPidField($taskInfo['pid']); |
|
87
|
|
|
|
|
88
|
|
|
// DropDown for Solr core |
|
89
|
|
|
$additionalFields['solr'] = $this->getSolrField($taskInfo['solr'], $taskInfo['pid']); |
|
90
|
|
|
|
|
91
|
|
|
// Text field for from |
|
92
|
|
|
$fieldName = 'from'; |
|
93
|
|
|
$fieldId = 'task_' . $fieldName; |
|
94
|
|
|
$fieldHtml = '<input type="date" name="tx_scheduler[' . $fieldName . ']" id="' . $fieldId . '" value="' . $taskInfo[$fieldName] . '" >'; |
|
95
|
|
|
$additionalFields[$fieldId] = [ |
|
96
|
|
|
'code' => $fieldHtml, |
|
97
|
|
|
'label' => 'LLL:EXT:dlf/Resources/Private/Language/locallang_tasks.xlf:additionalFields.from', |
|
98
|
|
|
'cshKey' => '_MOD_system_txschedulerM1', |
|
99
|
|
|
'cshLabel' => $fieldId |
|
100
|
|
|
]; |
|
101
|
|
|
|
|
102
|
|
|
// Text field for until |
|
103
|
|
|
$fieldName = 'until'; |
|
104
|
|
|
$fieldId = 'task_' . $fieldName; |
|
105
|
|
|
$fieldHtml = '<input type="date" name="tx_scheduler[' . $fieldName . ']" id="' . $fieldId . '" value="' . $taskInfo[$fieldName] . '" >'; |
|
106
|
|
|
$additionalFields[$fieldId] = [ |
|
107
|
|
|
'code' => $fieldHtml, |
|
108
|
|
|
'label' => 'LLL:EXT:dlf/Resources/Private/Language/locallang_tasks.xlf:additionalFields.until', |
|
109
|
|
|
'cshKey' => '_MOD_system_txschedulerM1', |
|
110
|
|
|
'cshLabel' => $fieldId |
|
111
|
|
|
]; |
|
112
|
|
|
|
|
113
|
|
|
// Text field for set |
|
114
|
|
|
$fieldName = 'set'; |
|
115
|
|
|
$fieldId = 'task_' . $fieldName; |
|
116
|
|
|
$fieldHtml = '<input type="text" name="tx_scheduler[' . $fieldName . ']" id="' . $fieldId . '" value="' . $taskInfo[$fieldName] . '" >'; |
|
117
|
|
|
$additionalFields[$fieldId] = [ |
|
118
|
|
|
'code' => $fieldHtml, |
|
119
|
|
|
'label' => 'LLL:EXT:dlf/Resources/Private/Language/locallang_tasks.xlf:additionalFields.set', |
|
120
|
|
|
'cshKey' => '_MOD_system_txschedulerM1', |
|
121
|
|
|
'cshLabel' => $fieldId |
|
122
|
|
|
]; |
|
123
|
|
|
|
|
124
|
|
|
return $additionalFields; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* Fetches all libraries from given page. |
|
129
|
|
|
* |
|
130
|
|
|
* @access private |
|
131
|
|
|
* |
|
132
|
|
|
* @param int $pid The UID of the storage page |
|
133
|
|
|
* |
|
134
|
|
|
* @return array Array of libraries |
|
135
|
|
|
*/ |
|
136
|
|
|
private function getLibraries(int $pid): array |
|
137
|
|
|
{ |
|
138
|
|
|
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_dlf_libraries'); |
|
139
|
|
|
|
|
140
|
|
|
$libraries = []; |
|
141
|
|
|
$result = $queryBuilder->select('uid', 'label') |
|
142
|
|
|
->from('tx_dlf_libraries') |
|
143
|
|
|
->where( |
|
144
|
|
|
$queryBuilder->expr() |
|
145
|
|
|
->eq('pid', $queryBuilder->createNamedParameter((int) $pid, Connection::PARAM_INT)) |
|
146
|
|
|
) |
|
147
|
|
|
->execute(); |
|
148
|
|
|
|
|
149
|
|
|
while ($record = $result->fetchAssociative()) { |
|
150
|
|
|
$libraries[$record['label']] = $record['uid']; |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
return $libraries; |
|
154
|
|
|
} |
|
155
|
|
|
} |
|
156
|
|
|
|