From 2a379b2de65fc0ad39365d0f7cb04653b80634f2 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 17 Jul 2017 20:50:23 +0200 Subject: [PATCH] Allow image-only ranks Closes #2325 --- .../files/acp/templates/userRankAdd.tpl | 13 +++++++++++++ .../lib/acp/form/UserRankAddForm.class.php | 19 ++++++++++++++++--- .../lib/acp/form/UserRankEditForm.class.php | 4 +++- .../files/lib/data/user/UserProfile.class.php | 5 +++-- .../lib/data/user/rank/UserRank.class.php | 10 ++++++++++ wcfsetup/install/lang/de.xml | 3 +++ wcfsetup/install/lang/en.xml | 3 +++ wcfsetup/setup/db/install.sql | 3 ++- 8 files changed, 53 insertions(+), 7 deletions(-) diff --git a/wcfsetup/install/files/acp/templates/userRankAdd.tpl b/wcfsetup/install/files/acp/templates/userRankAdd.tpl index 9225de04d7..035791ca85 100644 --- a/wcfsetup/install/files/acp/templates/userRankAdd.tpl +++ b/wcfsetup/install/files/acp/templates/userRankAdd.tpl @@ -114,6 +114,19 @@ {/if} + +
+
+ + {if $errorField == 'hideTitle'} + + {lang}wcf.acp.user.rank.hideTitle.error.{@$errorType}{/lang} + + {/if} + {lang}wcf.acp.user.rank.hideTitle.description{/lang} +
+ + {event name='imageFields'} diff --git a/wcfsetup/install/files/lib/acp/form/UserRankAddForm.class.php b/wcfsetup/install/files/lib/acp/form/UserRankAddForm.class.php index 76a5dad3c8..d993b752c1 100644 --- a/wcfsetup/install/files/lib/acp/form/UserRankAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/UserRankAddForm.class.php @@ -82,6 +82,12 @@ class UserRankAddForm extends AbstractForm { */ public $requiredGender = 0; + /** + * hide generic user title + * @var integer + */ + public $hideTitle = 0; + /** * list of pre-defined css class names * @var string[] @@ -126,6 +132,7 @@ class UserRankAddForm extends AbstractForm { if (isset($_POST['rankImage'])) $this->rankImage = StringUtil::trim($_POST['rankImage']); if (isset($_POST['repeatImage'])) $this->repeatImage = intval($_POST['repeatImage']); if (isset($_POST['requiredGender'])) $this->requiredGender = intval($_POST['requiredGender']); + if (isset($_POST['hideTitle'])) $this->hideTitle = intval($_POST['hideTitle']); } /** @@ -170,6 +177,10 @@ class UserRankAddForm extends AbstractForm { if ($this->requiredGender < 0 || $this->requiredGender > 2) { $this->requiredGender = 0; } + + if ($this->hideTitle && !$this->rankImage) { + throw new UserInputException('hideTitle', 'rankImage'); + } } /** @@ -186,7 +197,8 @@ class UserRankAddForm extends AbstractForm { 'requiredPoints' => $this->requiredPoints, 'rankImage' => $this->rankImage, 'repeatImage' => $this->repeatImage, - 'requiredGender' => $this->requiredGender + 'requiredGender' => $this->requiredGender, + 'hideTitle' => ($this->hideTitle ? 1 : 0) ])]); $this->objectAction->executeAction(); @@ -205,7 +217,7 @@ class UserRankAddForm extends AbstractForm { // reset values $this->rankTitle = $this->cssClassName = $this->customCssClassName = $this->rankImage = ''; - $this->groupID = $this->requiredPoints = $this->requiredGender = 0; + $this->groupID = $this->requiredPoints = $this->requiredGender = $this->hideTitle = 0; $this->repeatImage = 1; I18nHandler::getInstance()->reset(); @@ -233,7 +245,8 @@ class UserRankAddForm extends AbstractForm { 'requiredPoints' => $this->requiredPoints, 'rankImage' => $this->rankImage, 'repeatImage' => $this->repeatImage, - 'requiredGender' => $this->requiredGender + 'requiredGender' => $this->requiredGender, + 'hideTitle' => $this->hideTitle ]); } } diff --git a/wcfsetup/install/files/lib/acp/form/UserRankEditForm.class.php b/wcfsetup/install/files/lib/acp/form/UserRankEditForm.class.php index 0828e8b080..458b4ed349 100644 --- a/wcfsetup/install/files/lib/acp/form/UserRankEditForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/UserRankEditForm.class.php @@ -69,7 +69,8 @@ class UserRankEditForm extends UserRankAddForm { 'requiredPoints' => $this->requiredPoints, 'rankImage' => $this->rankImage, 'repeatImage' => $this->repeatImage, - 'requiredGender' => $this->requiredGender + 'requiredGender' => $this->requiredGender, + 'hideTitle' => $this->hideTitle ])]); $this->objectAction->executeAction(); $this->saved(); @@ -100,6 +101,7 @@ class UserRankEditForm extends UserRankAddForm { $this->requiredGender = $this->rank->requiredGender; $this->repeatImage = $this->rank->repeatImage; $this->rankImage = $this->rank->rankImage; + $this->hideTitle = $this->rank->hideTitle; } } diff --git a/wcfsetup/install/files/lib/data/user/UserProfile.class.php b/wcfsetup/install/files/lib/data/user/UserProfile.class.php index b5adf1d2a3..502f78a382 100644 --- a/wcfsetup/install/files/lib/data/user/UserProfile.class.php +++ b/wcfsetup/install/files/lib/data/user/UserProfile.class.php @@ -561,7 +561,7 @@ class UserProfile extends DatabaseObjectDecorator implements ITitledLinkObject { */ public function getUserTitle() { if ($this->userTitle) return $this->userTitle; - if ($this->getRank()) return WCF::getLanguage()->get($this->getRank()->rankTitle); + if ($this->getRank() && $this->getRank()->showTitle()) return WCF::getLanguage()->get($this->getRank()->rankTitle); return ''; } @@ -583,7 +583,8 @@ class UserProfile extends DatabaseObjectDecorator implements ITitledLinkObject { 'cssClassName' => $this->cssClassName, 'rankImage' => $this->rankImage, 'repeatImage' => $this->repeatImage, - 'requiredGender' => $this->requiredGender + 'requiredGender' => $this->requiredGender, + 'hideTitle' => $this->hideTitle ]); } else { diff --git a/wcfsetup/install/files/lib/data/user/rank/UserRank.class.php b/wcfsetup/install/files/lib/data/user/rank/UserRank.class.php index f2036d28be..88c24ee828 100644 --- a/wcfsetup/install/files/lib/data/user/rank/UserRank.class.php +++ b/wcfsetup/install/files/lib/data/user/rank/UserRank.class.php @@ -20,6 +20,7 @@ use wcf\util\StringUtil; * @property-read string $rankImage (WCF relative) path to the image displayed next to the rank or empty if no rank image exists * @property-read integer $repeatImage number of times the rank image is displayed * @property-read integer $requiredGender numeric representation of the user's gender required for the user rank (see `UserProfile::GENDER_*` constants) or 0 if no specific gender is required + * @property-read integer $hideTitle hides the generic title of the rank, but not custom titles, `0` to show the title at all times */ class UserRank extends DatabaseObject { /** @@ -36,4 +37,13 @@ class UserRank extends DatabaseObject { return ''; } + + /** + * Returns true if the generic rank title should be displayed. + * + * @return boolean + */ + public function showTitle() { + return !$this->rankImage || !$this->hideTitle; + } } diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 7214041640..ae009a2081 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -2084,6 +2084,9 @@ Wenn {if LANGUAGE_USE_INFORMAL_VARIANT}du{else}Sie{/if} unter „Konfiguration {$userRank->rankTitle|language} wirklich löschen?]]> + + + diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index b27cfb9920..b718eeda8f 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -2027,6 +2027,9 @@ You can define the default sender in “Configuration » Options » General » E {$userRank->rankTitle|language}?]]> + + + diff --git a/wcfsetup/setup/db/install.sql b/wcfsetup/setup/db/install.sql index 0d570c7f31..17289be071 100644 --- a/wcfsetup/setup/db/install.sql +++ b/wcfsetup/setup/db/install.sql @@ -1706,7 +1706,8 @@ CREATE TABLE wcf1_user_rank ( cssClassName VARCHAR(255) NOT NULL DEFAULT '', rankImage VARCHAR(255) NOT NULL DEFAULT '', repeatImage TINYINT(3) NOT NULL DEFAULT 1, - requiredGender TINYINT(1) NOT NULL DEFAULT 0 + requiredGender TINYINT(1) NOT NULL DEFAULT 0, + hideTitle TINYINT(1) NOT NULL DEFAULT 0 ); DROP TABLE IF EXISTS wcf1_user_storage; -- 2.20.1