2 namespace wcf\system\cache\builder
;
3 use wcf\system\database\util\PreparedStatementConditionBuilder
;
4 use wcf\system\exception\SystemException
;
6 use wcf\util\ClassUtil
;
7 use wcf\util\StringUtil
;
10 * Caches the merged user group options for a certain user group combination.
13 * @copyright 2001-2013 WoltLab GmbH
14 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
15 * @package com.woltlab.wcf
16 * @subpackage system.cache.builder
17 * @category Community Framework
19 class UserGroupPermissionCacheBuilder
extends AbstractCacheBuilder
{
21 * list of used group option type objects
22 * @var array<wcf\system\option\group\IGroupOptionType>
24 protected $typeObjects = array();
27 * @see wcf\system\cache\builder\AbstractCacheBuilder::rebuild()
29 public function rebuild(array $parameters) {
33 $sql = "SELECT optionName, optionID
34 FROM wcf".WCF_N
."_user_group_option";
35 $statement = WCF
::getDB()->prepareStatement($sql);
36 $statement->execute();
39 while ($row = $statement->fetchArray()) {
40 $options[$row['optionName']] = $row['optionID'];
43 if (!empty($options)) {
45 $conditions = new PreparedStatementConditionBuilder();
46 $conditions->add("option_value.groupID IN (?)", array($parameters));
47 $conditions->add("option_value.optionID IN (?)", array($options));
49 $sql = "SELECT option_table.optionName, option_table.optionType, option_value.optionValue
50 FROM wcf".WCF_N
."_user_group_option_value option_value
51 LEFT JOIN wcf".WCF_N
."_user_group_option option_table
52 ON (option_table.optionID = option_value.optionID)
54 $statement = WCF
::getDB()->prepareStatement($sql);
55 $statement->execute($conditions->getParameters());
56 while ($row = $statement->fetchArray()) {
57 if (!isset($data[$row['optionName']])) {
58 $data[$row['optionName']] = array('type' => $row['optionType'], 'values' => array());
61 $data[$row['optionName']]['values'][] = $row['optionValue'];
65 foreach ($data as $optionName => $option) {
66 if (count($option['values']) == 1) {
67 $result = $option['values'][0];
70 $typeObj = $this->getTypeObject($option['type']);
71 $result = array_shift($option['values']);
72 foreach ($option['values'] as $value) {
73 $newValue = $typeObj->merge($result, $value);
74 if ($newValue !== null) {
81 if ($result === false) {
82 unset($data[$optionName]);
85 $data[$optionName] = $result;
90 $data['groupIDs'] = $parameters;
95 * Returns an object of the requested group option type.
98 * @return wcf\system\option\user\group\IUserGroupOptionType
100 protected function getTypeObject($type) {
101 if (!isset($this->typeObjects
[$type])) {
102 $className = 'wcf\system\option\user\group\\'.StringUtil
::firstCharToUpperCase($type).'UserGroupOptionType';
105 if (!class_exists($className)) {
106 throw new SystemException("unable to find class '".$className."'");
108 if (!ClassUtil
::isInstanceOf($className, 'wcf\system\option\user\group\IUserGroupOptionType')) {
109 throw new SystemException("'".$className."' does not implement 'wcf\system\option\user\group\IUserGroupOptionType'");
113 $this->typeObjects
[$type] = new $className();
116 return $this->typeObjects
[$type];