ShowSlackLinkViewHelper.php 2 KB
Newer Older
Stefan Busemann's avatar
Stefan Busemann committed
1
<?php
2
declare(strict_types = 1);
Stefan Busemann's avatar
Stefan Busemann committed
3 4 5 6 7 8 9 10 11 12 13 14 15

namespace T3o\T3oSlack\ViewHelpers;

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

class ShowSlackLinkViewHelper extends AbstractViewHelper
{
    /**
     * @var \T3o\T3oSlack\Domain\Repository\SlackUserRepository
     * @inject
     */
    public $slackUserRepository;

16 17 18 19 20
    /**
     * @var \T3o\T3oSlack\Domain\Repository\SlackFrontendUserRepository
     * @inject
     */
    public $slackFrontendUserRepository;
21

Stefan Busemann's avatar
Stefan Busemann committed
22 23
    /**
     * Check if a property of the userprofile is visible in the current context
24
     *
Stefan Busemann's avatar
Stefan Busemann committed
25 26
     * @return string
     */
27
    public function render()
Stefan Busemann's avatar
Stefan Busemann committed
28
    {
29
        $feUser = $this->slackFrontendUserRepository->findByUid((int)$this->arguments['frontendUserUID']);
30
        $slackUser = $this->slackUserRepository->findBySlackId($feUser->getSlackId());
31

Stefan Busemann's avatar
Stefan Busemann committed
32
        if ($slackUser) {
33
            if ($slackUser->getPresence() === 'active') {
34
                $content = '<a href="https://typo3.slack.com/messages/' . $slackUser->getLink() . '" target="_blank">' . $slackUser->getSlackUserName() . ' </a>  Realname: ' . $slackUser->getRealName() . ' status: ' . $slackUser->getPresence();
35
            } else {
36
                $content = 'Slack username: ' . $slackUser->getSlackUserName() . ' Realname: ' . $slackUser->getRealName() . ' status: ' . $slackUser->getPresence();
37
            }
Stefan Busemann's avatar
Stefan Busemann committed
38
        } else {
39
            // @todo render link to register for slack
40
            if ($GLOBALS['TSFE']->fe_user->user['uid'] === (int)$this->arguments['frontendUserUID']) {
41 42
                // @todo add TS configuration
                $content = '<a href="https://my.typo3.org/?id=23">Get your TYPO3 Slack Account</a>';
43 44 45
            } else {
                $content = 'No Slack profile yet';
            }
Stefan Busemann's avatar
Stefan Busemann committed
46
        }
47

Stefan Busemann's avatar
Stefan Busemann committed
48 49
        return $content;
    }
50 51 52 53 54 55 56 57 58

    /**
     * Initialize
     */
    public function initializeArguments()
    {
        parent::initializeArguments();
        $this->registerArgument('frontendUserUID', 'integer', 'UID of the FrontendUser which should get displayed');
    }
Stefan Busemann's avatar
Stefan Busemann committed
59
}