$conditions = new PreparedStatementConditionBuilder();
$conditions->add("option_value.groupID IN (?)", [$parameters]);
- $sql = "SELECT option_table.optionName, option_table.optionType, option_value.optionValue
+ $optionData = [];
+ $sql = "SELECT option_table.optionName, option_table.optionType, option_value.optionValue, option_value.groupID, option_table.enableOptions
FROM wcf".WCF_N."_user_group_option_value option_value
LEFT JOIN wcf".WCF_N."_user_group_option option_table
ON (option_table.optionID = option_value.optionID)
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute($conditions->getParameters());
while ($row = $statement->fetchArray()) {
- if (!isset($data[$row['optionName']])) {
- $data[$row['optionName']] = ['type' => $row['optionType'], 'values' => []];
+ $optionData[$row['groupID']][$row['optionName']] = $row;
+ }
+
+ foreach ($optionData as $groupID => $options) {
+ $optionBlacklist = [];
+
+ foreach ($options as $option) {
+ if ($option['enableOptions']) {
+ $typeObj = $this->getTypeObject($option['optionType']);
+ $disabledOptions = $typeObj->getDisabledOptionNames($option['optionValue'], $option['enableOptions']);
+ if (!empty($disabledOptions)) {
+ $optionBlacklist = array_merge($optionBlacklist, $disabledOptions);
+ }
+ }
}
- $data[$row['optionName']]['values'][] = $row['optionValue'];
+ $options = array_filter($options, function($optionName) use (&$optionBlacklist) {
+ return !in_array($optionName, $optionBlacklist);
+ }, ARRAY_FILTER_USE_KEY);
+
+ foreach ($options as $option) {
+ if (!isset($data[$option['optionName']])) {
+ $data[$option['optionName']] = ['type' => $option['optionType'], 'values' => []];
+ }
+
+ $data[$option['optionName']]['values'][] = $option['optionValue'];
+ }
}
$includesOwnerGroup = false;
use wcf\data\user\UserList;
use wcf\system\database\util\PreparedStatementConditionBuilder;
use wcf\system\WCF;
+use wcf\util\ArrayUtil;
/**
* Option type implementation for boolean values.
return $value1 ? 1 : -1;
}
+
+ /**
+ * @inheritDoc
+ */
+ public function getDisabledOptionNames($value, $enableOptions) {
+ $options = ArrayUtil::trim(explode(',', $enableOptions));
+ $result = [];
+
+ foreach ($options as $item) {
+ if ($item{0} == '!') {
+ if ($value) $result[] = $item;
+ }
+ else {
+ if (!$value) $result[] = $item;
+ }
+ }
+
+ return $result;
+ }
}
public function getCSSClassName();
/**
- * Returns true if options supports internationalization .
+ * Returns true if options supports internationalization.
*
* @return boolean
*/
* @return boolean
*/
public function hideLabelInSearch();
+
+ /**
+ * Determines disabled options by given option value.
+ *
+ * @param mixed $value
+ * @param string $enableOptions
+ * @return string[]
+ * @since 5.2
+ */
+ public function getDisabledOptionNames($value, $enableOptions);
}
use wcf\system\database\util\PreparedStatementConditionBuilder;
use wcf\system\exception\UserInputException;
use wcf\system\WCF;
+use wcf\util\ArrayUtil;
use wcf\util\StringUtil;
/**
public function getCSSClassName() {
return 'checkboxList';
}
+
+ /**
+ * @inheritDoc
+ */
+ public function getDisabledOptionNames($value, $enableOptions) {
+ $valueToOptions = explode("\n", StringUtil::trim(StringUtil::unifyNewlines($enableOptions)));
+
+ $i = 0;
+ foreach ($valueToOptions as $valueToOption) {
+ if (mb_strpos($valueToOption, ':') !== false) {
+ $optionData = explode(':', $valueToOption);
+ $key = array_shift($optionData);
+ $enableOptionValues = implode(':', $optionData);
+ }
+ else {
+ $key = $i;
+ $enableOptionValues = $valueToOption;
+ }
+
+ if ($key == $value) {
+ $options = ArrayUtil::trim(explode(',', $enableOptionValues));
+ $result = [];
+
+ foreach ($options as $item) {
+ if ($item{0} == '!') {
+ $result[] = $item;
+ }
+ else {
+ $result[] = $item;
+ }
+ }
+
+ return $result;
+ }
+
+ $i++;
+ }
+
+ return [];
+ }
}