[TASK] Re-work/simplify copyright header in PHP files - Part 9
[Packages/TYPO3.CMS.git] / typo3 / sysext / scheduler / Classes / Task / FileStorageIndexingAdditionalFieldProvider.php
1 <?php
2 namespace TYPO3\CMS\Scheduler\Task;
3
4 /**
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * Additional BE fields for tasks which indexes files in a storage
19 *
20 */
21 class FileStorageIndexingAdditionalFieldProvider implements \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface {
22
23 /**
24 * Add additional fields
25 *
26 * @param array $taskInfo Reference to the array containing the info used in the add/edit form
27 * @param object $task When editing, reference to the current task object. Null when adding.
28 * @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject Reference to the calling object (Scheduler's BE module)
29 * @return array Array containing all the information pertaining to the additional fields
30 * @throws \InvalidArgumentException
31 */
32 public function getAdditionalFields(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject) {
33 if ($task !== NULL && !$task instanceof FileStorageIndexingTask) {
34 throw new \InvalidArgumentException('Task not of type FileStorageExtractionTask', 1384275696);
35 }
36 $additionalFields['scheduler_fileStorageIndexing_storage'] = $this->getAllStoragesField($task);
37 return $additionalFields;
38 }
39
40 /**
41 * Add a select field of available storages.
42 *
43 * @param FileStorageIndexingTask $task When editing, reference to the current task object. NULL when adding.
44 * @return array Array containing all the information pertaining to the additional fields
45 */
46 protected function getAllStoragesField(FileStorageIndexingTask $task = NULL) {
47 /** @var \TYPO3\CMS\Core\Resource\ResourceStorage[] $storages */
48 $storages = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Core\Resource\StorageRepository')->findAll();
49 $options = array();
50 foreach ($storages as $storage) {
51 if ($task != NULL && $task->storageUid === $storage->getUid()) {
52 $options[] = '<option value="' . $storage->getUid() . '" selected="selected">' . $storage->getName() . '</option>';
53 } else {
54 $options[] = '<option value="' . $storage->getUid() . '">' . $storage->getName() . '</option>';
55 }
56 }
57
58 $fieldName = 'tx_scheduler[scheduler_fileStorageIndexing_storage]';
59 $fieldId = 'scheduler_fileStorageIndexing_storage';
60 $fieldHtml = '<select name="' . $fieldName . '" id="' . $fieldId . '">' . implode("\n", $options) . '</select>';
61
62 $fieldConfiguration = array(
63 'code' => $fieldHtml,
64 'label' => 'LLL:EXT:scheduler/mod1/locallang.xlf:label.fileStorageIndexing.storage',
65 'cshKey' => '_MOD_system_txschedulerM1',
66 'cshLabel' => $fieldId
67 );
68 return $fieldConfiguration;
69 }
70
71 /**
72 * Validate additional fields
73 *
74 * @param array $submittedData Reference to the array containing the data submitted by the user
75 * @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject Reference to the calling object (Scheduler's BE module)
76 * @return boolean True if validation was ok (or selected class is not relevant), false otherwise
77 */
78 public function validateAdditionalFields(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject) {
79 $value = $submittedData['scheduler_fileStorageIndexing_storage'];
80 if (!\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($value)) {
81 return FALSE;
82 } elseif(\TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getStorageObject($submittedData['scheduler_fileStorageIndexing_storage']) !== NULL) {
83 return TRUE;
84 }
85 return FALSE;
86 }
87
88 /**
89 * Save additional field in task
90 *
91 * @param array $submittedData Contains data submitted by the user
92 * @param \TYPO3\CMS\Scheduler\Task\AbstractTask $task Reference to the current task object
93 * @return void
94 * @throws \InvalidArgumentException
95 */
96 public function saveAdditionalFields(array $submittedData, \TYPO3\CMS\Scheduler\Task\AbstractTask $task) {
97 if (!$task instanceof FileStorageIndexingTask) {
98 throw new \InvalidArgumentException('Task not of type FileStorageExtractionTask', 1384275697);
99 }
100 $task->storageUid = (int)$submittedData['scheduler_fileStorageIndexing_storage'];
101 }
102
103 }