From: Matthias Schmidt Date: Tue, 30 Jun 2020 16:10:50 +0000 (+0200) Subject: Support setting user's style when editing user in ACP X-Git-Tag: 5.3.0_Alpha_1~180 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=f0f8e3438c97b54a33f0ff1e634b6cff7bc209a3;p=GitHub%2FWoltLab%2FWCF.git Support setting user's style when editing user in ACP Close #3254 --- diff --git a/wcfsetup/install/files/acp/templates/userAdd.tpl b/wcfsetup/install/files/acp/templates/userAdd.tpl index 3ca491e1e1..a735f59c25 100644 --- a/wcfsetup/install/files/acp/templates/userAdd.tpl +++ b/wcfsetup/install/files/acp/templates/userAdd.tpl @@ -241,23 +241,49 @@

{lang}wcf.user.option.category.{@$categoryLevel2[object]->categoryName}{/lang}

- {if $categoryLevel2[object]->categoryName == 'settings.general' && $availableLanguages|count > 1} -
-
-
- {htmlOptions options=$availableLanguages selected=$languageID name=languageID id=languageID disableEncoding=true} -
-
+ {if $categoryLevel2[object]->categoryName == 'settings.general'} + {if $availableLanguages|count > 1} +
+
+
+ {htmlOptions options=$availableLanguages selected=$languageID name=languageID id=languageID disableEncoding=true} +
+
+ + {if $availableContentLanguages|count > 1} +
+
+ +
+
+ {foreach from=$availableContentLanguages key=availableLanguageID item=availableLanguage} + + {/foreach} +
+
+ {/if} + {/if} - {if $availableContentLanguages|count > 1} + {if $action === 'edit' && $availableStyles|count > 1}
-
- -
+
- {foreach from=$availableContentLanguages key=availableLanguageID item=availableLanguage} - - {/foreach} + + {if $errorField === 'styleID'} + + {if $errorType === 'empty' || $errorType === 'noValidSelection'} + {lang}wcf.global.form.error.{@$errorType}{/lang} + {else} + {lang}wcf.user.style.error.{@$errorType.password}{/lang} + {/if} + + {/if} + {lang}wcf.user.style.description{/lang}
{/if} diff --git a/wcfsetup/install/files/lib/acp/form/UserEditForm.class.php b/wcfsetup/install/files/lib/acp/form/UserEditForm.class.php index c1c5045b12..9a94c562f9 100755 --- a/wcfsetup/install/files/lib/acp/form/UserEditForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/UserEditForm.class.php @@ -1,5 +1,6 @@ * @package WoltLabSuite\Core\Acp\Form */ @@ -133,6 +135,20 @@ class UserEditForm extends UserAddForm { */ public $disconnect3rdParty = 0; + /** + * list of available styles for the edited user + * @var Style[] + * @since 5.3 + */ + public $availableStyles = []; + + /** + * id of the used style + * @var int + * @since 5.3 + */ + public $styleID; + /** * @inheritDoc */ @@ -175,6 +191,7 @@ class UserEditForm extends UserAddForm { } if (isset($_POST['avatarType'])) $this->avatarType = $_POST['avatarType']; + if (isset($_POST['styleID'])) $this->styleID = intval($_POST['styleID']); if (WCF::getSession()->getPermission('admin.user.canDisableAvatar')) { if (!empty($_POST['disableAvatar'])) $this->disableAvatar = 1; @@ -208,6 +225,13 @@ class UserEditForm extends UserAddForm { $this->readDefaultValues(); } + $userProfile = UserProfileRuntimeCache::getInstance()->getObject($this->userID); + foreach (StyleHandler::getInstance()->getStyles() as $style) { + if (!$style->isDisabled || $userProfile->getPermission('admin.style.canUseDisabledStyle')) { + $this->availableStyles[$style->styleID] = $style; + } + } + parent::readData(); // get the avatar object @@ -217,8 +241,6 @@ class UserEditForm extends UserAddForm { // get the user cover photo object if ($this->user->coverPhotoHash) { - $userProfile = UserProfileRuntimeCache::getInstance()->getObject($this->userID); - // If the editing user lacks the permissions to view the cover photo, the system // will try to load the default cover photo. However, the default cover photo depends // on the style, eventually triggering a change to the template group which will @@ -248,6 +270,7 @@ class UserEditForm extends UserAddForm { $this->banReason = $this->user->banReason; $this->banExpires = $this->user->banExpires; $this->userTitle = $this->user->userTitle; + $this->styleID = $this->user->styleID; $this->signature = $this->user->signature; $this->disableSignature = $this->user->disableSignature; @@ -292,6 +315,8 @@ class UserEditForm extends UserAddForm { 'disableCoverPhotoExpires' => $this->disableCoverPhotoExpires, 'deleteCoverPhoto' => $this->deleteCoverPhoto, 'ownerGroupID' => UserGroup::getOwnerGroupID(), + 'availableStyles' => $this->availableStyles, + 'styleID' => $this->styleID, ]); } @@ -351,7 +376,7 @@ class UserEditForm extends UserAddForm { // save user $saveOptions = $this->optionHandler->save(); - + $data = [ 'data' => array_merge($this->additionalFields, [ 'username' => $this->username, @@ -359,11 +384,12 @@ class UserEditForm extends UserAddForm { 'password' => $this->password, 'languageID' => $this->languageID, 'userTitle' => $this->userTitle, - 'signature' => $this->htmlInputProcessor->getHtml() + 'signature' => $this->htmlInputProcessor->getHtml(), + 'styleID' => $this->styleID, ]), 'groups' => $this->groupIDs, 'languageIDs' => $this->visibleLanguages, - 'options' => $saveOptions + 'options' => $saveOptions, ]; // handle changed username if (mb_strtolower($this->username) != mb_strtolower($this->user->username)) { @@ -520,5 +546,9 @@ class UserEditForm extends UserAddForm { $this->validateAvatar(); parent::validate(); + + if (!isset($this->availableStyles[$this->styleID])) { + throw new UserInputException('styleID', 'noValidSelection'); + } } }