[TASK] Remove compat layer for new 6.0 classes
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Resource / Service / UserFileMountService.php
1 <?php
2 namespace TYPO3\CMS\Core\Resource\Service;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2011 Benjamin Mack <benni@typo3.org>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29 /**
30 * Service class for implementing the user filemounts,
31 * used for BE_USER (t3lib_beUserAuth) and TCEforms hooks
32 *
33 * Note: This is now also used by sys_file_category table (fieldname "folder")! (Ingmar Schlecht, 19 November 2011)
34 *
35 * @author Benjamin Mack <benni@typo3.org>
36 * @package TYPO3
37 * @subpackage t3lib
38 */
39 class UserFileMountService {
40
41 /**
42 * User function for sys_filemounts (the userfilemounts)
43 * to render a dropdown for selecting a folder
44 * of a selected mount
45 *
46 * @param array $PA the array with additional configuration options.
47 * @param t3lib_tceforms $tceformsObj the TCEforms parent object
48 * @return string The HTML code for the TCEform field
49 */
50 public function renderTceformsSelectDropdown(&$PA, &$tceformsObj) {
51 // If working for sys_filemounts table
52 $storageUid = intval($PA['row']['base']);
53 if (!$storageUid) {
54 // If working for sys_file_collection table
55 $storageUid = intval($PA['row']['storage']);
56 }
57 if ($storageUid > 0) {
58 /** @var $storageRepository \TYPO3\CMS\Core\Resource\StorageRepository */
59 $storageRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\StorageRepository');
60 /** @var $storage \TYPO3\CMS\Core\Resource\ResourceStorage */
61 $storage = $storageRepository->findByUid($storageUid);
62 $rootLevelFolder = $storage->getRootLevelFolder();
63 $folderItems = $this->getSubfoldersForOptionList($rootLevelFolder);
64 foreach ($folderItems as $item) {
65 $PA['items'][] = array(
66 htmlspecialchars($item->getIdentifier()),
67 htmlspecialchars($item->getIdentifier())
68 );
69 }
70 } else {
71 $PA['items'][] = array('', 'Please choose a FAL mount from above first.');
72 }
73 }
74
75 /**
76 * Simple function to make a hierarchical subfolder request into
77 * a "flat" option list
78 *
79 * @param \TYPO3\CMS\Core\Resource\Folder $parentFolder
80 * @param integer $level a limiter
81 * @return \TYPO3\CMS\Core\Resource\Folder[]
82 */
83 protected function getSubfoldersForOptionList(\TYPO3\CMS\Core\Resource\Folder $parentFolder, $level = 0) {
84 $level++;
85 // hard break on recursion
86 if ($level > 99) {
87 return array();
88 }
89 $allFolderItems = array($parentFolder);
90 $subFolders = $parentFolder->getSubfolders();
91 foreach ($subFolders as $subFolder) {
92 $subFolderItems = $this->getSubfoldersForOptionList($subFolder, $level);
93 $allFolderItems = array_merge($allFolderItems, $subFolderItems);
94 }
95 return $allFolderItems;
96 }
97
98 }
99
100
101 ?>