FrontendUser.php 4.33 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
<?php

namespace T3o\Karma\Domain\Model;

/***************************************************************
 *  Copyright notice
 *
 *  (c) 2018
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
 *  free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  The GNU General Public License can be found at
 *  http://www.gnu.org/copyleft/gpl.html.
 *
 *  This script is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  This copyright notice MUST APPEAR in all copies of the script!
 ***************************************************************/

class FrontendUser extends \TYPO3\CMS\Extbase\Domain\Model\FrontendUser
{
    /**
     * Cached immutable karma total
     *
     * @var int
     */
35
    protected $karmaImmutableValueCache = 0;
36
37
38
39
40
41

    /**
     * Cached mutable karma total
     *
     * @var int
     */
42
    protected $karmaMutableValueCache = 0;
43
44
45
46
47
48

    /**
     * Karma total cache generation timestamp
     *
     * @var int
     */
mabolek's avatar
mabolek committed
49
    protected $karmaCacheTimestamp = 0;
50

51
52
53
54
55
56
57
58
59
60
61
62
    /**
     * JSON encoded associative array containing totals for the karma source
     *
     * @var string
     */
    protected $karmaSourceTotalCache = '';

    /**
     * @var array|null
     */
    private $karmaSourceTotalCacheDecoded;

63
64
65
66
67
    /**
     * Get the cached immutable karma total
     *
     * @return int
     */
68
    public function getKarmaImmutableValueCache(): int
69
    {
70
        return $this->karmaImmutableValueCache;
71
72
73
74
75
    }

    /**
     * Set cached immutable karma total
     *
76
     * @param int $karmaImmutableValueCache
77
     */
78
    public function setKarmaImmutableValueCache(int $karmaImmutableValueCache)
79
    {
80
        $this->karmaImmutableValueCache = $karmaImmutableValueCache;
81
82
83
84
85
86
87
    }

    /**
     * Get cached mutable karma total
     *
     * @return int
     */
88
    public function getKarmaMutableValueCache(): int
89
    {
90
        return $this->karmaMutableValueCache;
91
92
93
94
95
96
97
    }

    /**
     * Set cached mutable karma total
     *
     * @param int $karmaMutableValue
     */
98
    public function setKarmaMutableValueCache(int $karmaMutableValue)
99
    {
100
        $this->karmaMutableValueCache = $karmaMutableValue;
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
    }

    /**
     * Get karma total cache generation timestamp
     *
     * @return int
     */
    public function getKarmaCacheTimestamp(): int
    {
        return $this->karmaCacheTimestamp;
    }

    /**
     * Set karma total cache generation timestamp
     *
     * @param int $karmaCacheTimestamp
     */
    public function setKarmaCacheTimestamp(int $karmaCacheTimestamp)
    {
        $this->karmaCacheTimestamp = $karmaCacheTimestamp;
    }
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150

    /**
     * Get the JSON string containing the karma source total cache array
     *
     * @return string
     */
    public function getKarmaSourceTotalCache(): string
    {
        return $this->karmaSourceTotalCache;
    }

    /**
     * Set the JSON string containing the karma source total cache array
     *
     * @param string $karmaSourceTotalCache
     */
    public function setKarmaSourceTotalCache(string $karmaSourceTotalCache)
    {
        $this->karmaSourceTotalCache = $karmaSourceTotalCache;
    }

    /**
     * @return array|null
     */
    public function getKarmaSourceTotalCacheDecoded(): ?array
    {
        if ($this->karmaSourceTotalCacheDecoded === null) {
            $this->karmaSourceTotalCacheDecoded = json_decode($this->getKarmaSourceTotalCache());

mabolek's avatar
mabolek committed
151
            if (!is_array($this->karmaSourceTotalCacheDecoded)) {
152
153
154
155
156
157
158
159
160
161
162
                $this->karmaSourceTotalCacheDecoded = [];
                $this->setKarmaSourceTotalCache(json_encode($this->karmaSourceTotalCacheDecoded));
            }
        }

        return $this->karmaSourceTotalCacheDecoded;
    }

    /**
     * @param array|null $karmaSourceTotalCacheDecoded
     */
mabolek's avatar
mabolek committed
163
164
    public function setKarmaSourceTotalCacheDecoded(array $karmaSouceTotalDecoded)
    {
165
166
167
        $this->karmaSourceTotalCacheDecoded = $karmaSouceTotalDecoded;
        $this->setKarmaSourceTotalCache(json_encode($this->karmaSourceTotalCacheDecoded));
    }
mabolek's avatar
mabolek committed
168
}