Completed
Branch master (b7ffcb)
by Tomas Norre
17:57
created

CrawlMultiProcessTaskAdditionalFieldProvider   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 67
rs 10
c 0
b 0
f 0
wmc 7
lcom 0
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
B getAdditionalFields() 0 24 4
A validateAdditionalFields() 0 12 2
A saveAdditionalFields() 0 4 1
1
<?php
2
namespace AOE\Crawler\Task;
3
4
/***************************************************************
5
 *  Copyright notice
6
 *
7
 *  (c) 2016 AOE GmbH <[email protected]>
8
 *
9
 *  All rights reserved
10
 *
11
 *  This script is part of the TYPO3 project. The TYPO3 project is
12
 *  free software; you can redistribute it and/or modify
13
 *  it under the terms of the GNU General Public License as published by
14
 *  the Free Software Foundation; either version 3 of the License, or
15
 *  (at your option) any later version.
16
 *
17
 *  The GNU General Public License can be found at
18
 *  http://www.gnu.org/copyleft/gpl.html.
19
 *
20
 *  This script is distributed in the hope that it will be useful,
21
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 *  GNU General Public License for more details.
24
 *
25
 *  This copyright notice MUST APPEAR in all copies of the script!
26
 ***************************************************************/
27
28
use TYPO3\CMS\Core\Messaging\FlashMessage;
29
use TYPO3\CMS\Core\Utility\MathUtility;
30
use TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface;
31
use TYPO3\CMS\Scheduler\Controller\SchedulerModuleController;
32
use TYPO3\CMS\Scheduler\Task\AbstractTask;
33
34
/**
35
 * Class CrawlMultiProcessTaskAdditionalFieldProvider
36
 *
37
 * @package AOE\Crawler\Task
38
 * @codeCoverageIgnore
39
 */
40
class CrawlMultiProcessTaskAdditionalFieldProvider implements AdditionalFieldProviderInterface
41
{
42
    /**
43
     * Gets additional fields to render in the form to add/edit a task
44
     *
45
     * @param array $taskInfo
46
     * @param AbstractTask $task
47
     * @param SchedulerModuleController $schedulerModule
48
     * @return array
49
     */
50
    public function getAdditionalFields(array &$taskInfo, $task, SchedulerModuleController $schedulerModule)
51
    {
52
        $additionalFields = [];
53
54
        if (empty($taskInfo['timeOut'])) {
55
            if ($schedulerModule->CMD == 'add') {
56
                $taskInfo['timeOut'] = 10000;
57
            } elseif ($schedulerModule->CMD == 'edit') {
58
                $taskInfo['timeOut'] = $task->timeOut;
0 ignored issues
show
Bug introduced by
The property timeOut does not seem to exist in TYPO3\CMS\Scheduler\Task\AbstractTask.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
59
            } else {
60
                $taskInfo['timeOut'] = $task->timeOut;
61
            }
62
        }
63
64
        // input for timeOut
65
        $fieldId = 'task_timeOut';
66
        $fieldCode = '<input type="text" name="tx_scheduler[timeOut]" id="' . $fieldId . '" value="' . htmlentities($taskInfo['timeOut']) . '" class="form-control" />';
67
        $additionalFields[$fieldId] = [
68
            'code' => $fieldCode,
69
            'label' => 'LLL:EXT:crawler/Resources/Private/Language/Backend.xlf:crawler_im.timeOut'
70
        ];
71
72
        return $additionalFields;
73
    }
74
75
    /**
76
     * Validates the additional fields' values
77
     *
78
     * @param array $submittedData
79
     * @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $schedulerModule
80
     * @return bool
81
     */
82
    public function validateAdditionalFields(array &$submittedData, SchedulerModuleController $schedulerModule)
83
    {
84
        $isValid = false;
85
86
        if (MathUtility::convertToPositiveInteger($submittedData['timeOut']) > 0) {
87
            $isValid = true;
88
        } else {
89
            $schedulerModule->addMessage($GLOBALS['LANG']->sL('LLL:EXT:crawler/Resources/Private/Language/Backend.xlf:crawler_im.invalidTimeOut'), FlashMessage::ERROR);
90
        }
91
92
        return $isValid;
93
    }
94
95
    /**
96
     * Takes care of saving the additional fields' values in the task's object
97
     *
98
     * @param array $submittedData
99
     * @param AbstractTask $task
100
     * @return void
101
     */
102
    public function saveAdditionalFields(array $submittedData, AbstractTask $task)
103
    {
104
        $task->timeOut = intval($submittedData['timeOut']);
0 ignored issues
show
Bug introduced by
The property timeOut does not seem to exist in TYPO3\CMS\Scheduler\Task\AbstractTask.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
105
    }
106
}
107