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
27 changes: 27 additions & 0 deletions wcfsetup/install/files/acp/templates/categoryNodeTreeView.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{include file='header'}

<header class="contentHeader">
<div class="contentHeaderTitle">
<h1 class="contentTitle">{unsafe:$objectType->getProcessor()->getLanguageVariable('list')}</h1>
</div>

{hascontent}
<nav class="contentHeaderNavigation">
<ul>
{content}
{if $objectType->getProcessor()->canAddCategory()}
<li><a href="{$addFormLink}" class="button">{icon name='plus'} <span>{unsafe:$objectType->getProcessor()->getLanguageVariable('add')}</span></a></li>
{/if}

{event name='contentHeaderNavigation'}
{/content}
</ul>
</nav>
{/hascontent}
</header>

<div class="section">
{unsafe:$nodeTreeView->render()}
</div>

{include file='footer'}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ abstract class CategoryAddFormBuilderForm extends AbstractFormBuilderForm
*/
public int $packageID = 0;

/**
* id of the pre-selected parent category, read from the request
* @since 6.3
*/
public ?int $parentCategoryID = null;

/**
* language item with the page title
* @deprecated 6.3 No longer in use.
Expand Down Expand Up @@ -157,6 +163,14 @@ public function readParameters()
if ($this->formAction !== 'create') {
$this->readFormObject();
}

if (isset($_GET['parentCategoryID'])) {
$parentCategoryID = \intval($_GET['parentCategoryID']);
$category = CategoryHandler::getInstance()->getCategory($parentCategoryID);
if ($category !== null && $category->objectTypeID === $this->objectType->getObjectID()) {
$this->parentCategoryID = $parentCategoryID;
}
}
}

#[\Override]
Expand Down Expand Up @@ -265,6 +279,7 @@ protected function getPositionFormFields(): array
)
->options($categoryNodeTree, true)
->available((bool)$this->getObjectTypeProcessor()->getMaximumNestingLevel())
->value($this->parentCategoryID)
->addValidator(
new FormFieldValidator(
'recursion',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* @author Matthias Schmidt
* @copyright 2001-2019 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @deprecated 6.3 Use `AbstractCategoryNodeTreeViewPage` instead.
*/
abstract class AbstractCategoryListPage extends AbstractPage
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

namespace wcf\acp\page;

use wcf\data\object\type\ObjectType;
use wcf\page\AbstractNodeTreeViewPage;
use wcf\system\category\CategoryHandler;
use wcf\system\exception\InvalidObjectTypeException;
use wcf\system\nodeTreeView\admin\CategoryNodeTreeView;
use wcf\system\request\LinkHandler;
use wcf\system\WCF;

