Passed
Pull Request — master (#123)
by
unknown
04:18
created

IndexAdditionalFieldProvider   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 28
c 1
b 0
f 0
dl 0
loc 55
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A getAdditionalFields() 0 45 2
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\Scheduler\Controller\SchedulerModuleController;
15
use TYPO3\CMS\Scheduler\Task\AbstractTask;
16
use TYPO3\CMS\Scheduler\Task\Enumeration\Action;
17
18
/**
19
 * Additional fields for index document task.
20
 *
21
 * @package TYPO3
22
 * @subpackage dlf
23
 *
24
 * @access public
25
 */
26
class IndexAdditionalFieldProvider extends BaseAdditionalFieldProvider
27
{
28
    /**
29
     * Gets additional fields to render in the form to add/edit a task
30
     *
31
     * @param array $taskInfo Values of the fields from the add/edit task form
32
     * @param BaseTask $task The task object being edited. Null when adding a task!
33
     * @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $schedulerModule Reference to the scheduler backend module
34
     * @return array A two dimensional array, array('Identifier' => array('fieldId' => array('code' => '', 'label' => '', 'cshKey' => '', 'cshLabel' => ''))
35
     */
36
    public function getAdditionalFields(array &$taskInfo, $task, SchedulerModuleController $schedulerModule)
37
    {
38
        $currentSchedulerModuleAction = $schedulerModule->getCurrentAction();
39
40
        /** @var BaseTask $task */
41
        if ($currentSchedulerModuleAction->equals(Action::EDIT)) {
42
            $taskInfo['dryRun'] = $task->isDryRun();
43
            $taskInfo['doc'] = $task->getDoc();
44
            $taskInfo['pid'] = $task->getPid();
45
            $taskInfo['solr'] = $task->getSolr();
46
            $taskInfo['owner'] = $task->getOwner();
47
        } else {
48
            $taskInfo['dryRun'] = false;
49
            $taskInfo['doc'] = 'https://';
50
            $taskInfo['pid'] = - 1;
51
            $taskInfo['solr'] = - 1;
52
            $taskInfo['owner'] = '';
53
        }
54
55
        $additionalFields = [];
56
57
        // Checkbox for dry-run
58
        $additionalFields['dryRun'] = $this->getDryRunField($taskInfo['dryRun']);
59
60
        // Text field for document URL
61
        $fieldName = 'doc';
62
        $fieldId = 'task_' . $fieldName;
63
        $fieldHtml = '<input type="text" name="tx_scheduler[' . $fieldName . ']" id="' . $fieldId . '" value="' . $taskInfo[$fieldName] . '" >';
64
        $additionalFields[$fieldId] = [
65
            'code' => $fieldHtml,
66
            'label' => 'LLL:EXT:dlf/Resources/Private/Language/locallang_tasks.xlf:additionalFields.doc',
67
            'cshKey' => '_MOD_system_txschedulerM1',
68
            'cshLabel' => $fieldId
69
        ];
70
71
        // DropDown for storage page
72
        $additionalFields['pid'] = $this->getPidField($taskInfo['pid']);
73
74
        // DropDown for Solr core
75
        $additionalFields['solr'] = $this->getSolrField($taskInfo['solr'], $taskInfo['pid']);
76
77
        // Text field for owner
78
        $additionalFields['owner'] = $this->getOwnerField($taskInfo['owner']);
79
80
        return $additionalFields;
81
    }
82
}
83