xref: /plugin/structpublish/meta/Revision.php (revision c2f8a3c436c4e9b483f84c9901319c1d150026a8)
1<?php
2
3namespace dokuwiki\plugin\structpublish\meta;
4
5class Revision
6{
7    const STATUS_DRAFT = 'draft';
8    const STATUS_APPROVED = 'approved';
9    const STATUS_PUBLISHED = 'published';
10
11    protected $sqlite;
12    protected $id;
13    protected $rev;
14    protected $status;
15    protected $version;
16    protected $user;
17
18    /**
19     * @param $sqlite
20     * @param $id
21     * @param null $rev
22     */
23    public function __construct($sqlite, $id, $rev = null)
24    {
25        $this->sqlite = $sqlite;
26        $this->id = $id;
27        $this->rev = $rev;
28
29        // FIXME check revision too
30        $sql = 'SELECT * FROM structpublish_revisions WHERE id = ? ORDER BY rev LIMIT 1';
31        $res = $sqlite->query($sql, $id);
32        $vals = $sqlite->res2row($res);
33        $this->rev = $vals['rev'] ?? null;
34        $this->status = $vals['status'] ?? null;
35        $this->version = $vals['version'] ?? 0;
36        $this->user = $vals['user'] ?? null;
37    }
38
39    public function save()
40    {
41        $sql = 'INSERT INTO structpublish_revisions (id, rev, status, version, user) VALUES (?,?,?,?,?)';
42        $res = $this->sqlite->query(
43            $sql,
44            $this->id,
45            $this->rev,
46            $this->status,
47            $this->version,
48            $this->user
49        );
50    }
51
52    /**
53     * @return mixed
54     */
55    public function getId()
56    {
57        return $this->id;
58    }
59
60    /**
61     * @return mixed
62     */
63    public function getVersion()
64    {
65        return $this->version;
66    }
67
68    /**
69     * @param mixed $version
70     */
71    public function setVersion($version): void
72    {
73        $this->version = $version;
74    }
75
76    /**
77     * @return mixed|null
78     */
79    public function getRev()
80    {
81        return $this->rev;
82    }
83
84    /**
85     * @param mixed|null $rev
86     */
87    public function setRev($rev): void
88    {
89        $this->rev = $rev;
90    }
91
92    /**
93     * @return mixed
94     */
95    public function getStatus()
96    {
97        return $this->status ?? self::STATUS_DRAFT;
98    }
99
100    /**
101     * @param mixed $status
102     */
103    public function setStatus($status): void
104    {
105        $this->status = $status;
106    }
107
108    /**
109     * @return mixed
110     */
111    public function getUser()
112    {
113        return $this->user;
114    }
115
116    /**
117     * @param mixed $user
118     */
119    public function setUser($user): void
120    {
121        $this->user = $user;
122    }
123}
124