1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Extension "sf_event_mgt" for TYPO3 CMS. |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please read the |
9
|
|
|
* LICENSE.txt file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace DERHANSEN\SfEventMgt\ViewHelpers\Category; |
13
|
|
|
|
14
|
|
|
use TYPO3\CMS\Core\Context\Context; |
15
|
|
|
use TYPO3\CMS\Core\Database\Connection; |
16
|
|
|
use TYPO3\CMS\Core\Database\ConnectionPool; |
17
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
18
|
|
|
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; |
19
|
|
|
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; |
20
|
|
|
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic; |
21
|
|
|
use TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperInterface; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Get usage count |
25
|
|
|
* |
26
|
|
|
* Example usage |
27
|
|
|
* {e:category.count(categoryUid:category.item.uid) -> f:variable(name: 'categoryUsageCount')} |
28
|
|
|
* {categoryUsageCount} |
29
|
|
|
*/ |
30
|
|
|
class CountViewHelper extends AbstractViewHelper implements ViewHelperInterface |
31
|
|
|
{ |
32
|
|
|
use CompileWithRenderStatic; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Initialize arguments |
36
|
|
|
*/ |
37
|
|
|
public function initializeArguments() |
38
|
|
|
{ |
39
|
|
|
parent::initializeArguments(); |
40
|
|
|
$this->registerArgument('categoryUid', 'int', 'Uid of the category', true); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param array $arguments |
45
|
|
|
* @param \Closure $renderChildrenClosure |
46
|
|
|
* @param RenderingContextInterface $renderingContext |
47
|
|
|
* @return int |
48
|
|
|
*/ |
49
|
|
|
public static function renderStatic( |
50
|
|
|
array $arguments, |
51
|
|
|
\Closure $renderChildrenClosure, |
52
|
|
|
RenderingContextInterface $renderingContext |
53
|
|
|
): int { |
54
|
|
|
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
55
|
|
|
->getQueryBuilderForTable('tx_sfeventmgt_domain_model_event'); |
56
|
|
|
|
57
|
|
|
$categoryUid = $arguments['categoryUid']; |
58
|
|
|
$languageUid = GeneralUtility::makeInstance(Context::class)->getAspect('language')->getId(); |
59
|
|
|
|
60
|
|
|
$count = $queryBuilder |
61
|
|
|
->count('tx_sfeventmgt_domain_model_event.title') |
62
|
|
|
->from('tx_sfeventmgt_domain_model_event') |
63
|
|
|
->rightJoin( |
64
|
|
|
'tx_sfeventmgt_domain_model_event', |
65
|
|
|
'sys_category_record_mm', |
66
|
|
|
'sys_category_record_mm', |
67
|
|
|
$queryBuilder->expr()->eq('tx_sfeventmgt_domain_model_event.uid', $queryBuilder->quoteIdentifier('sys_category_record_mm.uid_foreign')) |
68
|
|
|
) |
69
|
|
|
->rightJoin( |
70
|
|
|
'sys_category_record_mm', |
71
|
|
|
'sys_category', |
72
|
|
|
'sys_category', |
73
|
|
|
$queryBuilder->expr()->eq('sys_category.uid', $queryBuilder->quoteIdentifier('sys_category_record_mm.uid_local')) |
74
|
|
|
) |
75
|
|
|
->where( |
76
|
|
|
$queryBuilder->expr()->andX( |
77
|
|
|
$queryBuilder->expr()->eq( |
78
|
|
|
'sys_category.uid', |
79
|
|
|
$queryBuilder->createNamedParameter($categoryUid, \PDO::PARAM_INT) |
80
|
|
|
), |
81
|
|
|
$queryBuilder->expr()->eq( |
82
|
|
|
'sys_category_record_mm.tablenames', |
83
|
|
|
$queryBuilder->createNamedParameter('tx_sfeventmgt_domain_model_event', \PDO::PARAM_STR) |
84
|
|
|
), |
85
|
|
|
$queryBuilder->expr()->eq( |
86
|
|
|
'sys_category_record_mm.fieldname', |
87
|
|
|
$queryBuilder->createNamedParameter('category', \PDO::PARAM_STR) |
88
|
|
|
), |
89
|
|
|
$queryBuilder->expr()->in( |
90
|
|
|
'tx_sfeventmgt_domain_model_event.sys_language_uid', |
91
|
|
|
$queryBuilder->createNamedParameter([-1, $languageUid], Connection::PARAM_INT_ARRAY) |
92
|
|
|
) |
93
|
|
|
) |
94
|
|
|
) |
95
|
|
|
->execute() |
96
|
|
|
->fetchColumn(0); |
97
|
|
|
|
98
|
|
|
return $count; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|