2 namespace wcf\system\form\builder\field\user\group\option;
3 use wcf\system\database\util\PreparedStatementConditionBuilder;
4 use wcf\system\form\builder\field\IPackagesFormField;
5 use wcf\system\form\builder\field\ItemListFormField;
6 use wcf\system\form\builder\field\TDefaultIdFormField;
7 use wcf\system\form\builder\field\TPackagesFormField;
8 use wcf\system\form\builder\field\validation\FormFieldValidationError;
12 * Implementation of a form field for user group options/permissions.
14 * This field uses the `wcf.form.field.userGroupOption` language item as the default
15 * form field label and uses `permissions` as the default node id.
17 * @author Matthias Schmidt
18 * @copyright 2001-2018 WoltLab GmbH
19 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
20 * @package WoltLabSuite\Core\System\Form\Builder\Field\User\Group\Option
23 class UserGroupOptionFormField extends ItemListFormField implements IPackagesFormField {
24 use TDefaultIdFormField;
25 use TPackagesFormField;
28 * Creates a new instance of `OptionsFormField`.
30 public function __construct() {
31 $this->label('wcf.form.field.userGroupOption');
37 public function validate() {
40 if (empty($this->getValidationErrors()) && is_array($this->getValue()) && !empty($this->getValue())) {
41 $conditionBuilder = new PreparedStatementConditionBuilder();
42 $conditionBuilder->add('optionName IN (?)', [$this->getValue()]);
43 if (!empty($this->getPackageIDs())) {
44 $conditionBuilder->add('packageID IN (?)', [$this->getPackageIDs()]);
47 $sql = "SELECT optionName
48 FROM wcf" . WCF_N . "_user_group_option
49 " . $conditionBuilder;
50 $statement = WCF::getDB()->prepareStatement($sql);
51 $statement->execute($conditionBuilder->getParameters());
52 $availableOptions = $statement->fetchAll(\PDO::FETCH_COLUMN);
54 $unknownOptions = array_diff($this->getValue(), $availableOptions);
56 if (!empty($unknownOptions)) {
57 $this->addValidationError(
58 new FormFieldValidationError(
60 'wcf.form.field.userGroupOption.error.nonExistent',
61 ['options' => $unknownOptions]
71 protected static function getDefaultId() {