RecordListQueryHook.php 1014 Bytes
Newer Older
Dainis Abols's avatar
Dainis Abols committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php

namespace Lu\LuNotices\Hooks\Backend;

use Lu\LuNotices\Controller\NoticesController;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
 * Restrict notices records to topics assigned to user in backend list module
 *
 * @package Lu\LuNotices\Hooks\Backend
 */
class RecordListQueryHook
{
    public function modifyQuery(
        array &$parameters,
        string $table,
        int $pageId,
        array $additionalConstraints,
        array $fieldList,
        QueryBuilder $queryBuilder
    ) {
        global $BE_USER;
        $noticesController = GeneralUtility::makeInstance(NoticesController::class);
        $allowedTopics = $noticesController->getBeUserCatMounts($pageId);

        if (empty($allowedTopics)) {
            $allowedTopics = [0];
        }

        if ($table == 'tx_lunotices_domain_model_notices' && !$BE_USER->user['admin']) {
            $queryBuilder->andWhere('topic_id IN ('.implode(',', $allowedTopics).')');
        }
    }
}