2 namespace wcf\system\package\plugin;
3 use wcf\data\user\group\option\UserGroupOption;
4 use wcf\data\user\group\option\UserGroupOptionEditor;
5 use wcf\data\user\group\UserGroup;
7 use wcf\util\StringUtil;
10 * This PIP installs, updates or deletes user group permissions.
12 * @author Benjamin Kunz
13 * @copyright 2001-2011 WoltLab GmbH
14 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
15 * @package com.woltlab.wcf
16 * @subpackage system.package.plugin
17 * @category Community Framework
19 class UserGroupOptionsPackageInstallationPlugin extends AbstractOptionPackageInstallationPlugin {
21 * @see wcf\system\package\plugin\AbstractPackageInstallationPlugin::$tableName
23 public $tableName = 'user_group_option';
25 public static $reservedTags = array('name', 'optiontype', 'defaultvalue', 'admindefaultvalue', 'validationpattern', 'showorder', 'categoryname', 'selectoptions', 'enableoptions', 'permissions', 'options', 'attrs', 'cdata');
28 * Deletes group-option-categories and/or group-options which where installed by the package.
30 public function uninstall() {
31 // Delete value-entries using categories or options
32 // which will be deleted.
33 $sql = "DELETE FROM wcf".WCF_N."_user_group_option_value
36 FROM wcf".WCF_N."_user_group_option
39 $statement = WCF::getDB()->prepareStatement($sql);
40 $statement->execute(array($this->installation->getPackageID()));
46 * @see wcf\system\package\plugin\AbstractOptionPackageInstallationPlugin::saveOption()
48 protected function saveOption($option, $categoryName, $existingOptionID = 0) {
50 $optionName = $optionType = $defaultValue = $adminDefaultValue = $validationPattern = $enableOptions = $permissions = $options = '';
54 if (isset($option['name'])) $optionName = $option['name'];
55 if (isset($option['optiontype'])) $optionType = $option['optiontype'];
56 if (isset($option['defaultvalue'])) $defaultValue = $option['defaultvalue'];
57 if (isset($option['admindefaultvalue'])) $adminDefaultValue = $option['admindefaultvalue'];
58 if (isset($option['validationpattern'])) $validationPattern = $option['validationpattern'];
59 if (!empty($option['showorder'])) $showOrder = intval($option['showorder']);
60 $showOrder = $this->getShowOrder($showOrder, $categoryName, 'categoryName');
61 if (isset($option['enableoptions'])) $enableOptions = $option['enableoptions'];
62 if (isset($option['permissions'])) $permissions = $option['permissions'];
63 if (isset($option['options'])) $options = $option['options'];
65 // check if optionType exists
66 $className = 'wcf\system\option\user\group\\'.StringUtil::firstCharToUpperCase($optionType).'UserGroupOptionType';
67 if (!class_exists($className)) {
68 throw new SystemException("unable to find class '".$className."'");
71 // collect additional tags and their values
72 $additionalData = array();
73 foreach ($option as $tag => $value) {
74 if (!in_array($tag, self::$reservedTags)) $additionalData[$tag] = $value;
77 // check if the otion exist already and was installed by this package
78 $sql = "SELECT optionID
79 FROM wcf".WCF_N."_user_group_option
82 $statement = WCF::getDB()->prepareStatement($sql);
83 $statement->execute(array(
85 $this->installation->getPackageID()
87 $row = $statement->fetchArray();
90 'categoryName' => $categoryName,
91 'optionType' => $optionType,
92 'defaultValue' => $defaultValue,
93 'adminDefaultValue' => $adminDefaultValue,
94 'validationPattern' => $validationPattern,
95 'showOrder' => $showOrder,
96 'enableOptions' => $enableOptions,
97 'permissions' => $permissions,
98 'options' => $options,
99 'additionalData' => serialize($additionalData)
102 if (!empty($row['optionID'])) {
103 // update existing option
104 $optionID = $row['optionID'];
106 $groupOption = new UserGroupOption(null, $row);
107 $groupOptionEditor = new UserGroupOptionEditor($groupOption);
108 $groupOptionEditor->update($data);
112 $data['packageID'] = $this->installation->getPackageID();
113 $data['optionName'] = $optionName;
115 $groupOptionEditor = UserGroupOptionEditor::create($data);
116 $optionID = $groupOptionEditor->optionID;
118 // get default group ("everyone")
119 $sql = "SELECT groupID
120 FROM wcf".WCF_N."_user_group
121 WHERE groupType = ?";
122 $statement = WCF::getDB()->prepareStatement($sql);
123 $statement->execute(array(UserGroup::EVERYONE));
124 $row = $statement->fetchArray();
126 // save default value
127 $sql = "INSERT INTO wcf".WCF_N."_user_group_option_value
128 (groupID, optionID, optionValue)
130 $statement = WCF::getDB()->prepareStatement($sql);
131 $statement->execute(array($row['groupID'], $optionID, $defaultValue));
133 if ($adminDefaultValue && $defaultValue != $adminDefaultValue) {
134 $sql = "SELECT groupID
135 FROM wcf".WCF_N."_user_group_option_value
138 FROM wcf".WCF_N."_user_group_option
141 AND optionValue = '1'";
142 $statement2 = WCF::getDB()->prepareStatement($sql);
143 $statement2->execute(array('admin.general.canUseAcp'));
145 $acpGroups = array();
146 while ($row = $statement2->fetchArray()) {
147 $acpGroups[] = $row['groupID'];
150 $statement2->execute(array('admin.user.canEditGroup'));
151 while ($row = $statement2->fetchArray()) {
152 if (!in_array($row['groupID'], $acpGroups)) {
156 $statement->execute(array(