1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2024-11-16 16:30:09 +00:00
Tims-Chat/files/lib/system/cache/builder/PermissionCacheBuilder.class.php

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

66 lines
2.6 KiB
PHP
Raw Normal View History

2018-08-16 22:30:59 +00:00
<?php
2022-03-04 17:10:24 +00:00
2018-08-16 22:30:59 +00:00
/**
2024-01-13 20:03:36 +00:00
* Copyright (C) 2010-2024 Tim Düsterhus
* Copyright (C) 2010-2024 Woltlab GmbH
2018-08-16 22:30:59 +00:00
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
namespace chat\system\cache\builder;
2022-03-04 17:10:24 +00:00
use wcf\system\acl\ACLHandler;
use wcf\system\cache\builder\AbstractCacheBuilder;
use wcf\system\database\util\PreparedStatementConditionBuilder;
use wcf\system\WCF;
2018-08-16 22:30:59 +00:00
/**
* Caches the chat permissions for a combination of user groups.
*/
2022-03-04 18:49:30 +00:00
final class PermissionCacheBuilder extends AbstractCacheBuilder
2022-03-04 17:10:24 +00:00
{
/**
* @inheritDoc
*/
public function rebuild(array $parameters)
{
$data = [ ];
2018-08-16 22:30:59 +00:00
2022-03-04 17:10:24 +00:00
if (!empty($parameters)) {
$conditionBuilder = new PreparedStatementConditionBuilder();
$conditionBuilder->add('acl_option.objectTypeID = ?', [ ACLHandler::getInstance()->getObjectTypeID('be.bastelstu.chat.room') ]);
$conditionBuilder->add('option_to_group.groupID IN (?)', [ $parameters ]);
$sql = "SELECT option_to_group.objectID AS roomID,
option_to_group.optionValue,
acl_option.optionName AS permission
FROM wcf1_acl_option acl_option
INNER JOIN wcf1_acl_option_to_group option_to_group
ON option_to_group.optionID = acl_option.optionID
{$conditionBuilder}";
$statement = WCF::getDB()->prepare($sql);
$statement->execute($conditionBuilder->getParameters());
while (($row = $statement->fetchArray())) {
if (!isset($data[$row['roomID']][$row['permission']])) {
$data[$row['roomID']][$row['permission']] = $row['optionValue'];
} else {
$data[$row['roomID']][$row['permission']] = $row['optionValue'] || $data[$row['roomID']][$row['permission']];
}
}
}
2018-08-16 22:30:59 +00:00
2022-03-04 17:10:24 +00:00
return $data;
}
2018-08-16 22:30:59 +00:00
}