<select id="groupID" name="groupID">
<option value="0">{lang}wcf.global.noSelection{/lang}</option>
{foreach from=$labelGroupList item=group}
- <option value="{@$group->groupID}"{if $group->groupID == $groupID} selected="selected"{/if}>{$group->groupName}</option>
+ <option value="{@$group->groupID}"{if $group->groupID == $groupID} selected="selected"{/if}>{$group}</option>
{/foreach}
</select>
{if $errorField == 'groupID'}
{include file='aclPermissionJavaScript' containerID='groupPermissions' objectID=$groupID}
{/if}
+{assign var=labelForceSelection value=$forceSelection}
+
<header class="boxHeadline">
<h1>{lang}wcf.acp.label.group.{$action}{/lang}</h1>
</header>
<dl{if $errorField == 'groupName'} class="formError"{/if}>
<dt><label for="groupName">{lang}wcf.acp.label.group.groupName{/lang}</label></dt>
<dd>
- <input type="text" id="groupName" name="groupName" value="{$groupName}" autofocus="autofocus" class="long" />
+ <input type="text" id="groupName" name="groupName" value="{$i18nPlainValues['groupName']}" autofocus="autofocus" class="long" />
{if $errorField == 'groupName'}
<small class="innerError">
{if $errorType == 'empty'}
{/if}
</small>
{/if}
+ {include file='multipleLanguageInputJavascript' elementIdentifier='groupName' forceSelection=false}
+ </dd>
+ </dl>
+
+ <dl>
+ <dt><label for="showOrder">{lang}wcf.acp.label.group.showOrder{/lang}</label></dt>
+ <dd>
+ <input type="number" min="0" id="showOrder" name="showOrder" class="tiny" value="{if $showOrder}{@$showOrder}{/if}" />
</dd>
</dl>
<dl>
- <dt class="reversed"><label for="forceSelection">{lang}wcf.acp.label.group.forceSelection{/lang}</label></dt>
- <dd><input type="checkbox" name="forceSelection" id="forceSelection" value="1"{if $forceSelection} checked="checked"{/if} /></dd>
+ <dt></dt>
+ <dd><label><input type="checkbox" name="forceSelection" id="forceSelection" value="1"{if $labelForceSelection} checked="checked"{/if} /> {lang}wcf.acp.label.group.forceSelection{/lang}</label></dd>
</dl>
<dl id="groupPermissions">
<tr>
<th class="columnID columnLabelGroupID{if $sortField == 'groupID'} active {@$sortOrder}{/if}" colspan="2"><a href="{link controller='LabelGroupList'}pageNo={@$pageNo}&sortField=groupID&sortOrder={if $sortField == 'groupID' && $sortOrder == 'ASC'}DESC{else}ASC{/if}{/link}">{lang}wcf.global.objectID{/lang}</a></th>
<th class="columnTitle columnGroupName{if $sortField == 'groupName'} active {@$sortOrder}{/if}"><a href="{link controller='LabelGroupList'}pageNo={@$pageNo}&sortField=groupName&sortOrder={if $sortField == 'groupName' && $sortOrder == 'ASC'}DESC{else}ASC{/if}{/link}">{lang}wcf.acp.label.group.groupName{/lang}</a></th>
+ <th class="columnDigits columnShowOrder{if $sortField == 'showOrder'} active {@$sortOrder}{/if}"><a href="{link controller='LabelGroupList'}pageNo={@$pageNo}&sortField=showOrder&sortOrder={if $sortField == 'showOrder' && $sortOrder == 'ASC'}DESC{else}ASC{/if}{/link}">{lang}wcf.acp.label.group.showOrder{/lang}</a></th>
{event name='columnHeads'}
</tr>
{event name='rowButtons'}
</td>
<td class="columnID">{@$group->groupID}</td>
- <td class="columnTitle columnGroupName"><a href="{link controller='LabelGroupEdit' object=$group}{/link}">{$group->groupName}</a></td>
+ <td class="columnTitle columnGroupName"><a href="{link controller='LabelGroupEdit' object=$group}{/link}">{$group}</a></td>
+ <td class="columnDigits columnShowOrder">{@$group->showOrder}</td>
{event name='columns'}
</tr>
</td>
<td class="columnID">{@$label->labelID}</td>
<td class="columnTitle columnLabel"><a href="{link controller='LabelEdit' object=$label}{/link}" title="{$label}" class="badge label{if $label->getClassNames()} {$label->getClassNames()}{/if}">{$label}</a></td>
- <td class="columnText columnGroup">{$label->groupName}</td>
+ <td class="columnText columnGroup">{lang}{$label->groupName}{/lang}</td>
{event name='columns'}
</tr>
use wcf\form\AbstractForm;
use wcf\system\acl\ACLHandler;
use wcf\system\exception\UserInputException;
+use wcf\system\language\I18nHandler;
use wcf\system\WCF;
use wcf\util\StringUtil;
+use wcf\data\label\group\LabelGroupEditor;
/**
* Shows the label group add form.
*/
public $objectTypeID = 0;
+ /**
+ * show order
+ * @var integer
+ */
+ public $showOrder = 0;
+
/**
* @see \wcf\page\AbstractPage::readParameters()
*/
parent::readParameters();
$this->objectTypeID = ACLHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.label');
+
+ I18nHandler::getInstance()->register('groupName');
}
/**
public function readFormParameters() {
parent::readFormParameters();
+ I18nHandler::getInstance()->readValues();
+
+ if (I18nHandler::getInstance()->isPlainValue('groupName')) $this->groupName = I18nHandler::getInstance()->getValue('groupName');
+
if (isset($_POST['forceSelection'])) $this->forceSelection = true;
- if (isset($_POST['groupName'])) $this->groupName = StringUtil::trim($_POST['groupName']);
if (isset($_POST['objectTypes']) && is_array($_POST['objectTypes'])) $this->objectTypes = $_POST['objectTypes'];
+ if (isset($_POST['showOrder'])) $this->showOrder = intval($_POST['showOrder']);
}
/**
public function validate() {
parent::validate();
- // validate class name
- if (empty($this->groupName)) {
- throw new UserInputException('groupName');
+ // validate group name
+ try {
+ if (!I18nHandler::getInstance()->validateValue('groupName')) {
+ if (I18nHandler::getInstance()->isPlainValue('groupName')) {
+ throw new UserInputException('groupName');
+ }
+ else {
+ throw new UserInputException('groupName', 'multilingual');
+ }
+ }
+ }
+ catch (UserInputException $e) {
+ $this->errorType[$e->getField()] = $e->getType();
}
// validate object type relations
// save label
$this->objectAction = new LabelGroupAction(array(), 'create', array('data' => array_merge($this->additionalFields, array(
'forceSelection' => ($this->forceSelection ? 1 : 0),
- 'groupName' => $this->groupName
+ 'groupName' => $this->groupName,
+ 'showOrder' => $this->showOrder
))));
$returnValues = $this->objectAction->executeAction();
+ if (!I18nHandler::getInstance()->isPlainValue('groupName')) {
+ I18nHandler::getInstance()->save('groupName', 'wcf.acp.label.group'.$returnValues['returnValues']->groupID, 'wcf.acp.label', 1);
+
+ // update group name
+ $groupEditor = new LabelGroupEditor($returnValues['returnValues']);
+ $groupEditor->update(array(
+ 'groupName' => 'wcf.acp.label.group'.$returnValues['returnValues']->groupID
+ ));
+ }
+
// save acl
ACLHandler::getInstance()->save($returnValues['returnValues']->groupID, $this->objectTypeID);
ACLHandler::getInstance()->disableAssignVariables();
$this->forceSelection = false;
$this->groupName = '';
$this->objectTypes = array();
+ $this->showOrder = 0;
$this->setObjectTypeRelations();
// show success
WCF::getTPL()->assign(array(
'success' => true
));
+
+ I18nHandler::getInstance()->reset();
}
/**
parent::assignVariables();
ACLHandler::getInstance()->assignVariables($this->objectTypeID);
+ I18nHandler::getInstance()->assignVariables();
WCF::getTPL()->assign(array(
'action' => 'add',
'forceSelection' => $this->forceSelection,
'groupName' => $this->groupName,
'labelObjectTypeContainers' => $this->labelObjectTypeContainers,
- 'objectTypeID' => $this->objectTypeID
+ 'objectTypeID' => $this->objectTypeID,
+ 'showOrder' => $this->showOrder
));
}
use wcf\form\AbstractForm;
use wcf\system\acl\ACLHandler;
use wcf\system\exception\IllegalLinkException;
+use wcf\system\language\I18nHandler;
use wcf\system\WCF;
/**
public function save() {
AbstractForm::save();
+ $this->groupName = 'wcf.acp.label.group'.$this->group->groupID;
+ if (I18nHandler::getInstance()->isPlainValue('groupName')) {
+ I18nHandler::getInstance()->remove($this->groupName);
+ $this->groupName = I18nHandler::getInstance()->getValue('groupName');
+ }
+ else {
+ I18nHandler::getInstance()->save('groupName', $this->groupName, 'wcf.acp.label', 1);
+ }
+
// update label
$this->objectAction = new LabelGroupAction(array($this->groupID), 'update', array('data' => array_merge($this->additionalFields, array(
'forceSelection' => ($this->forceSelection ? 1 : 0),
- 'groupName' => $this->groupName
+ 'groupName' => $this->groupName,
+ 'showOrder' => $this->showOrder
))));
$this->objectAction->executeAction();
parent::readData();
if (empty($_POST)) {
+ I18nHandler::getInstance()->setOptions('groupName', 1, $this->group->groupName, 'wcf.acp.label.group\d+');
+
$this->forceSelection = ($this->group->forceSelection ? true : false);
$this->groupName = $this->group->groupName;
+ $this->showOrder = $this->group->showOrder;
}
}
public function assignVariables() {
parent::assignVariables();
+ I18nHandler::getInstance()->assignVariables(!empty($_POST));
+
WCF::getTPL()->assign(array(
'action' => 'edit',
'groupID' => $this->groupID,
/**
* @see \wcf\page\SortablePage::$defaultSortField
*/
- public $defaultSortField = 'groupName';
+ public $defaultSortField = 'showOrder';
/**
* @see \wcf\page\SortablePage::$validSortFields
*/
- public $validSortFields = array('groupID', 'groupName');
+ public $validSortFields = array('groupID', 'groupName', 'showOrder');
/**
* @see \wcf\page\AbstractPage::$neededPermissions
namespace wcf\data\label\group;
use wcf\data\DatabaseObject;
use wcf\system\request\IRouteController;
+use wcf\system\WCF;
/**
* Represents a label group.
* @see \wcf\data\ITitledObject::getTitle()
*/
public function getTitle() {
- return $this->groupName;
+ return WCF::getLanguage()->get($this->groupName);
+ }
+
+ /**
+ * Returns label group title.
+ *
+ * @return string
+ */
+ public function __toString() {
+ return $this->getTitle();
+ }
+
+ /**
+ * Callback for uasort() to sort label groups by show order and (if equal) group id.
+ *
+ * @param \wcf\data\DatabaseObject $groupA
+ * @param \wcf\data\DatabaseObject $groupB
+ * @return integer
+ */
+ public static function sortLabelGroups(DatabaseObject $groupA, DatabaseObject $groupB) {
+ if ($groupA->showOrder == $groupB->showOrder) {
+ return ($groupA->groupID > $groupB->groupID) ? 1 : -1;
+ }
+
+ return ($groupA->showOrder > $groupB->showOrder) ? 1 : -1;
}
}
* @see \wcf\data\DatabaseObjectList::$className
*/
public $className = 'wcf\data\label\group\LabelGroup';
+
+ /**
+ * @see \wcf\data\DatabaseObjectList::$sqlOrderBy
+ */
+ public $sqlOrderBy = 'label_group.showOrder ASC, label_group.groupID';
}
// get label groups
$groupList = new LabelGroupList();
- $groupList->sqlOrderBy = 'groupName';
$groupList->readObjects();
$groups = $groupList->getObjects();
foreach ($groups as &$group) {
}
}
+ // order label ids by label group
+ $labelGroups =& $this->labelGroups;
+ foreach ($data as &$labels) {
+ usort($labels, function($a, $b) use($labelGroups) {
+ $groupA = $labelGroups['groups'][$a->groupID];
+ $groupB = $labelGroups['groups'][$b->groupID];
+
+ if ($groupA->showOrder == $groupB->showOrder) {
+ return ($groupA->groupID > $groupB->groupID) ? 1 : -1;
+ }
+
+ return ($groupA->showOrder > $groupB->showOrder) ? 1 : -1;
+ });
+ }
+ unset($labels);
+
return $data;
}
$data[$groupID] = $this->labelGroups['groups'][$groupID];
}
+ uasort($data, function($a, $b) {
+ if ($a->showOrder == $b->showOrder) {
+ return ($a->groupID > $b->groupID) ? 1 : -1;
+ }
+
+ return ($a->showOrder > $b->showOrder) ? 1 : -1;
+ });
+
return $data;
}
$data[$groupID] = $this->labelGroups[$groupID];
}
+ uasort($data, array('\wcf\data\label\group\LabelGroup', 'sortLabelGroups'));
+
return $data;
}
/**
* @see \wcf\system\label\manager\ILabelObjectHandler::validateLabelIDs()
*/
- public function validateLabelIDs(array $labelIDs, $optionName = '') {
+ public function validateLabelIDs(array $labelIDs, $optionName = '', $legacyReturnValue = true) {
$optionID = 0;
if (!empty($optionName)) {
$optionID = LabelHandler::getInstance()->getOptionID($optionName);
}
}
+ $validationErrors = array();
$satisfiedGroups = array();
foreach ($labelIDs as $groupID => $labelID) {
// only one label per group is allowed
if (is_array($labelID)) {
- return false;
+ $validationErrors[$groupID] = 'invalid';
+ continue;
+ }
+
+ // label group id is unknown
+ if (!isset($this->labelGroups[$groupID])) {
+ $validationErrors[0] = 'invalid';
+ continue;
}
- // label group id is unknown or label id is invalid for this group
- if (!isset($this->labelGroups[$groupID]) || !$this->labelGroups[$groupID]->isValid($labelID)) {
- return false;
+ // label id is invalid for this group
+ if (!$this->labelGroups[$groupID]->isValid($labelID)) {
+ $validationErrors[$groupID] = 'invalid';
+ continue;
}
// check permission
if ($optionID && !$this->labelGroups[$groupID]->getPermission($optionID)) {
- return false;
+ $validationErrors[0] = 'invalid';
+ continue;
}
$satisfiedGroups[] = $groupID;
continue;
}
- return false;
+ $validationErrors[$labelGroup->groupID] = 'missing';
+ continue;
}
}
- return true;
+ if ($legacyReturnValue) {
+ // WCF 2.0: boolean true/false
+ return (empty($validationErrors));
+ }
+ else {
+ // WCF 2.1+: detailed error report (empty array if validation passed)
+ return $validationErrors;
+ }
}
/**
*
* @param array<integer> $labelIDs
* @param array $optionName
- * @return boolean
+ * @return mixed
*/
- public function validateLabelIDs(array $labelIDs, $optionName = '');
+ public function validateLabelIDs(array $labelIDs, $optionName = '', $legacyReturnValue = true);
/**
* Assigns labels to an object.
<item name="wcf.acp.label.group.edit"><![CDATA[Labelgruppe bearbeiten]]></item>
<item name="wcf.acp.label.group.error.notValid"><![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.groupName"><![CDATA[Gruppenname]]></item>
<item name="wcf.acp.label.group.list"><![CDATA[Labelgruppen]]></item>
+ <item name="wcf.acp.label.group.showOrder"><![CDATA[Reihenfolge]]></item>
<item name="wcf.acp.label.label"><![CDATA[Label]]></item>
<item name="wcf.acp.label.list"><![CDATA[Labels]]></item>
</category>
<category name="wcf.label">
<item name="wcf.label.all"><![CDATA[Alle]]></item>
+ <item name="wcf.label.error.missing"><![CDATA[Sie müssen ein Label auswählen.]]></item>
<item name="wcf.label.error.notValid"><![CDATA[Die Labelauswahl ist ungültig.]]></item>
<item name="wcf.label.label"><![CDATA[Label]]></item>
<item name="wcf.label.labels"><![CDATA[Labels]]></item>
<item name="wcf.acp.label.group.edit"><![CDATA[Edit Label Group]]></item>
<item name="wcf.acp.label.group.error.notValid"><![CDATA[Chosen 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.groupName"><![CDATA[Title]]></item>
<item name="wcf.acp.label.group.list"><![CDATA[Label Groups]]></item>
+ <item name="wcf.acp.label.group.showOrder"><![CDATA[Display Order]]></item>
<item name="wcf.acp.label.label"><![CDATA[Label]]></item>
<item name="wcf.acp.label.list"><![CDATA[Labels]]></item>
</category>
<category name="wcf.label">
<item name="wcf.label.all"><![CDATA[All]]></item>
+ <item name="wcf.label.error.missing"><![CDATA[You are required to select a label.]]></item>
<item name="wcf.label.error.notValid"><![CDATA[The label selection is invalid.]]></item>
<item name="wcf.label.label"><![CDATA[Label]]></item>
<item name="wcf.label.labels"><![CDATA[Labels]]></item>
CREATE TABLE wcf1_label_group (
groupID INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
groupName VARCHAR(80) NOT NULL,
- forceSelection TINYINT(1) NOT NULL DEFAULT 0
+ forceSelection TINYINT(1) NOT NULL DEFAULT 0,
+ showOrder INT(10) NOT NULL DEFAULT 0
);
DROP TABLE IF EXISTS wcf1_label_group_to_object;