IsSlackOnlineViewhelper.php 1.15 KB
Newer Older
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
<?php
declare(strict_types = 1);

namespace T3o\T3omy\ViewHelpers;

use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;

/**
 * Class IsSlackOnlineViewhelper
 * @package T3o\T3omy\ViewHelpers
 */
class IsSlackOnlineViewhelper extends AbstractViewHelper
{
    /**
     * @var \T3o\T3oSlack\Domain\Repository\SlackUserRepository
     * @inject
     */
    public $slackUserRepository;

    /**
     * @var \T3o\T3oSlack\Domain\Repository\SlackFrontendUserRepository
     * @inject
     */
    public $slackFrontendUserRepository;

    /**
     * Checks if the user is online in slack
     *
     * @param int $frontendUserUID
     * @return string
     */
    public function render($frontendUserUID)
    {
        $feUser = $this->slackFrontendUserRepository->findByUid($frontendUserUID);
        $slackUser = $this->slackUserRepository->findBySlackId($feUser->getSlackId());

        if ($slackUser) {
            if ($slackUser->getPresence() === 'active') {
                $status = "slack-online";
            } else {
                $status = "slack-offline";
            }
        } else {
            $status = "no-slack";
        }
        return $status;
    }
}