/
JoinqrcodeViewHelper.php
55 lines (47 loc) · 1.61 KB
/
JoinqrcodeViewHelper.php
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
<?php
namespace SmartNoses\Gpsnose\ViewHelpers\Community;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use SmartNoses\Gpsnose\Domain\Repository\MashupRepository;
use GpsNose\SDK\Framework\Logging\GnLogger;
use GpsNose\SDK\Mashup\Api\GnApi;
class JoinqrcodeViewHelper extends AbstractViewHelper
{
/**
* @var bool
*/
protected $escapeOutput = FALSE;
/**
* @return void
*/
public function initializeArguments()
{
$this->registerArgument('tag', 'string', 'name of the community', TRUE, '');
}
/**
* @return string
*/
public function render()
{
$tag = $this->arguments['tag'];
try {
$visibility = substr($tag, 0, 1);
list ($community) = explode('@', substr($tag, 1));
$community = $visibility . $community;
$mashupRepository = GeneralUtility::makeInstance(MashupRepository::class);
if ($mashupRepository) {
$mashup = $mashupRepository->findByCommunityTag($community);
if ($mashup) {
$gnApi = new GnApi();
$gnLoginApi = $gnApi->GetLoginApiForEndUser($mashup->getAppKey(), NULL, NULL);
$bytes = $gnLoginApi->GetCommunityApi()->GenerateQrCodeForCommunityJoin($tag);
$base64 = base64_encode($bytes);
return "<img src=\"data:image/png;base64,{$base64}\" />";
}
}
} catch (\Exception $e) {
GnLogger::Error($e->getMessage());
}
return NULL;
}
}