Add EmailLogListPage
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / data / label / LabelEditor.class.php
CommitLineData
3b75466f 1<?php
a9229942 2
3b75466f 3namespace wcf\data\label;
a9229942 4
3b75466f
MW
5use wcf\data\DatabaseObjectEditor;
6use wcf\data\IEditableCachedObject;
7use wcf\system\cache\builder\LabelCacheBuilder;
d8475f48 8use wcf\system\WCF;
3b75466f
MW
9
10/**
11 * Provides functions to edit labels.
a9229942
TD
12 *
13 * @author Alexander Ebert
14 * @copyright 2001-2019 WoltLab GmbH
15 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
16 * @package WoltLabSuite\Core\Data\Label
17 *
18 * @method static Label create(array $parameters = [])
19 * @method Label getDecoratedObject()
20 * @mixin Label
3b75466f 21 */
a9229942
TD
22class LabelEditor extends DatabaseObjectEditor implements IEditableCachedObject
23{
24 /**
25 * @inheritDoc
26 */
27 protected static $baseClass = Label::class;
28
29 /**
30 * @inheritDoc
31 */
32 public static function resetCache()
33 {
34 LabelCacheBuilder::getInstance()->reset();
35 }
36
37 /**
38 * Adds the label to a specific position in the label group.
39 *
40 * @param int $groupID
41 * @param int $showOrder
42 */
43 public function setShowOrder($groupID, $showOrder = 0)
44 {
45 // shift back labels in old label group with higher showOrder
46 if ($this->showOrder) {
47 $sql = "UPDATE wcf" . WCF_N . "_label
48 SET showOrder = showOrder - 1
49 WHERE groupID = ?
50 AND showOrder >= ?";
51 $statement = WCF::getDB()->prepareStatement($sql);
52 $statement->execute([$this->groupID, $this->showOrder]);
53 }
54
55 // shift labels in new label group with higher showOrder
56 if ($showOrder) {
57 $sql = "UPDATE wcf" . WCF_N . "_label
58 SET showOrder = showOrder + 1
59 WHERE groupID = ?
60 AND showOrder >= ?";
61 $statement = WCF::getDB()->prepareStatement($sql);
62 $statement->execute([$groupID, $showOrder]);
63 }
64
65 // get maximum existing show order
66 $sql = "SELECT MAX(showOrder)
67 FROM wcf" . WCF_N . "_label
68 WHERE groupID = ?";
69 $statement = WCF::getDB()->prepareStatement($sql);
70 $statement->execute([$groupID]);
71 $maxShowOrder = $statement->fetchSingleColumn() ?: 0;
72
73 if (!$showOrder || $showOrder > $maxShowOrder) {
74 $showOrder = $maxShowOrder + 1;
75 }
76
77 $this->update(['showOrder' => $showOrder]);
78 }
3b75466f 79}