aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/Forum/BaseController.php
blob: 5a7e8f8937e6e9ad3008d6fb39558eb7c2fe58f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
namespace Forum;

use ActionsWidget;
use Context;
use CoreForum;
use Icon;
use Request;
use SearchWidget;
use Sidebar;
use StudipController;
use User;

abstract class BaseController extends StudipController
{
    protected $with_session = true;
    protected $is_admin = false;
    protected $is_moderator = false;

    public function before_filter(&$action, &$args): void
    {
        object_set_visit_module('forum');

        $this->range_id = Context::getId();
        $this->user_id = User::findCurrent()?->user_id;

        if ($this->user_id) {
            $this->is_admin = CoreForum::isAdmin($this->range_id);
            $this->is_moderator = CoreForum::isModerator($this->range_id);
        }

        $this->buildSidebar();
        parent::before_filter($action, $args);
    }

    protected function buildSidebar(): void
    {
        $actions = new ActionsWidget();

        if ($this->user_id) {
            $actions->addLink(
                _('Neue Diskussion starten'),
                $this->url_for('course/forum/discussions/edit'),
                Icon::create('add', Icon::ROLE_CLICKABLE, ['title' => _('Neue Diskussion starten')])
            )->asDialog('width=900;height=750');
        }

        if ($this->is_admin) {
            $actions->addLink(
                _('Forum verwalten'),
                $this->url_for('course/forum/configs/edit'),
                Icon::create('admin', Icon::ROLE_CLICKABLE, ['title' => _('Forum verwalten')])
            )->asDialog('width=500;height=350');
        }

        Sidebar::Get()->addWidget($actions);

        $search = new SearchWidget($this->url_for('course/forum/search', [
            'begin' => Request::int('begin'),
            'end' => Request::int('end')
        ]));

        $search->addNeedle(
            _('Suche nach Diskussionen oder Beiträge'),
            'q',
            true
        );

        Sidebar::Get()->addWidget($search, 'forum_search');
    }
}