Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/**
* Updates the database layout during the update from 6.2 to 6.3.
*
* @author Marcel Werk
* @copyright 2001-2026 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
*/

use wcf\system\database\table\column\DefaultFalseBooleanDatabaseTableColumn;
use wcf\system\database\table\PartialDatabaseTable;

return [
PartialDatabaseTable::create('wcf1_label_group')
->columns([
DefaultFalseBooleanDatabaseTableColumn::create('sortAlphabetically')
]),
];
13 changes: 10 additions & 3 deletions wcfsetup/install/files/acp/templates/labelGroupAdd.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
<nav class="contentHeaderNavigation">
<ul>
{if $action == 'edit'}
<li><button type="button" class="button jsChangeShowOrder">{icon name='up-down'} <span>{lang}wcf.global.changeShowOrder{/lang}</span></button></li>
{if !$labelGroup->sortAlphabetically}
<li><button type="button" class="button jsChangeShowOrder">{icon name='up-down'} <span>{lang}wcf.global.changeShowOrder{/lang}</span></button></li>
{/if}
<li>
{unsafe:$interactionContextMenu->render()}
</li>
Expand Down Expand Up @@ -84,7 +86,12 @@
<dt></dt>
<dd><label><input type="checkbox" name="forceSelection" id="forceSelection" value="1"{if $labelForceSelection} checked{/if}> {lang}wcf.acp.label.group.forceSelection{/lang}</label></dd>
</dl>


<dl>
<dt></dt>
<dd><label><input type="checkbox" name="sortAlphabetically" id="sortAlphabetically" value="1"{if $sortAlphabetically} checked{/if}> {lang}wcf.acp.label.group.sortAlphabetically{/lang}</label></dd>
</dl>

<dl id="groupPermissions">
<dt>{lang}wcf.acl.permissions{/lang}</dt>
<dd></dd>
Expand Down Expand Up @@ -125,7 +132,7 @@
</div>
</form>