/**
* Abstract implementation of a page that lists all categories of a certain object type using a node tree view.
*
* @author Marcel Werk
* @copyright 2001-2026 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @since 6.3
*
* @extends AbstractNodeTreeViewPage<CategoryNodeTreeView>
*/
abstract class AbstractCategoryNodeTreeViewPage extends AbstractNodeTreeViewPage
{
/**
* language item with the page title
*/
public string $pageTitle = 'wcf.category.list';

/**
* category object type object
*/
public ?ObjectType $objectType = null;

/**
* name of the category object type
*/
public string $objectTypeName = '';

/**
* @inheritDoc
*/
public $templateName = 'categoryNodeTreeView';

#[\Override]
public function readData()
{
$this->objectType = CategoryHandler::getInstance()->getObjectTypeByName($this->objectTypeName);
if ($this->objectType === null) {
throw new InvalidObjectTypeException($this->objectTypeName, 'com.woltlab.wcf.category');
}

parent::readData();
}

#[\Override]
public function assignVariables()
{
parent::assignVariables();

WCF::getTPL()->assign([
'objectType' => $this->objectType,
'addFormLink' => LinkHandler::getInstance()->getControllerLink($this->objectType->getProcessor()->getAddControllerClass()),
]);

if ($this->pageTitle) {
WCF::getTPL()->assign('pageTitle', $this->pageTitle);
}
}

#[\Override]
protected function createNodeTreeView(): CategoryNodeTreeView
{
return new CategoryNodeTreeView($this->objectTypeName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @copyright 2001-2019 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
*/
class ArticleCategoryListPage extends AbstractCategoryListPage
class ArticleCategoryListPage extends AbstractCategoryNodeTreeViewPage
{
/**
* @inheritDoc
Expand All @@ -19,7 +19,7 @@ class ArticleCategoryListPage extends AbstractCategoryListPage
/**
* @inheritDoc
*/
public $objectTypeName = 'com.woltlab.wcf.article.category';
public string $objectTypeName = 'com.woltlab.wcf.article.category';

/**
* @inheritDoc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @copyright 2001-2019 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
*/
class MediaCategoryListPage extends AbstractCategoryListPage
class MediaCategoryListPage extends AbstractCategoryNodeTreeViewPage
{
/**
* @inheritDoc
Expand All @@ -19,5 +19,5 @@ class MediaCategoryListPage extends AbstractCategoryListPage
/**
* @inheritDoc
*/
public $objectTypeName = 'com.woltlab.wcf.media.category';
public string $objectTypeName = 'com.woltlab.wcf.media.category';
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @copyright 2001-2019 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
*/
class SmileyCategoryListPage extends AbstractCategoryListPage
class SmileyCategoryListPage extends AbstractCategoryNodeTreeViewPage
{
/**
* @inheritDoc
Expand All @@ -19,7 +19,7 @@ class SmileyCategoryListPage extends AbstractCategoryListPage
/**
* @inheritDoc
*/
public $objectTypeName = 'com.woltlab.wcf.bbcode.smiley';
public string $objectTypeName = 'com.woltlab.wcf.bbcode.smiley';

/**
* @inheritDoc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @copyright 2001-2019 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
*/
class TrophyCategoryListPage extends AbstractCategoryListPage
class TrophyCategoryListPage extends AbstractCategoryNodeTreeViewPage
{
/**
* @inheritDoc
Expand All @@ -19,7 +19,7 @@ class TrophyCategoryListPage extends AbstractCategoryListPage
/**
* @inheritDoc
*/
public $objectTypeName = 'com.woltlab.wcf.trophy.category';
public string $objectTypeName = 'com.woltlab.wcf.trophy.category';

/**
* @inheritDoc
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace wcf\command\category;

use wcf\data\category\Category;
use wcf\data\category\CategoryEditor;
use wcf\event\category\CategoryDisabled;
use wcf\system\event\EventHandler;

/**
* Disables a category.
*
* @author Marcel Werk
* @copyright 2001-2026 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @since 6.3
*/
final class DisableCategory
{
public function __construct(private readonly Category $category) {}

public function __invoke(): void
{
(new CategoryEditor($this->category))->update([
'isDisabled' => 1,
]);

CategoryEditor::resetCache();

EventHandler::getInstance()->fire(
new CategoryDisabled($this->category)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace wcf\command\category;

use wcf\data\category\Category;
use wcf\data\category\CategoryEditor;
use wcf\event\category\CategoryEnabled;
use wcf\system\event\EventHandler;

/**
* Enables a category.
*
* @author Marcel Werk
* @copyright 2001-2026 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @since 6.3
*/
final class EnableCategory
{
public function __construct(private readonly Category $category) {}

public function __invoke(): void
{
(new CategoryEditor($this->category))->update([
'isDisabled' => 0,
]);

CategoryEditor::resetCache();

EventHandler::getInstance()->fire(
new CategoryEnabled($this->category)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

namespace wcf\command\category;

use wcf\data\category\CategoryEditor;
use wcf\system\category\CategoryHandler;
use wcf\system\WCF;

/**
* Sets the positions of categories.
*
* @author Marcel Werk
* @copyright 2001-2026 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @since 6.3
*/
final class SetCategoryPositions
{
/**
* @param array<int, list<int>> $positions
*/
public function __construct(private readonly array $positions) {}

public function __invoke(): void
{
$parentUpdates = [];
$objectType = null;

$sql = "UPDATE wcf1_category
SET parentCategoryID = ?,
showOrder = ?
WHERE categoryID = ?";
$statement = WCF::getDB()->prepare($sql);

WCF::getDB()->beginTransaction();
foreach ($this->positions as $parentCategoryID => $children) {
foreach ($children as $showOrder => $categoryID) {
$category = CategoryHandler::getInstance()->getCategory($categoryID);
if ($category === null) {
continue;
}

if ($objectType === null) {
$objectType = $category->getObjectType();
}

if ($category->parentCategoryID != $parentCategoryID) {
$parentUpdates[$categoryID] = [
'oldParentCategoryID' => $category->parentCategoryID,
'newParentCategoryID' => $parentCategoryID,
];
}

$statement->execute([
$parentCategoryID,
$showOrder + 1,
$categoryID,
]);
}
}
WCF::getDB()->commitTransaction();

CategoryEditor::resetCache();

if ($parentUpdates !== [] && $objectType !== null) {
$objectType->getProcessor()->changedParentCategories($parentUpdates);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace wcf\event\category;

use wcf\data\category\Category;
use wcf\event\IPsr14Event;

/**
* Indicates that a category has been disabled.
*
* @author Marcel Werk
* @copyright 2001-2026 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @since 6.3
*/
final class CategoryDisabled implements IPsr14Event
{
public function __construct(public readonly Category $category) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace wcf\event\category;

use wcf\data\category\Category;
use wcf\event\IPsr14Event;

/**
* Indicates that a category has been enabled.
*
* @author Marcel Werk
* @copyright 2001-2026 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @since 6.3
*/
final class CategoryEnabled implements IPsr14Event
{
public function __construct(public readonly Category $category) {}
}
Loading
Loading