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

FlushQueueTaskAdditionalFieldProvider   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 63
rs 10
c 0
b 0
f 0
wmc 9
lcom 0
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
C getAdditionalFields() 0 28 7
A validateAdditionalFields() 0 4 1
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\Scheduler\AdditionalFieldProviderInterface;
29
use TYPO3\CMS\Scheduler\Controller\SchedulerModuleController;
30
use TYPO3\CMS\Scheduler\Task\AbstractTask;
31
32
/**
33
 * Class FlushQueueTaskAdditionalFieldProvider
34
 *
35
 * @package AOE\Crawler\Task
36
 * @codeCoverageIgnore
37
 */
38
class FlushQueueTaskAdditionalFieldProvider implements AdditionalFieldProviderInterface
39
{
40
    /**
41
     * Gets additional fields to render in the form to add/edit a task
42
     *
43
     * @param array $taskInfo
44
     * @param AbstractTask $task
45
     * @param SchedulerModuleController $schedulerModule
46
     * @return array
47
     */
48
    public function getAdditionalFields(array &$taskInfo, $task, SchedulerModuleController $schedulerModule)
49
    {
50
        $additionalFields = [];
51
        // Initialize extra field value
52
        if (empty($taskInfo['mode'])) {
53
            if ($schedulerModule->CMD == 'add') {
54
                $taskInfo['mode'] = 'finished';
55
            } elseif ($schedulerModule->CMD == 'edit') {
56
                $taskInfo['mode'] = $task->mode;
0 ignored issues
show
Bug introduced by
The property mode 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...
57
            } else {
58
                $taskInfo['mode'] = $task->mode;
59
            }
60
        }
61
62
        $fieldId = 'mode';
63
        $fieldCode = '<select name="tx_scheduler[mode]" id="' . $fieldId . '" value="' . htmlentities($taskInfo['mode']) . '" class="form-control">'
64
            . '<option value="all"' . ($taskInfo['mode'] == 'all' ? ' selected="selected"' : '') . '>' . $GLOBALS['LANG']->sL('LLL:EXT:crawler/Resources/Private/Language/Backend.xlf:crawler_flush.modeAll') . '</option>'
65
            . '<option value="finished"' . ($taskInfo['mode'] == 'finished' ? ' selected="selected"' : '') . '>' . $GLOBALS['LANG']->sL('LLL:EXT:crawler/Resources/Private/Language/Backend.xlf:crawler_flush.modeFinished') . '</option>'
66
            . '<option value="pending"' . ($taskInfo['mode'] == 'pending' ? ' selected="selected"' : '') . '>' . $GLOBALS['LANG']->sL('LLL:EXT:crawler/Resources/Private/Language/Backend.xlf:crawler_flush.modePending') . '</option>'
67
            . '</select>';
68
69
        $additionalFields[$fieldId] = [
70
            'code' => $fieldCode,
71
            'label' => 'LLL:EXT:crawler/Resources/Private/Language/Backend.xlf:crawler_flush.mode'
72
        ];
73
74
        return $additionalFields;
75
    }
76
77
    /**
78
     * Validates the additional fields' values
79
     *
80
     * @param array $submittedData
81
     * @param SchedulerModuleController $schedulerModule
82
     * @return bool
83
     */
84
    public function validateAdditionalFields(array &$submittedData, SchedulerModuleController $schedulerModule)
85
    {
86
        return in_array($submittedData['mode'], ['all', 'pending', 'finished']);
87
    }
88
89
    /**
90
     * Takes care of saving the additional fields' values in the task's object
91
     *
92
     * @param array $submittedData
93
     * @param AbstractTask $task
94
     * @return void
95
     */
96
    public function saveAdditionalFields(array $submittedData, AbstractTask $task)
97
    {
98
        $task->mode = $submittedData['mode'];
0 ignored issues
show
Bug introduced by
The property mode 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...
99
    }
100
}
101