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    public const STATUS_DRAFT = 'draft';
14    public const STATUS_APPROVED = 'approved';
15    public const STATUS_PUBLISHED = 'published';
16
17    // an action transitions a page from one status to another
18    public const ACTION_APPROVE = 'approve';
19    public const ACTION_PUBLISH = 'publish';
20
21    /**
22     * Convenience function mapping transition actions to resulting status
23     *
24     * @param string $action
25     * @return string
26     */
27    public static function transitionBy($action)
28    {
29        $map = [
30            self::ACTION_APPROVE => self::STATUS_APPROVED,
31            self::ACTION_PUBLISH => self::STATUS_PUBLISHED,
32        ];
33
34        return $map[$action];
35    }
36
37    public static function workflowSteps($action)
38    {
39        $map = [
40            self::ACTION_APPROVE => [
41                'fromStatus' => self::STATUS_DRAFT,
42                'currentStatus' => self::STATUS_APPROVED,
43                'toStatus' => self::STATUS_PUBLISHED,
44                'previousAction' => null,
45                'nextAction' => self::ACTION_PUBLISH
46            ],
47            self::ACTION_PUBLISH => [
48                'fromStatus' => self::STATUS_APPROVED,
49                'currentStatus' => self::STATUS_PUBLISHED,
50                'toStatus' => null,
51                'previousAction' => self::ACTION_APPROVE,
52                'nextAction' => null
53            ],
54        ];
55
56        return $map[$action];
57    }
58}
59