xref: /plugin/structpublish/helper/db.php (revision bcee0e7291f5711195e679503d4d3a3c36e03575)
1<?php
2
3use dokuwiki\plugin\structpublish\meta\Assignments;
4
5class helper_plugin_structpublish_db extends helper_plugin_struct_db
6{
7
8    /**
9     * Get list of all pages known to the plugin
10     * @return array
11     */
12    public function getPages()
13    {
14        $sql = 'SELECT pid FROM titles';
15        $res = $this->sqlite->query($sql);
16        $list = $this->sqlite->res2arr($res);
17        $this->sqlite->res_close($res);
18        return array_column($list, 'pid');
19    }
20
21    /**
22     * Returns true if the current page is included in publishing workflows
23     *
24     * @return bool
25     */
26    public function isPublishable()
27    {
28        global $ID;
29
30        $sql = 'SELECT pid FROM structpublish_assignments WHERE pid = ? AND assigned = 1';
31        $res = $this->sqlite->query($sql, $ID);
32        if ($res && $this->sqlite->res2count($res)) {
33            return true;
34        }
35        return false;
36    }
37
38    /**
39     * Check if the current user has the given roles on the current page
40     *
41     * @param string $pid The page ID to check access for
42     * @param string[] $roles Roles needed. Empty for any role
43     * @return bool
44     */
45    public function checkAccess($pid, $roles = [])
46    {
47        return action_plugin_structpublish_sqlitefunction::userHasRole($pid, '', [], $roles);
48    }
49
50}
51