DataHelper.php 1.53 KB
Newer Older
Dainis Abols's avatar
Dainis Abols committed
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
<?php

namespace Lu\LuStudyCatalogue\Helpers;

/**
 * Class DataHelper
 *
 * @author  Dainis Abols <dainis.abols@lu.lv>
 * @owner   University of Latvia
 * @version 2.0.0
 * @since   25.07.2018
 *
 * @package Lu\LuStudyCatalogue\Helpers
 */
class DataHelper
{
    /**
     * Localisation prefix
     */
    private $L10N_PREFIX = 'LLL:EXT:lu_study_catalogue/Resources/Private/Language/locallang.xlf';

    /**
     * Change language file location
     *
     * @param string $L10N_PREFIX
     */
    public function setL10NPrefix(string $L10N_PREFIX)
    {
        $this->L10N_PREFIX = $L10N_PREFIX;
    }

    /**
     * Decode API returned JSON or return null, if failed
     *
     * @param $jsonData
     *
     * @return string
     */
    public function APIDecode($jsonData)
    {
        // Decode result
        $decoded = json_decode($jsonData, true);
        if ($decoded['code'] == 200) {
            $data = $decoded['data'];
        } else {
            $data = null;
        }

        return $data;
    }

    /**
     * Retrieve language value for requested string
     * @TODO: Implement different language requests
     *
     * @param string $string
     *
     * @return string
     */
    public function getLangString(string $string): string
    {
        return $this->getLanguageService()->sL($this->L10N_PREFIX.':'.$string);
    }

    /**
     * Retrieve LanguageService
     *
Dainis Abols's avatar
Dainis Abols committed
68
     * @return mixed|\TYPO3\CMS\Core\Localization\LanguageService
Dainis Abols's avatar
Dainis Abols committed
69
70
71
72
73
74
     */
    private function getLanguageService()
    {
        return $GLOBALS['LANG'];
    }
}