{if $action == 'edit'}
{if $action == 'edit' && !$labelGroup->sortAlphabetically}
<script data-relocate="true">
require(["WoltLabSuite/Core/Component/ChangeShowOrder"], ({ setup }) => {
{jsphrase name='wcf.global.changeShowOrder'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class LabelGroupAddForm extends AbstractForm
*/
public $forceSelection = false;

public bool $sortAlphabetically = false;

/**
* group name
* @var string
Expand Down Expand Up @@ -113,6 +115,9 @@ public function readFormParameters()
if (isset($_POST['forceSelection'])) {
$this->forceSelection = true;
}
if (isset($_POST['sortAlphabetically'])) {
$this->sortAlphabetically = true;
}
if (isset($_POST['objectTypes']) && \is_array($_POST['objectTypes'])) {
$this->objectTypes = $_POST['objectTypes'];
}
Expand Down Expand Up @@ -179,6 +184,7 @@ public function save()
$this->objectAction = new LabelGroupAction([], 'create', [
'data' => \array_merge($this->additionalFields, [
'forceSelection' => $this->forceSelection ? 1 : 0,
'sortAlphabetically' => $this->sortAlphabetically ? 1 : 0,
'groupName' => $this->groupName,
'groupDescription' => $this->groupDescription,
'showOrder' => $this->showOrder,
Expand Down Expand Up @@ -216,6 +222,7 @@ public function save()

// reset values
$this->forceSelection = false;
$this->sortAlphabetically = false;
$this->groupName = $this->groupDescription = '';
$this->objectTypes = [];
$this->showOrder = 0;
Expand Down Expand Up @@ -246,6 +253,7 @@ public function assignVariables()
WCF::getTPL()->assign([
'action' => 'add',
'forceSelection' => $this->forceSelection,
'sortAlphabetically' => $this->sortAlphabetically,
'groupName' => $this->groupName,
'groupDescription' => $this->groupDescription,
'labelObjectTypeContainers' => $this->labelObjectTypeContainers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public function save()
[
'data' => \array_merge($this->additionalFields, [
'forceSelection' => $this->forceSelection ? 1 : 0,
'sortAlphabetically' => $this->sortAlphabetically ? 1 : 0,
'groupName' => $this->groupName,
'groupDescription' => $this->groupDescription,
'showOrder' => $this->showOrder,
Expand Down Expand Up @@ -119,6 +120,7 @@ public function readData()
I18nHandler::getInstance()->setOptions('groupName', 1, $this->group->groupName, 'wcf.acp.label.group\d+');

$this->forceSelection = ($this->group->forceSelection ? true : false);
$this->sortAlphabetically = ($this->group->sortAlphabetically ? true : false);
$this->groupName = $this->group->groupName;
$this->groupDescription = $this->group->groupDescription;
$this->showOrder = $this->group->showOrder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* @property-read string $groupName name of the label group or name of language item which contains the label text
* @property-read string $groupDescription description of the label group (only shown in ACP)
* @property-read 1|0 $forceSelection is `1` if a label in the label group has to be selected when creating an object for which the label group is available, otherwise `0`
* @property-read 1|0 $sortAlphabetically is `1` if labels in the label group are sorted alphabetically by their translated name, otherwise `0`
* @property-read int $showOrder position of the label group in relation to the other label groups
*/
class LabelGroup extends DatabaseObject implements IRouteController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,21 @@ public function search($objectID)
}
}

/**
* Sorts the labels alphabetically by their translated name using locale-aware comparison.
*
* @since 6.3
*/
public function sortLabelsAlphabetically(): void
{
$collator = new \Collator(WCF::getLanguage()->getLocale());
\uasort(
$this->labels,
static fn(Label $a, Label $b) => $collator->compare($a->getTitle(), $b->getTitle())
);
$this->indexToObject = \array_values(\array_keys($this->labels));
}

/**
* Returns true if any permissions have been set for this label group.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ protected function rebuild(array $parameters)
$data['options'] = $permissions['options']->getObjects();

// assign permissions for each label group
/** @var ViewableLabelGroup $group */
foreach ($data['groups'] as $groupID => $group) {
\assert($group instanceof ViewableLabelGroup);

// group permissions
if (isset($permissions['group'][$groupID])) {
$group->setGroupPermissions($permissions['group'][$groupID]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use wcf\http\Helper;
use wcf\system\endpoint\IController;
use wcf\system\endpoint\PostRequest;
use wcf\system\exception\IllegalLinkException;
use wcf\system\label\LabelHandler;
use wcf\system\showOrder\ShowOrderHandler;
use wcf\system\showOrder\ShowOrderItem;
Expand All @@ -32,6 +33,10 @@ public function __invoke(ServerRequestInterface $request, array $variables): Res
WCF::getSession()->checkPermissions(['admin.content.label.canManageLabel']);

$labelGroup = Helper::fetchObjectFromRequestParameter($variables['id'], LabelGroup::class);
if ($labelGroup->sortAlphabetically) {
throw new IllegalLinkException();
}

$items = \array_map(
static fn(Label $label) => new ShowOrderItem($label->labelID, $label->getTitle()),
LabelHandler::getInstance()->getLabelGroup($labelGroup->groupID)->getLabels()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use wcf\http\Helper;
use wcf\system\endpoint\GetRequest;
use wcf\system\endpoint\IController;
use wcf\system\exception\IllegalLinkException;
use wcf\system\label\LabelHandler;
use wcf\system\showOrder\ShowOrderHandler;
use wcf\system\showOrder\ShowOrderItem;
Expand All @@ -30,6 +31,10 @@ public function __invoke(ServerRequestInterface $request, array $variables): Res
WCF::getSession()->checkPermissions(['admin.content.label.canManageLabel']);

$labelGroup = Helper::fetchObjectFromRequestParameter($variables['id'], LabelGroup::class);
if ($labelGroup->sortAlphabetically) {
throw new IllegalLinkException();
}

$items = \array_map(
static fn(Label $label) => new ShowOrderItem($label->labelID, $label->getTitle()),
LabelHandler::getInstance()->getLabelGroup($labelGroup->groupID)->getLabels()
Expand Down
16 changes: 13 additions & 3 deletions wcfsetup/install/files/lib/system/label/LabelHandler.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ public function getLabelGroups(array $groupIDs = [], $validatePermissions = true
}
}

$data[$groupID] = $this->labelGroups['groups'][$groupID];
$data[$groupID] = $this->getLabelGroup($groupID);
}

// @phpstan-ignore argument.type
Expand Down Expand Up @@ -413,9 +413,19 @@ public function getAccessibleLabelIDs()
* @param int $groupID
* @return ViewableLabelGroup|null
*/
public function getLabelGroup($groupID)
public function getLabelGroup($groupID): ?ViewableLabelGroup
{
return $this->labelGroups['groups'][$groupID] ?? null;
if (!isset($this->labelGroups['groups'][$groupID])) {
return null;
}

$labelGroup = $this->labelGroups['groups'][$groupID];

if ($labelGroup->sortAlphabetically) {
$labelGroup->sortLabelsAlphabetically();
}

return $labelGroup;
}

/**
Expand Down
1 change: 1 addition & 0 deletions wcfsetup/install/lang/de.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,7 @@ Sie erreichen das Fehlerprotokoll unter: {link controller='ExceptionLogView' isE
<item name="wcf.acp.label.group.edit"><![CDATA[Labelgruppe bearbeiten]]></item>
<item name="wcf.acp.label.group.error.invalid"><![CDATA[Die gewählte Labelgruppe ist ungültig.]]></item>
<item name="wcf.acp.label.group.forceSelection"><![CDATA[Label aus dieser Gruppe muss zwingend ausgewählt werden]]></item>
<item name="wcf.acp.label.group.sortAlphabetically"><![CDATA[Labels alphabetisch sortieren]]></item>
<item name="wcf.acp.label.group.list"><![CDATA[Labelgruppen]]></item>
<item name="wcf.acp.label.group.permanentSelection"><![CDATA[Die ausgewählte Labelgruppe kann nachträglich nicht mehr verändert werden.]]></item>
<item name="wcf.acp.label.label"><![CDATA[Label]]></item>
Expand Down
1 change: 1 addition & 0 deletions wcfsetup/install/lang/en.xml
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,7 @@ You can access the error log at: {link controller='ExceptionLogView' isEmail=tru
<item name="wcf.acp.label.group.edit"><![CDATA[Edit Label Group]]></item>
<item name="wcf.acp.label.group.error.invalid"><![CDATA[The selected label group is invalid.]]></item>
<item name="wcf.acp.label.group.forceSelection"><![CDATA[Force selection of a label]]></item>
<item name="wcf.acp.label.group.sortAlphabetically"><![CDATA[Sort labels alphabetically]]></item>
<item name="wcf.acp.label.group.list"><![CDATA[Label Groups]]></item>
<item name="wcf.acp.label.group.permanentSelection"><![CDATA[The selected label group cannot be modified and is permanent for this label.]]></item>
<item name="wcf.acp.label.label"><![CDATA[Label]]></item>
Expand Down
1 change: 1 addition & 0 deletions wcfsetup/setup/db/install.sql
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,7 @@ CREATE TABLE wcf1_label_group (
groupName VARCHAR(80) NOT NULL,
groupDescription VARCHAR(255) NOT NULL DEFAULT '',
forceSelection TINYINT(1) NOT NULL DEFAULT 0,
sortAlphabetically TINYINT(1) NOT NULL DEFAULT 0,
showOrder INT(10) NOT NULL DEFAULT 0
);

Expand Down