);
$this->pageIDs = $this->visibleEverywhere = null;
- foreach ($this->groupedConditionObjectTypes as $groupedObjectTypes) {
- foreach ($groupedObjectTypes as $objectTypes) {
- if (\is_array($objectTypes)) {
- foreach ($objectTypes as $objectType) {
- $objectType->getProcessor()->readFormParameters();
- if ($objectType->objectTypeID == $pageConditionObjectTypeID) {
- \assert($objectTypes->getProcessor() instanceof MultiPageCondition);
-
- $data = $objectType->getProcessor()->getData();
- if ($data !== null) {
- $this->pageIDs = $data['pageIDs'];
- $this->visibleEverywhere = $data['pageIDs_reverseLogic'] ? 1 : 0;
- } else {
- $this->pageIDs = [];
- $this->visibleEverywhere = 1;
- }
- }
- }
+ foreach ($this->toFlatList($this->groupedConditionObjectTypes) as $objectType) {
+ $objectType->getProcessor()->readFormParameters();
+ if ($objectType->objectTypeID == $pageConditionObjectTypeID) {
+ \assert($objectType->getProcessor() instanceof MultiPageCondition);
+
+ $data = $objectType->getProcessor()->getData();
+ if ($data !== null) {
+ $this->pageIDs = $data['pageIDs'];
+ $this->visibleEverywhere = $data['pageIDs_reverseLogic'] ? 1 : 0;
} else {
- $objectTypes->getProcessor()->readFormParameters();
- if ($objectTypes->objectTypeID == $pageConditionObjectTypeID) {
- \assert($objectTypes->getProcessor() instanceof MultiPageCondition);
-
- $data = $objectTypes->getProcessor()->getData();
- if ($data !== null) {
- $this->pageIDs = $data['pageIDs'];
- $this->visibleEverywhere = $data['pageIDs_reverseLogic'] ? 1 : 0;
- } else {
- $this->pageIDs = [];
- $this->visibleEverywhere = 1;
- }
- }
+ $this->pageIDs = [];
+ $this->visibleEverywhere = 1;
}
}
}
$this->pageIDs = $statement->fetchAll(\PDO::FETCH_COLUMN);
}
- foreach ($this->groupedConditionObjectTypes as $groupedObjectTypes) {
- foreach ($groupedObjectTypes as $objectTypes) {
- if (\is_array($objectTypes)) {
- foreach ($objectTypes as $objectType) {
- $objectType->getProcessor()->validate();
- }
- } else {
- $objectTypes->getProcessor()->validate();
- }
- }
+ foreach ($this->toFlatList($this->groupedConditionObjectTypes) as $objectType) {
+ $objectType->getProcessor()->validate();
}
}
// save acl
SimpleAclHandler::getInstance()->setValues('com.woltlab.wcf.box', $box->boxID, $this->aclValues);
- // transform conditions array into one-dimensional array
- $conditions = [];
- foreach ($this->groupedConditionObjectTypes as $groupedObjectTypes) {
- foreach ($groupedObjectTypes as $objectTypes) {
- if (\is_array($objectTypes)) {
- $conditions = \array_merge($conditions, $objectTypes);
- } else {
- $conditions[] = $objectTypes;
- }
- }
- }
- ConditionHandler::getInstance()->createConditions($box->boxID, $conditions);
+ ConditionHandler::getInstance()->createConditions(
+ $box->boxID,
+ $this->toFlatList($this->groupedConditionObjectTypes)
+ );
// call saved event
$this->saved();
$this->linkPageID = 0;
$this->linkPageObjectID = 0;
- foreach ($conditions as $condition) {
+ foreach ($this->toFlatList($this->groupedConditionObjectTypes) as $condition) {
$condition->getProcessor()->reset();
}
}
}
}
+ /**
+ * This is a helper method to convert groupedConditionObjectTypes to a flat list.
+ * This method should not be used for any other purpose!
+ *
+ * @since 5.5
+ */
+ protected function toFlatList(array $array): array
+ {
+ $returnList = [];
+
+ foreach ($array as $element) {
+ if (\is_array($element)) {
+ $returnList = \array_merge($returnList, $this->toFlatList($element));
+ } else {
+ $returnList[] = $element;
+ }
+ }
+
+ return $returnList;
+ }
+
/**
* @inheritDoc
*/
SimpleAclHandler::getInstance()->setValues('com.woltlab.wcf.box', $this->box->boxID, $this->aclValues);
- // transform conditions array into one-dimensional array
- $conditions = [];
- foreach ($this->groupedConditionObjectTypes as $groupedObjectTypes) {
- foreach ($groupedObjectTypes as $objectTypes) {
- if (\is_array($objectTypes)) {
- $conditions = \array_merge($conditions, $objectTypes);
- } else {
- $conditions[] = $objectTypes;
- }
- }
- }
-
ConditionHandler::getInstance()->updateConditions(
$this->box->boxID,
$this->box->getVisibilityConditions(),
- $conditions
+ $this->toFlatList($this->groupedConditionObjectTypes)
);
// call saved event
$conditionsByObjectTypeID[$condition->objectTypeID] = $condition;
}
- foreach ($this->groupedConditionObjectTypes as $objectTypes1) {
- foreach ($objectTypes1 as $objectTypes2) {
- if (\is_array($objectTypes2)) {
- foreach ($objectTypes2 as $objectType) {
- if (isset($conditionsByObjectTypeID[$objectType->objectTypeID])) {
- $conditionsByObjectTypeID[$objectType->objectTypeID]->getObjectType()->getProcessor()->setData($conditionsByObjectTypeID[$objectType->objectTypeID]);
- }
- }
- } elseif (isset($conditionsByObjectTypeID[$objectTypes2->objectTypeID])) {
- $conditionsByObjectTypeID[$objectTypes2->objectTypeID]->getObjectType()->getProcessor()->setData($conditionsByObjectTypeID[$objectTypes2->objectTypeID]);
- }
+ foreach ($this->toFlatList($this->groupedConditionObjectTypes) as $objectType) {
+ if (isset($conditionsByObjectTypeID[$objectType->objectTypeID])) {
+ $conditionsByObjectTypeID[$objectType->objectTypeID]->getObjectType()->getProcessor()->setData($conditionsByObjectTypeID[$objectType->objectTypeID]);
}
}
}