1
|
|
|
<?php |
2
|
|
|
namespace AOE\AoeIpauth\Domain\Service; |
3
|
|
|
|
4
|
|
|
/*************************************************************** |
5
|
|
|
* Copyright notice |
6
|
|
|
* |
7
|
|
|
* (c) 2019 AOE GmbH <[email protected]> |
8
|
|
|
* |
9
|
|
|
* All rights reserved |
10
|
|
|
* |
11
|
|
|
* This script is part of the TYPO3 project. The TYPO3 project is |
12
|
|
|
* free software; you can redistribute it and/or modify |
13
|
|
|
* it under the terms of the GNU General Public License as published by |
14
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
15
|
|
|
* (at your option) any later version. |
16
|
|
|
* |
17
|
|
|
* The GNU General Public License can be found at |
18
|
|
|
* http://www.gnu.org/copyleft/gpl.html. |
19
|
|
|
* |
20
|
|
|
* This script is distributed in the hope that it will be useful, |
21
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
22
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23
|
|
|
* GNU General Public License for more details. |
24
|
|
|
* |
25
|
|
|
* This copyright notice MUST APPEAR in all copies of the script! |
26
|
|
|
***************************************************************/ |
27
|
|
|
|
28
|
|
|
use AOE\AoeIpauth\Utility\EnableFieldsUtility; |
29
|
|
|
use TYPO3\CMS\Core\Database\ConnectionPool; |
30
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Class ContentService |
34
|
|
|
* |
35
|
|
|
* @package AOE\AoeIpauth\Domain\Service |
36
|
|
|
*/ |
37
|
|
|
class ContentService implements \TYPO3\CMS\Core\SingletonInterface |
38
|
|
|
{ |
39
|
|
|
|
40
|
|
|
const CONTENT_TABLE = 'tt_content'; |
41
|
|
|
const PAGES_TABLE = 'pages'; |
42
|
|
|
const PAGES_OVERLAY_TABLE = 'pages_language_overlay'; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Returns true if the page has content elements |
46
|
|
|
* that depend on logged in users/user groups |
47
|
|
|
* |
48
|
|
|
* @param int $uid |
49
|
|
|
* @param int $languageUid |
50
|
|
|
* @return bool |
51
|
|
|
*/ |
52
|
|
|
public function isPageUserCustomized($uid, $languageUid) |
53
|
|
|
{ |
54
|
|
|
$rows = $this->findUserCustomizedContentByPageId($uid, $languageUid); |
55
|
|
|
$isCustomizedByContent = (0 < count($rows)); |
56
|
|
|
$isCustomizedByPage = $this->isPageBareUserCustomized($uid, $languageUid); |
57
|
|
|
return ($isCustomizedByContent || $isCustomizedByPage); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Checks if a page itself is user customized |
62
|
|
|
* No matter what the languageUid is, we only need to check the original page |
63
|
|
|
* |
64
|
|
|
* @param int $uid |
65
|
|
|
* @param int $languageUid |
66
|
|
|
* @return bool |
67
|
|
|
*/ |
68
|
|
|
public function isPageBareUserCustomized($uid, $languageUid) |
|
|
|
|
69
|
|
|
{ |
70
|
|
|
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable(self::PAGES_TABLE); |
71
|
|
|
$queryBuilder->getRestrictions()->removeAll(); |
72
|
|
|
$pages = $queryBuilder->select('uid', 'pid') |
73
|
|
|
->from(self::PAGES_TABLE) |
74
|
|
|
->where( |
75
|
|
|
$queryBuilder->expr()->neq('fe_group', 0), |
76
|
|
|
$queryBuilder->expr()->eq('uid', (int)$uid . ' ' . EnableFieldsUtility::enableFields(self::CONTENT_TABLE)) |
77
|
|
|
) |
78
|
|
|
->execute() |
79
|
|
|
->fetchAll(); |
80
|
|
|
|
81
|
|
|
$isPageCustomized = (count($pages) > 0); |
82
|
|
|
return $isPageCustomized; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Returns content elements that depend on logged in users/user groups |
87
|
|
|
* TODO: this will not consider: |
88
|
|
|
* a) content that is displayed here but is only referenced, and |
89
|
|
|
* b) content that is on the page but not used |
90
|
|
|
* (not actually linked to the page) |
91
|
|
|
* |
92
|
|
|
* @param int $uid fe_groups uid |
93
|
|
|
* @param int $languageUid |
94
|
|
|
* @return array |
95
|
|
|
*/ |
96
|
|
|
public function findUserCustomizedContentByPageId($uid, $languageUid) |
97
|
|
|
{ |
98
|
|
|
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable(self::CONTENT_TABLE); |
99
|
|
|
$queryBuilder->getRestrictions()->removeAll(); |
100
|
|
|
$ttContent = $queryBuilder->select('uid', 'pid') |
101
|
|
|
->from(self::CONTENT_TABLE) |
102
|
|
|
->where( |
103
|
|
|
$queryBuilder->expr()->gt('fe_group', 0), |
104
|
|
|
$queryBuilder->expr()->eq('sys_language_uid', (int)$languageUid), |
105
|
|
|
$queryBuilder->expr()->eq('pid', (int)$uid . ' ' . EnableFieldsUtility::enableFields(self::CONTENT_TABLE)) |
106
|
|
|
) |
107
|
|
|
->execute() |
108
|
|
|
->fetchAll(); |
109
|
|
|
|
110
|
|
|
|
111
|
|
|
return $ttContent; |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.