From: joshuaruesweg Date: Mon, 30 Aug 2021 08:28:33 +0000 (+0200) Subject: Add condition handling for boxes X-Git-Tag: 5.5.0_Alpha_1~456^2~6 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=fdf2e75f1a6ee7015a9d9c8d092a9a86ffa5f0d1;p=GitHub%2FWoltLab%2FWCF.git Add condition handling for boxes --- diff --git a/wcfsetup/install/files/acp/templates/boxAdd.tpl b/wcfsetup/install/files/acp/templates/boxAdd.tpl index 2c83daf0d3..779c3d877c 100644 --- a/wcfsetup/install/files/acp/templates/boxAdd.tpl +++ b/wcfsetup/install/files/acp/templates/boxAdd.tpl @@ -97,6 +97,7 @@
  • {lang}wcf.global.form.data{/lang}
  • {lang}wcf.acp.box.contents{/lang}
  • {lang}wcf.acp.page.list{/lang}
  • +
  • {lang}wcf.acp.box.conditions{/lang}
  • {lang}wcf.acl.access{/lang}
  • {event name='tabMenuTabs'} @@ -478,6 +479,42 @@ {include file='aclSimple' __supportsInvertedPermissions=true} +
    +
    +
    +

    {lang}wcf.acp.box.conditions.page{/lang}

    +
    + + {foreach from=$groupedConditionObjectTypes['com.woltlab.wcf.page'] item='pageConditionObjectType'} + {@$pageConditionObjectType->getProcessor()->getHtml()} + {/foreach} +
    + + {if $groupedConditionObjectTypes['com.woltlab.wcf.pointInTime']|isset} +
    +
    +

    {lang}wcf.acp.box.conditions.pointInTime{/lang}

    +
    + + {foreach from=$groupedConditionObjectTypes['com.woltlab.wcf.pointInTime'] item='pointInTimeConditionObjectType'} + {@$pointInTimeConditionObjectType->getProcessor()->getHtml()} + {/foreach} +
    + {/if} + + {if $groupedConditionObjectTypes['com.woltlab.wcf.user']|isset} +
    +
    +

    {lang}wcf.acp.box.conditions.user{/lang}

    +
    + + {include file='userConditions' groupedObjectTypes=$groupedConditionObjectTypes['com.woltlab.wcf.user']} +
    + {/if} + + {event name='conditionContainers'} +
    + {event name='tabMenuContents'} diff --git a/wcfsetup/install/files/lib/acp/form/BoxAddForm.class.php b/wcfsetup/install/files/lib/acp/form/BoxAddForm.class.php index 2b6dccfb5e..4c40f67f82 100644 --- a/wcfsetup/install/files/lib/acp/form/BoxAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/BoxAddForm.class.php @@ -16,6 +16,7 @@ use wcf\form\AbstractForm; use wcf\system\acl\simple\SimpleAclHandler; use wcf\system\box\IBoxController; use wcf\system\box\IConditionBoxController; +use wcf\system\condition\ConditionHandler; use wcf\system\database\util\PreparedStatementConditionBuilder; use wcf\system\exception\IllegalLinkException; use wcf\system\exception\UserInputException; @@ -222,6 +223,12 @@ class BoxAddForm extends AbstractForm */ public $invertPermissions; + /** + * grouped boxes condition object types + * @var ObjectType[][] + */ + public $groupedConditionObjectTypes = []; + /** * @inheritDoc */ @@ -393,6 +400,18 @@ class BoxAddForm extends AbstractForm if ($this->boxType === 'system') { $this->boxController = ObjectTypeCache::getInstance()->getObjectType($this->boxControllerID); } + + foreach ($this->groupedConditionObjectTypes as $groupedObjectTypes) { + foreach ($groupedObjectTypes as $objectTypes) { + if (\is_array($objectTypes)) { + foreach ($objectTypes as $objectType) { + $objectType->getProcessor()->readFormParameters(); + } + } else { + $objectTypes->getProcessor()->readFormParameters(); + } + } + } } /** @@ -532,6 +551,18 @@ class BoxAddForm extends AbstractForm $statement->execute($conditionBuilder->getParameters()); $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(); + } + } + } } /** @@ -637,6 +668,19 @@ class BoxAddForm extends AbstractForm // 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); + // call saved event $this->saved(); @@ -659,6 +703,10 @@ class BoxAddForm extends AbstractForm $this->linkType = 'none'; $this->linkPageID = 0; $this->linkPageObjectID = 0; + + foreach ($conditions as $condition) { + $condition->getProcessor()->reset(); + } } /** @@ -666,6 +714,27 @@ class BoxAddForm extends AbstractForm */ public function readData() { + $objectTypes = ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.condition.box'); + foreach ($objectTypes as $objectType) { + if (!$objectType->conditionobject) { + continue; + } + + if (!isset($this->groupedConditionObjectTypes[$objectType->conditionobject])) { + $this->groupedConditionObjectTypes[$objectType->conditionobject] = []; + } + + if ($objectType->conditiongroup) { + if (!isset($this->groupedConditionObjectTypes[$objectType->conditionobject][$objectType->conditiongroup])) { + $this->groupedConditionObjectTypes[$objectType->conditionobject][$objectType->conditiongroup] = []; + } + + $this->groupedConditionObjectTypes[$objectType->conditionobject][$objectType->conditiongroup][$objectType->objectTypeID] = $objectType; + } else { + $this->groupedConditionObjectTypes[$objectType->conditionobject][$objectType->objectTypeID] = $objectType; + } + } + parent::readData(); if (empty($_POST) && $this->presetBox) { @@ -758,6 +827,7 @@ class BoxAddForm extends AbstractForm 'aclValues' => SimpleAclHandler::getInstance()->getOutputValues($this->aclValues), 'availableBoxPositions' => $this->availableBoxPositions, 'invertPermissions' => $this->invertPermissions, + 'groupedConditionObjectTypes' => $this->groupedConditionObjectTypes, ]); } } diff --git a/wcfsetup/install/files/lib/acp/form/BoxEditForm.class.php b/wcfsetup/install/files/lib/acp/form/BoxEditForm.class.php index 9832dc5c4e..46ceef3b34 100644 --- a/wcfsetup/install/files/lib/acp/form/BoxEditForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/BoxEditForm.class.php @@ -166,6 +166,24 @@ class BoxEditForm extends BoxAddForm 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->getConditions2(), + $conditions + ); + // call saved event $this->saved(); @@ -239,6 +257,26 @@ class BoxEditForm extends BoxAddForm $this->invertPermissions = $this->box->invertPermissions; $this->readBoxImages(); + + $conditions = $this->box->getConditions2(); + $conditionsByObjectTypeID = []; + foreach ($conditions as $condition) { + $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]); + } + } + } } } diff --git a/wcfsetup/install/files/lib/data/box/Box.class.php b/wcfsetup/install/files/lib/data/box/Box.class.php index 2e00f9522c..2d51e5b16e 100644 --- a/wcfsetup/install/files/lib/data/box/Box.class.php +++ b/wcfsetup/install/files/lib/data/box/Box.class.php @@ -548,6 +548,32 @@ class Box extends DatabaseObject return []; } + /** + * @TODO + * + * @return Condition[] + * @since 5.5 + */ + public function getConditions2(): array // @TODO name + { + return ConditionHandler::getInstance()->getConditions( + 'com.woltlab.wcf.condition.box', // @TODO make const + $this->boxID + ); + } + + public function isVisible(): bool + { + $conditions = $this->getConditions2(); + foreach ($conditions as $condition) { + if (!$condition->getObjectType()->getProcessor()->showContent($condition)) { + return false; + } + } + + return true; + } + /** * Returns true if this box is accessible by current user. * diff --git a/wcfsetup/install/files/lib/system/box/BoxHandler.class.php b/wcfsetup/install/files/lib/system/box/BoxHandler.class.php index 410b71deb5..6cdb5f8294 100644 --- a/wcfsetup/install/files/lib/system/box/BoxHandler.class.php +++ b/wcfsetup/install/files/lib/system/box/BoxHandler.class.php @@ -270,7 +270,7 @@ class BoxHandler extends SingletonFactory $boxes = []; foreach ($boxList as $box) { - if (!$forDisplay || $box->isAccessible()) { + if (!$forDisplay || ($box->isAccessible() && $box->isVisible())) { $virtualShowOrder = (isset($showOrders[$box->boxID])) ? $showOrders[$box->boxID] : ($box->showOrder + 1000); $box->setVirtualShowOrder($virtualShowOrder); diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index b1ee460813..ada4555558 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -263,6 +263,10 @@ + + + + diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 80cee684f3..3aaadf76b0 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -262,6 +262,10 @@ + + + +