Merge branch '5.2' into 5.3
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / acp / form / ArticleCategoryAddForm.class.php
1 <?php
2 namespace wcf\acp\form;
3 use wcf\system\exception\UserInputException;
4 use wcf\system\request\LinkHandler;
5 use wcf\system\WCF;
6 use wcf\util\StringUtil;
7
8 /**
9 * Shows the article category add form.
10 *
11 * @author Marcel Werk
12 * @copyright 2001-2019 WoltLab GmbH
13 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
14 * @package WoltLabSuite\Core\Acp\Form
15 * @since 3.0
16 */
17 class ArticleCategoryAddForm extends AbstractCategoryAddForm {
18 /**
19 * @inheritDoc
20 */
21 public $activeMenuItem = 'wcf.acp.menu.link.article.category.add';
22
23 /**
24 * @inheritDoc
25 */
26 public $objectTypeName = 'com.woltlab.wcf.article.category';
27
28 /**
29 * @inheritDoc
30 */
31 public $neededModules = ['MODULE_ARTICLE'];
32
33 /**
34 * @var string[]
35 * @since 5.2
36 */
37 public $availableSortFields = [
38 'publicationDate',
39 'title'
40 ];
41
42 /**
43 * @var string
44 * @since 5.2
45 */
46 public $sortField = 'publicationDate';
47
48 /**
49 * @var string
50 * @since 5.2
51 */
52 public $sortOrder = 'DESC';
53
54 /**
55 * @inheritDoc
56 */
57 public function readParameters() {
58 parent::readParameters();
59
60 if (isset($_POST['sortField'])) $this->sortField = StringUtil::trim($_POST['sortField']);
61 if (isset($_POST['sortOrder'])) $this->sortOrder = StringUtil::trim($_POST['sortOrder']);
62 }
63
64 /**
65 * @inheritDoc
66 */
67 public function validate() {
68 parent::validate();
69
70 if (!in_array($this->sortField, $this->availableSortFields)) {
71 throw new UserInputException('sortField');
72 }
73
74 if ($this->sortOrder !== 'ASC' && $this->sortOrder !== 'DESC') {
75 throw new UserInputException('sortOrder');
76 }
77 }
78
79 /**
80 * @inheritDoc
81 */
82 public function save() {
83 $this->additionalData['sortField'] = $this->sortField;
84 $this->additionalData['sortOrder'] = $this->sortOrder;
85
86 parent::save();
87
88 WCF::getTPL()->assign([
89 'objectEditLink' => LinkHandler::getInstance()->getControllerLink(ArticleCategoryEditForm::class, ['id' => $this->objectAction->getReturnValues()['returnValues']->categoryID]),
90 ]);
91
92 $this->sortField = 'publicationDate';
93 $this->sortOrder = 'DESC';
94 }
95
96 /**
97 * @inheritDoc
98 */
99 public function assignVariables() {
100 parent::assignVariables();
101
102 WCF::getTPL()->assign([
103 'availableSortFields' => $this->availableSortFields,
104 'sortField' => $this->sortField,
105 'sortOrder' => $this->sortOrder
106 ]);
107 }
108 }