-
Notifications
You must be signed in to change notification settings - Fork 149
Expand file tree
/
Copy pathCreateBoxToPageAssignments.class.php
More file actions
67 lines (61 loc) · 2.13 KB
/
CreateBoxToPageAssignments.class.php
File metadata and controls
67 lines (61 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
namespace wcf\command\box;
use wcf\data\box\Box;
use wcf\data\page\Page;
use wcf\system\WCF;
/**
* Assigns pages to a certain box.
*
* Note: The primary use of this command is to be used during package installation.
*
* @author Marcel Werk
* @copyright 2001-2024 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @since 6.2
*/
final class CreateBoxToPageAssignments
{
/**
* @param string[] $pageIdentifiers
*/
public function __construct(
private readonly string $boxIdentifier,
private readonly array $pageIdentifiers,
private readonly bool $visible = true,
) {}
/**
* @throws \InvalidArgumentException
*/
public function __invoke(): void
{
$box = Box::getBoxByIdentifier($this->boxIdentifier);
if ($box === null) {
throw new \InvalidArgumentException("Unknown box with identifier '{$this->boxIdentifier}'");
}
$pages = [];
foreach ($this->pageIdentifiers as $pageIdentifier) {
$page = Page::getPageByIdentifier($pageIdentifier);
if ($page === null) {
throw new \InvalidArgumentException("Unknown page with identifier '{$pageIdentifier}'");
}
$pages[] = $page;
}
if (($this->visible && $box->visibleEverywhere) || (!$this->visible && !$box->visibleEverywhere)) {
$sql = "DELETE FROM wcf1_box_to_page
WHERE boxID = ?
AND pageID = ?";
$statement = WCF::getDB()->prepare($sql);
foreach ($pages as $page) {
$statement->execute([$box->boxID, $page->pageID]);
}
} else {
$sql = "REPLACE INTO wcf1_box_to_page
(boxID, pageID, visible)
VALUES (?, ?, ?)";
$statement = WCF::getDB()->prepare($sql);
foreach ($pages as $page) {
$statement->execute([$box->boxID, $page->pageID, $this->visible ? 1 : 0]);
}
}
}
}