1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of GitterBot package. |
4
|
|
|
* |
5
|
|
|
* @author Serafim <[email protected]> |
6
|
|
|
* @date 09.10.2015 19:49 |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
namespace Interfaces\Gitter\Karma; |
12
|
|
|
|
13
|
|
|
use Domains\User; |
14
|
|
|
use Lang; |
15
|
|
|
|
16
|
|
|
class Status |
17
|
|
|
{ |
18
|
|
|
const STATUS_NOTHING = 2; |
19
|
|
|
const STATUS_INCREMENT = 4; |
20
|
|
|
const STATUS_TIMEOUT = 8; |
21
|
|
|
const STATUS_SELF = 16; |
22
|
|
|
const STATUS_NO_USER = 32; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var int |
26
|
|
|
*/ |
27
|
|
|
protected $status = self::STATUS_NOTHING; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var User |
31
|
|
|
*/ |
32
|
|
|
protected $user; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Status constructor. |
36
|
|
|
* @param User $mention |
37
|
|
|
* @param int $status |
38
|
|
|
*/ |
39
|
|
|
public function __construct(User $mention, $status = self::STATUS_NOTHING) |
40
|
|
|
{ |
41
|
|
|
$this->user = $mention; |
42
|
|
|
$this->status = $status; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @return bool |
47
|
|
|
*/ |
48
|
|
|
public function isNothing() |
49
|
|
|
{ |
50
|
|
|
return $this->status === static::STATUS_NOTHING; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @return bool |
55
|
|
|
*/ |
56
|
|
|
public function isIncrement() |
57
|
|
|
{ |
58
|
|
|
return $this->status === static::STATUS_INCREMENT; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @return bool |
63
|
|
|
*/ |
64
|
|
|
public function isTimeout() |
65
|
|
|
{ |
66
|
|
|
return $this->status === static::STATUS_TIMEOUT; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return bool |
71
|
|
|
*/ |
72
|
|
|
public function isSelf() |
73
|
|
|
{ |
74
|
|
|
return $this->status === static::STATUS_SELF; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return bool |
79
|
|
|
*/ |
80
|
|
|
public function isNoUser() |
81
|
|
|
{ |
82
|
|
|
return $this->status === static::STATUS_NO_USER; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return int |
88
|
|
|
*/ |
89
|
|
|
public function getStatus() |
90
|
|
|
{ |
91
|
|
|
return $this->status; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @return User |
96
|
|
|
*/ |
97
|
|
|
public function getUser() |
98
|
|
|
{ |
99
|
|
|
return $this->user; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @param $karma |
104
|
|
|
* @return string|null |
105
|
|
|
*/ |
106
|
|
|
public function getTranslation($karma) |
107
|
|
|
{ |
108
|
|
|
$args = ['user' => $this->user->login, 'karma' => $karma]; |
109
|
|
|
|
110
|
|
|
switch ($this->status) { |
111
|
|
|
case static::STATUS_INCREMENT: |
112
|
|
|
return Lang::get('karma.increment', $args); |
113
|
|
|
|
114
|
|
|
case static::STATUS_TIMEOUT: |
115
|
|
|
return Lang::get('karma.timeout', $args); |
116
|
|
|
|
117
|
|
|
case static::STATUS_SELF: |
118
|
|
|
return Lang::get('karma.self', $args); |
119
|
|
|
|
120
|
|
|
case static::STATUS_NO_USER: |
121
|
|
|
return Lang::get('karma.nouser', $args); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
return null; |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|