aboutsummaryrefslogtreecommitdiff
path: root/app/controllers/course/messenger.php
blob: 47d302ecf0f54dfbf17a606addbd8d9b6f09bf1e (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
72
73
74
75
76
77
78
79
80
81
82
83
<?php
class Course_MessengerController extends AuthenticatedController
{
    public function before_filter(&$action, &$args)
    {
        parent::before_filter($action, $args);

        PageLayout::setBodyElementId('blubber-index');
        PageLayout::setHelpKeyword("Basis/InteraktionBlubber");
    }

    public function course_action($thread_id = null)
    {
        if (Context::get()) {
            PageLayout::setTitle(Context::get()->getFullname() . ' - ' . _('Blubber'));
        }

        if (Navigation::hasItem('/course/blubber')) {
            Navigation::activateItem('/course/blubber');
        }

        $this->threads = BlubberThread::findByContext(Context::get()->id, true, Context::getType());
        $this->thread = null;
        $this->threads_more_down = 0;

        if (!$thread_id) {
            $thread_id = $GLOBALS['user']->cfg->BLUBBER_DEFAULT_THREAD;
        }
        if ($thread_id) {
            foreach ($this->threads as $thread) {
                if ($thread->getId() === $thread_id) {
                    $this->thread = $thread;
                    break;
                }
            }
        }
        if (!$this->thread || Request::get("thread") === "new") {
            $threads = array_reverse($this->threads);
            $this->thread = array_pop($threads);
        }
        $this->thread->markAsRead();

        $this->thread_data = $this->thread->getJSONData();
        $_SESSION['already_asked_for_avatar'] = false;
        if (!Avatar::getAvatar($GLOBALS['user']->id)->is_customized() && !$_SESSION['already_asked_for_avatar']) {
            $_SESSION['already_asked_for_avatar'] = true;
            PageLayout::postInfo(sprintf(_("Wollen Sie ein Avatar-Bild nutzen? %sLaden Sie jetzt ein Bild hoch%s."), '<a href="'.URLHelper::getURL("dispatch.php/avatar/update/user/".$GLOBALS['user']->id).'" data-dialog>', '</a>'));
        }
        $this->buildSidebar();

        if (Request::isDialog()) {
            PageLayout::setTitle($this->thread->getName());
            $this->render_template('blubber/dialog');
        } else {
            $this->render_template('blubber/index', $this->layout);
        }
    }

    protected function buildSidebar()
    {
        $sidebar = Sidebar::Get();
        $search = new SearchWidget("#");
        $search->addNeedle(
            _("Suche nach ..."),
            "search",
            true,
            null,
            null,
            null,
            []
        );
        $sidebar->addWidget($search, "blubbersearch");

        $threads_widget = new BlubberThreadsWidget();
        foreach ($this->threads as $thread) {
            $threads_widget->addThread($thread);
        }
        if ($this->thread) {
            $threads_widget->setActive($this->thread->getId());
        }
        $sidebar->addWidget($threads_widget, "threads");
    }
}