Commit | Line | Data |
---|---|---|
158bd3ca TD |
1 | <?php |
2 | namespace wcf\data\user\group\option; | |
e85351ba | 3 | use wcf\data\user\group\UserGroupEditor; |
158bd3ca | 4 | use wcf\data\AbstractDatabaseObjectAction; |
4d96fd99 | 5 | use wcf\system\database\util\PreparedStatementConditionBuilder; |
c9fba0a2 | 6 | use wcf\system\WCF; |
158bd3ca TD |
7 | |
8 | /** | |
9 | * Executes user group option-related actions. | |
10 | * | |
11 | * @author Alexander Ebert | |
7b7b9764 | 12 | * @copyright 2001-2019 WoltLab GmbH |
158bd3ca | 13 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> |
e71525e4 | 14 | * @package WoltLabSuite\Core\Data\User\Group\Option |
0e8867ac MS |
15 | * |
16 | * @method UserGroupOption create() | |
17 | * @method UserGroupOptionEditor[] getObjects() | |
18 | * @method UserGroupOptionEditor getSingleObject() | |
158bd3ca TD |
19 | */ |
20 | class UserGroupOptionAction extends AbstractDatabaseObjectAction { | |
21 | /** | |
0fcfe5f6 | 22 | * @inheritDoc |
158bd3ca | 23 | */ |
157054c9 | 24 | protected $className = UserGroupOptionEditor::class; |
c9fba0a2 AE |
25 | |
26 | /** | |
27 | * Updates option values for given option id. | |
28 | */ | |
139fee8b | 29 | public function updateValues() { |
4d96fd99 | 30 | /** @var UserGroupOption $option */ |
c9fba0a2 AE |
31 | $option = current($this->objects); |
32 | ||
4d96fd99 AE |
33 | $conditions = new PreparedStatementConditionBuilder(); |
34 | $conditions->add("optionID = ?", [$option->optionID]); | |
35 | if (!empty($this->parameters['values'])) { | |
36 | $groupIDs = array_keys($this->parameters['values']); | |
37 | $conditions->add("groupID IN (?)", [$groupIDs]); | |
38 | } | |
39 | ||
c9fba0a2 AE |
40 | // remove old values |
41 | $sql = "DELETE FROM wcf".WCF_N."_user_group_option_value | |
4d96fd99 | 42 | ".$conditions; |
c9fba0a2 | 43 | $statement = WCF::getDB()->prepareStatement($sql); |
4d96fd99 | 44 | $statement->execute($conditions->getParameters()); |
c9fba0a2 AE |
45 | |
46 | if (!empty($this->parameters['values'])) { | |
47 | $sql = "INSERT INTO wcf".WCF_N."_user_group_option_value | |
48 | (optionID, groupID, optionValue) | |
49 | VALUES (?, ?, ?)"; | |
50 | $statement = WCF::getDB()->prepareStatement($sql); | |
51 | ||
52 | WCF::getDB()->beginTransaction(); | |
53 | foreach ($this->parameters['values'] as $groupID => $optionValue) { | |
058cbd6a | 54 | $statement->execute([ |
c9fba0a2 AE |
55 | $option->optionID, |
56 | $groupID, | |
57 | $optionValue | |
058cbd6a | 58 | ]); |
c9fba0a2 AE |
59 | } |
60 | WCF::getDB()->commitTransaction(); | |
61 | } | |
139fee8b AE |
62 | |
63 | // clear cache | |
e85351ba | 64 | UserGroupEditor::resetCache(); |
c9fba0a2 | 65 | } |
dcb3a44c | 66 | } |