xref: /plugin/acknowledge/admin/assign.php (revision 2cc1fbc1a551b6bb2d5662a34e2fba2febc8b0d9)
1<?php
2
3use dokuwiki\Form\Form;
4
5/**
6 * DokuWiki Plugin acknowledge (Admin Component)
7 *
8 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
9 * @author  Andreas Gohr, Anna Dabrowska <dokuwiki@cosmocode.de>
10 */
11class admin_plugin_acknowledge_assign extends \dokuwiki\Extension\AdminPlugin
12{
13    /** @inheritdoc */
14    public function forAdminOnly()
15    {
16        return false;
17    }
18
19    /** @inheritDoc */
20    public function getMenuText($language)
21    {
22        return $this->getLang('menu_assign');
23    }
24
25
26    /** @inheritDoc */
27    public function handle()
28    {
29        global $INPUT;
30
31        /** @var helper_plugin_acknowledge $helper */
32        $helper = plugin_load('helper', 'acknowledge');
33
34        $pattern = $INPUT->arr('pattern');
35        $assignees = $INPUT->arr('assignees');
36        $patterns = array_combine($pattern, $assignees);
37
38        if ($patterns && checkSecurityToken()) {
39            $helper->saveAssignmentPatterns($patterns);
40        }
41
42    }
43
44    /** @inheritDoc */
45    public function html()
46    {
47        echo $this->locale_xhtml('assign');
48
49        /** @var helper_plugin_acknowledge $helper */
50        $helper = plugin_load('helper', 'acknowledge');
51
52        $assignments = $helper->getAssignmentPatterns();
53
54        $form = new Form(['method' => 'post']);
55        $form->setHiddenField('do', 'admin');
56        $form->setHiddenField('page', 'acknowledge_assign');
57        $form->addTagOpen('table');
58        $form->addTagOpen('tr');
59        $form->addTagOpen('th');
60        $form->addHTML($this->getLang('pattern'));
61        $form->addTagClose('th');
62        $form->addTagOpen('th');
63        $form->addHTML($this->getLang('assignees'));
64        $form->addTagClose('th');
65        $form->addTagClose('tr');
66        foreach ($assignments as $pattern => $assignees) {
67            $this->addRow($form, $pattern, $assignees);
68        }
69        $this->addRow($form, '', '');
70        $form->addTagClose('table');
71
72        $form->addButton('save', $this->getLang('save'));
73        echo $form->toHTML();
74    }
75
76    /**
77     * @param Form $form
78     * @param string $pattern
79     * @param string $assignee
80     * @return void
81     */
82    public function addRow($form, $pattern, $assignee)
83    {
84        static $row = 0;
85
86        $form->addTagOpen('tr');
87        $form->addTagOpen('td');
88        $form->addTextInput("pattern[$row]")->val($pattern);
89        $form->addTagClose('td');
90        $form->addTagOpen('td');
91        $form->addTextInput("assignees[$row]")->val($assignee);
92        $form->addTagClose('td');
93        $form->addTagClose('tr');
94        $row++;
95    }
96
97    /** @inheritDoc */
98    public function getTOC()
99    {
100        return (new admin_plugin_acknowledge_report())->getTOC();
101    }
102
103
104}
105
106