xref: /plugin/structpublish/meta/Constants.php (revision d93c534ab70dab6913cef90024efe0b98384883d)
1<?php
2
3namespace dokuwiki\plugin\structpublish\meta;
4
5/**
6 * Defines some constants used throughout the plugin
7 *
8 * @todo this might need to be replaced later if we want to have user configurable status
9 */
10class Constants
11{
12    // a page can be in one current status
13    const STATUS_DRAFT = 'draft';
14    const STATUS_APPROVED = 'approved';
15    const STATUS_PUBLISHED = 'published';
16
17    // an action transitions a page from one status to another
18    const ACTION_APPROVE = 'approve';
19    const ACTION_PUBLISH = 'publish';
20
21
22    /**
23     * Convenience function mapping transition actions to resulting status
24     *
25     * @param string $action
26     * @return string
27     */
28    public static function transitionBy($action)
29    {
30        $map = [
31            self::ACTION_APPROVE => self::STATUS_APPROVED,
32            self::ACTION_PUBLISH => self::STATUS_PUBLISHED,
33        ];
34
35        return $map[$action];
36    }
37
38    public static function workflowSteps($action)
39    {
40        $map = [
41            self::ACTION_APPROVE => [
42                'fromStatus' => self::STATUS_DRAFT,
43                'currentStatus' => self::STATUS_APPROVED,
44                'toStatus' => self::STATUS_PUBLISHED,
45                'previousAction' => null,
46                'nextAction' => self::ACTION_PUBLISH
47            ],
48            self::ACTION_PUBLISH => [
49                'fromStatus' => self::STATUS_APPROVED,
50                'currentStatus' => self::STATUS_PUBLISHED,
51                'toStatus' => null,
52                'previousAction' => self::ACTION_APPROVE,
53                'nextAction' => null
54            ],
55        ];
56
57        return $map[$action];
58    }
59}
60