|
1
|
|
|
<?php |
|
2
|
|
|
namespace DERHANSEN\SfEventMgt\Service; |
|
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
|
|
|
* CategoryService |
|
19
|
|
|
* |
|
20
|
|
|
* @author Georg Ringer <[email protected]> |
|
21
|
|
|
* @author Torben Hansen <[email protected]> |
|
22
|
|
|
*/ |
|
23
|
|
|
class CategoryService |
|
24
|
|
|
{ |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Returns the given categories including their subcategories |
|
28
|
|
|
* |
|
29
|
|
|
* @param string $categories |
|
30
|
|
|
* @return string |
|
31
|
|
|
*/ |
|
32
|
|
|
public static function getCategoryListWithChilds($categories) |
|
33
|
|
|
{ |
|
34
|
|
|
return self::getChildrenCategoriesRecursive($categories); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Get child categories |
|
39
|
|
|
* |
|
40
|
|
|
* @param string $categoryList list of category ids to start |
|
41
|
|
|
* @param int $counter |
|
42
|
|
|
* @return string comma separated list of category ids |
|
43
|
|
|
*/ |
|
44
|
|
|
private function getChildrenCategoriesRecursive($categoryList, $counter = 0) |
|
45
|
|
|
{ |
|
46
|
|
|
$result = []; |
|
47
|
|
|
|
|
48
|
|
|
// add idlist to the output too |
|
49
|
|
|
if ($counter === 0) { |
|
50
|
|
|
$result[] = $GLOBALS['TYPO3_DB']->cleanIntList($categoryList); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery( |
|
54
|
|
|
'uid', |
|
55
|
|
|
'sys_category', |
|
56
|
|
|
'sys_category.parent IN (' . $GLOBALS['TYPO3_DB']->cleanIntList($categoryList) . ') AND deleted=0' |
|
57
|
|
|
); |
|
58
|
|
|
|
|
59
|
|
|
while (($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))) { |
|
60
|
|
|
$counter++; |
|
61
|
|
|
if ($counter > 10000) { |
|
62
|
|
|
$GLOBALS['TT']->setTSlogMessage('EXT:sf_event_mgt: one or more recursive categories where found'); |
|
63
|
|
|
return implode(',', $result); |
|
64
|
|
|
} |
|
65
|
|
|
$subcategories = self::getChildrenCategoriesRecursive($row['uid'], $counter); |
|
66
|
|
|
$result[] = $row['uid'] . ($subcategories ? ',' . $subcategories : ''); |
|
67
|
|
|
} |
|
68
|
|
|
$GLOBALS['TYPO3_DB']->sql_free_result($res); |
|
69
|
|
|
|
|
70
|
|
|
$result = implode(',', $result); |
|
71
|
|
|
return $result; |
|
72
|
|
|
} |
|
73
|
|
|
} |