* * @method static Label create(array $parameters = []) * @method Label getDecoratedObject() * @mixin Label */ class LabelEditor extends DatabaseObjectEditor implements IEditableCachedObject { /** * @inheritDoc */ protected static $baseClass = Label::class; /** * @inheritDoc */ public static function resetCache() { LabelCacheBuilder::getInstance()->reset(); } /** * Adds the label to a specific position in the label group. * * @param int $groupID * @param int $showOrder */ public function setShowOrder($groupID, $showOrder = 0) { // shift back labels in old label group with higher showOrder if ($this->showOrder) { $sql = "UPDATE wcf" . WCF_N . "_label SET showOrder = showOrder - 1 WHERE groupID = ? AND showOrder >= ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute([$this->groupID, $this->showOrder]); } // shift labels in new label group with higher showOrder if ($showOrder) { $sql = "UPDATE wcf" . WCF_N . "_label SET showOrder = showOrder + 1 WHERE groupID = ? AND showOrder >= ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute([$groupID, $showOrder]); } // get maximum existing show order $sql = "SELECT MAX(showOrder) FROM wcf" . WCF_N . "_label WHERE groupID = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute([$groupID]); $maxShowOrder = $statement->fetchSingleColumn() ?: 0; if (!$showOrder || $showOrder > $maxShowOrder) { $showOrder = $maxShowOrder + 1; } $this->update(['showOrder' => $showOrder]); } }