TYPO3 CMS  TYPO3_6-2
FileStorageExtractionAdditionalFieldProvider.php
Go to the documentation of this file.
1 <?php
3 
25 
31 
41  public function getAdditionalFields(array &$taskInfo, $task, SchedulerModuleController $parentObject) {
42  if ($task !== NULL && !$task instanceof FileStorageExtractionTask) {
43  throw new \InvalidArgumentException('Task not of type FileStorageExtractionTask', 1384275695);
44  }
45  $additionalFields['scheduler_fileStorageIndexing_storage'] = $this->getAllStoragesField($task);
46  $additionalFields['scheduler_fileStorageIndexing_fileCount'] = $this->getFileCountField($task);
47  $additionalFields['scheduler_fileStorageIndexing_registeredExtractors'] = $this->getRegisteredExtractorsField($task);
48  return $additionalFields;
49  }
50 
57  protected function getAllStoragesField(FileStorageExtractionTask $task = NULL) {
59  $storages = GeneralUtility::makeInstance('TYPO3\CMS\Core\Resource\StorageRepository')->findAll();
60  $options = array();
61  foreach ($storages as $storage) {
62  if ($task !== NULL && $task->storageUid === $storage->getUid()) {
63  $options[] = '<option value="' . $storage->getUid() . '" selected="selected">' . $storage->getName() . '</option>';
64  } else {
65  $options[] = '<option value="' . $storage->getUid() . '">' . $storage->getName() . '</option>';
66  }
67  }
68 
69  $fieldName = 'tx_scheduler[scheduler_fileStorageIndexing_storage]';
70  $fieldId = 'scheduler_fileStorageIndexing_storage';
71  $fieldHtml = '<select name="' . $fieldName . '" id="' . $fieldId . '">' . implode("\n", $options) . '</select>';
72 
73  $fieldConfiguration = array(
74  'code' => $fieldHtml,
75  'label' => 'LLL:EXT:scheduler/mod1/locallang.xlf:label.fileStorageIndexing.storage',
76  'cshKey' => '_MOD_system_txschedulerM1',
77  'cshLabel' => $fieldId
78  );
79  return $fieldConfiguration;
80  }
81 
88  protected function getFileCountField(FileStorageExtractionTask $task = NULL) {
89  $fieldName = 'tx_scheduler[scheduler_fileStorageIndexing_fileCount]';
90  $fieldId = 'scheduler_fileStorageIndexing_fileCount';
91  $fieldValue = $task !== NULL ? (int)$task->maxFileCount : 100;
92  $fieldHtml = '<input type="text" name="' . $fieldName . '" id="' . $fieldId . '" value="' . htmlspecialchars($fieldValue) . '" />';
93 
94  $fieldConfiguration = array(
95  'code' => $fieldHtml,
96  'label' => 'LLL:EXT:scheduler/mod1/locallang.xlf:label.fileStorageExtraction.fileCount',
97  'cshKey' => '_MOD_system_txschedulerM1',
98  'cshLabel' => $fieldId
99  );
100  return $fieldConfiguration;
101  }
102 
109  protected function getRegisteredExtractorsField(FileStorageExtractionTask $task = NULL) {
110  $extractors = ExtractorRegistry::getInstance()->getExtractors();
111 
112  if (empty($extractors)) {
113  $labelKey = 'LLL:EXT:scheduler/mod1/locallang.xlf:label.fileStorageExtraction.registeredExtractors.without_extractors';
115  $flashMessage = GeneralUtility::makeInstance(
116  'TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
117  $this->getLanguageService()->sL($labelKey),
118  '',
120  );
121  $content = $flashMessage->render();
122  } else {
123  // Assemble the extractor bullet list first.
124  $labelKey = 'LLL:EXT:scheduler/mod1/locallang.xlf:label.fileStorageExtraction.registeredExtractors.extractor';
125  $bullets = array();
126  foreach ($extractors as $extractor) {
127  $bullets[] = sprintf(
128  '<li title="%s">%s</li>',
129  get_class($extractor),
130  sprintf($this->getLanguageService()->sL($labelKey), $this->formatExtractorClassName($extractor), $extractor->getPriority())
131  );
132  }
133 
134  // Finalize content assembling.
135  $labelKey = 'LLL:EXT:scheduler/mod1/locallang.xlf:label.fileStorageExtraction.registeredExtractors.with_extractors';
137  $flashMessage = GeneralUtility::makeInstance(
138  'TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
139  '<ul>' . implode(LF, $bullets) . '</ul>',
140  $this->getLanguageService()->sL($labelKey),
142  );
143  $content = $flashMessage->render();
144  }
145 
146  $fieldConfiguration = array(
147  'code' => $content,
148  'label' => 'LLL:EXT:scheduler/mod1/locallang.xlf:label.fileStorageExtraction.registeredExtractors',
149  'cshKey' => '_MOD_system_txschedulerM1',
150  'cshLabel' => 'scheduler_fileStorageIndexing_registeredExtractors'
151  );
152  return $fieldConfiguration;
153  }
154 
162  public function validateAdditionalFields(array &$submittedData, SchedulerModuleController $parentObject) {
163  if (!MathUtility::canBeInterpretedAsInteger($submittedData['scheduler_fileStorageIndexing_storage']) ||
164  !MathUtility::canBeInterpretedAsInteger($submittedData['scheduler_fileStorageIndexing_fileCount'])) {
165  return FALSE;
166  } elseif (ResourceFactory::getInstance()->getStorageObject($submittedData['scheduler_fileStorageIndexing_storage']) === NULL) {
167  return FALSE;
168  } elseif (!MathUtility::isIntegerInRange($submittedData['scheduler_fileStorageIndexing_fileCount'], 1, 9999)) {
169  return FALSE;
170  }
171  return TRUE;
172  }
173 
182  public function saveAdditionalFields(array $submittedData, \TYPO3\CMS\Scheduler\Task\AbstractTask $task) {
183  if ($task !== NULL && !$task instanceof FileStorageExtractionTask) {
184  throw new \InvalidArgumentException('Task not of type FileStorageExtractionTask', 1384275698);
185  }
186  $task->storageUid = (int)$submittedData['scheduler_fileStorageIndexing_storage'];
187  $task->maxFileCount = (int)$submittedData['scheduler_fileStorageIndexing_fileCount'];
188  }
189 
197  protected function formatExtractorClassName(ExtractorInterface $extractor) {
198  $extractorParts = explode('\\', get_class($extractor));
199  return array_pop($extractorParts);
200  }
201 
205  protected function getLanguageService() {
206  return $GLOBALS['LANG'];
207  }
208 }
saveAdditionalFields(array $submittedData, \TYPO3\CMS\Scheduler\Task\AbstractTask $task)
getAdditionalFields(array &$taskInfo, $task, SchedulerModuleController $parentObject)
validateAdditionalFields(array &$submittedData, SchedulerModuleController $parentObject)
static isIntegerInRange($value, $minimum, $maximum)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]