--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<data xmlns="http://www.woltlab.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.woltlab.com http://www.woltlab.com/XSD/vortex/templateListener.xsd">
+ <import>
+ <templatelistener name="articleSortField">
+ <environment>admin</environment>
+ <templatename>categoryAdd</templatename>
+ <eventname>dataFields</eventname>
+ <templatecode><![CDATA[{include file='__articleSortField'}]]></templatecode>
+ </templatelistener>
+ </import>
+ <delete>
+ <templatelistener name="articleShowOrder">
+ <environment>admin</environment>
+ <templatename>categoryAdd</templatename>
+ <eventname>dataFields</eventname>
+ </templatelistener>
+ </delete>
+</data>
--- /dev/null
+<dl>
+ <dt><label for="sortField">{lang}wcf.acp.article.category.sortField{/lang}</label></dt>
+ <dd>
+ <select name="sortField" id="sortField">
+ {foreach from=$availableSortFields item=availableSortField}
+ <option value="{$availableSortField}"{if $availableSortField === $sortField} selected{/if}>{lang}wcf.acp.article.category.sortField.{$availableSortField}{/lang}</option>
+ {/foreach}
+ </select>
+ <select name="sortOrder" id="sortOrder">
+ <option value="ASC"{if $sortOrder === 'ASC'} selected{/if}>{lang}wcf.global.sortOrder.ascending{/lang}</option>
+ <option value="DESC"{if $sortOrder === 'DESC'} selected{/if}>{lang}wcf.global.sortOrder.descending{/lang}</option>
+ </select>
+ </dd>
+</dl>
<?php
declare(strict_types=1);
namespace wcf\acp\form;
+use wcf\system\exception\UserInputException;
+use wcf\system\WCF;
+use wcf\util\StringUtil;
/**
* Shows the article category add form.
*
- * @author Marcel Werk
- * @copyright 2001-2018 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @package WoltLabSuite\Core\Acp\Form
- * @since 3.0
+ * @author Marcel Werk
+ * @copyright 2001-2018 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core\Acp\Form
+ * @since 3.0
*/
class ArticleCategoryAddForm extends AbstractCategoryAddForm {
/**
* @inheritDoc
*/
public $neededModules = ['MODULE_ARTICLE'];
+
+ /**
+ * @var string[]
+ * @since 3.2
+ */
+ public $availableSortFields = [
+ 'publicationDate',
+ 'title'
+ ];
+
+ /**
+ * @var string
+ * @since 3.2
+ */
+ public $sortField = 'publicationDate';
+
+ /**
+ * @var string
+ * @since 3.2
+ */
+ public $sortOrder = 'DESC';
+
+ /**
+ * @inheritDoc
+ */
+ public function readParameters() {
+ parent::readParameters();
+
+ if (isset($_POST['sortField'])) $this->sortField = StringUtil::trim($_POST['sortField']);
+ if (isset($_POST['sortOrder'])) $this->sortOrder = StringUtil::trim($_POST['sortOrder']);
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function validate() {
+ parent::validate();
+
+ if (!in_array($this->sortField, $this->availableSortFields)) {
+ throw new UserInputException('sortField');
+ }
+
+ if ($this->sortOrder !== 'ASC' && $this->sortOrder !== 'DESC') {
+ throw new UserInputException('sortOrder');
+ }
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function save() {
+ $this->additionalData['sortField'] = $this->sortField;
+ $this->additionalData['sortOrder'] = $this->sortOrder;
+
+ parent::save();
+
+ $this->sortField = 'publicationDate';
+ $this->sortOrder = 'DESC';
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function assignVariables() {
+ parent::assignVariables();
+
+ WCF::getTPL()->assign([
+ 'availableSortFields' => $this->availableSortFields,
+ 'sortField' => $this->sortField,
+ 'sortOrder' => $this->sortOrder
+ ]);
+ }
}
<?php
declare(strict_types=1);
namespace wcf\acp\form;
+use wcf\system\exception\UserInputException;
+use wcf\system\WCF;
+use wcf\util\StringUtil;
/**
* Shows the article category edit form.
*
- * @author Marcel Werk
- * @copyright 2001-2018 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @package WoltLabSuite\Core\Acp\Form
- * @since 3.0
+ * @author Marcel Werk
+ * @copyright 2001-2018 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core\Acp\Form
+ * @since 3.0
*/
class ArticleCategoryEditForm extends AbstractCategoryEditForm {
/**
* @inheritDoc
*/
public $neededModules = ['MODULE_ARTICLE'];
+
+ /**
+ * @var string[]
+ * @since 3.2
+ */
+ public $availableSortFields = [
+ 'publicationDate',
+ 'title'
+ ];
+
+ /**
+ * @var string
+ * @since 3.2
+ */
+ public $sortField = 'publicationDate';
+
+ /**
+ * @var string
+ * @since 3.2
+ */
+ public $sortOrder = 'DESC';
+
+ /**
+ * @inheritDoc
+ */
+ public function readParameters() {
+ parent::readParameters();
+
+ if (isset($_POST['sortField'])) $this->sortField = StringUtil::trim($_POST['sortField']);
+ if (isset($_POST['sortOrder'])) $this->sortOrder = StringUtil::trim($_POST['sortOrder']);
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function validate() {
+ parent::validate();
+
+ if (!in_array($this->sortField, $this->availableSortFields)) {
+ throw new UserInputException('sortField');
+ }
+
+ if ($this->sortOrder !== 'ASC' && $this->sortOrder !== 'DESC') {
+ throw new UserInputException('sortOrder');
+ }
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function readData() {
+ parent::readData();
+
+ if (empty($_POST)) {
+ /** @noinspection PhpUndefinedFieldInspection */
+ $this->sortField = ($this->category->sortField ?: 'publicationDate');
+ /** @noinspection PhpUndefinedFieldInspection */
+ $this->sortOrder = ($this->category->sortOrder ?: 'DESC');
+ }
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function save() {
+ $this->additionalData['sortField'] = $this->sortField;
+ $this->additionalData['sortOrder'] = $this->sortOrder;
+
+ parent::save();
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function assignVariables() {
+ parent::assignVariables();
+
+ WCF::getTPL()->assign([
+ 'availableSortFields' => $this->availableSortFields,
+ 'sortField' => $this->sortField,
+ 'sortOrder' => $this->sortOrder
+ ]);
+ }
}
* @method ArticleCategory getParentCategory()
* @method ArticleCategory[] getParentCategories()
* @method static ArticleCategory|null getCategory($categoryID)
+ * @property-read string $sortField
+ * @property-read string $sortOrder
*/
class ArticleCategory extends AbstractDecoratedCategory implements IAccessibleObject, ITitledLinkObject {
/**
$this->canonicalURL = LinkHandler::getInstance()->getLink('CategoryArticleList', [
'object' => $this->category
], ($this->pageNo > 1 ? 'pageNo=' . $this->pageNo : ''));
+
+ if ($this->category->sortField) {
+ if ($this->category->sortField === 'title') {
+ $this->sortField = 'article_content.title';
+ $this->sortOrder = $this->category->sortOrder;
+ }
+ else {
+ $this->sortField = $this->category->sortField;
+ $this->sortOrder = $this->category->sortOrder;
+ }
+ }
}
/**
*/
protected function initObjectList() {
$this->objectList = new CategoryArticleList($this->categoryID, true);
+ if ($this->category->sortField === 'title') {
+ $this->objectList->sqlJoins .= ' LEFT JOIN wcf' . WCF_N . '_article_content article_content ON (article_content.articleID = article.articleID AND (
+ article_content.languageID IS NULL
+ OR article_content.languageID = ' . WCF::getLanguage()->languageID . '
+ ))';
+ }
$this->applyFilters();
}
<item name="wcf.acp.article.button.toggleI18n"><![CDATA[Mehrsprachigkeit]]></item>
<item name="wcf.acp.article.button.viewArticle"><![CDATA[Vorschau anzeigen]]></item>
<item name="wcf.acp.article.category"><![CDATA[Kategorie]]></item>
+ <item name="wcf.acp.article.category.sortField"><![CDATA[Sortierung]]></item>
+ <item name="wcf.acp.article.category.sortField.publicationDate"><![CDATA[Veröffentlichungsdatum]]></item>
+ <item name="wcf.acp.article.category.sortField.title"><![CDATA[Titel]]></item>
<item name="wcf.acp.article.content"><![CDATA[Inhalt]]></item>
<item name="wcf.acp.article.delete.confirmMessage"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Willst du{else}Wollen Sie{/if} {if $isArticleEdit|empty}den Artikel <span class="confirmationObject">{$article->getTitle()}</span>{else}diesen Artikel{/if} wirklich löschen?]]></item>
<item name="wcf.acp.article.enableComments"><![CDATA[Kommentare aktivieren]]></item>
<item name="wcf.acp.article.button.toggleI18n"><![CDATA[Internationalization]]></item>
<item name="wcf.acp.article.button.viewArticle"><![CDATA[Show Preview]]></item>
<item name="wcf.acp.article.category"><![CDATA[Category]]></item>
+ <item name="wcf.acp.article.category.sortField"><![CDATA[Show Order]]></item>
+ <item name="wcf.acp.article.category.sortField.publicationDate"><![CDATA[Publication Date]]></item>
+ <item name="wcf.acp.article.category.sortField.title"><![CDATA[Title]]></item>
<item name="wcf.acp.article.content"><![CDATA[Content]]></item>
<item name="wcf.acp.article.delete.confirmMessage"><![CDATA[Do you really want to delete {if $isArticleEdit|empty}the article <span class="confirmationObject">{$article->getTitle()}</span>{else}this article{/if}?]]></item>
<item name="wcf.acp.article.enableComments"><![CDATA[Enable comments]]></item>