|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2017 Vinzenz Rosenkranz <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* @author Vinzenz Rosenkranz <[email protected]> |
|
6
|
|
|
* @author Kai Schröer <[email protected]> |
|
7
|
|
|
* @author René Gieling <[email protected]> |
|
8
|
|
|
* |
|
9
|
|
|
* @license GNU AGPL version 3 or any later version |
|
10
|
|
|
* |
|
11
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
12
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
13
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
14
|
|
|
* License, or (at your option) any later version. |
|
15
|
|
|
* |
|
16
|
|
|
* This program is distributed in the hope that it will be useful, |
|
17
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
19
|
|
|
* GNU Affero General Public License for more details. |
|
20
|
|
|
* |
|
21
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
22
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
23
|
|
|
* |
|
24
|
|
|
*/ |
|
25
|
|
|
|
|
26
|
|
|
namespace OCA\Polls\Db; |
|
27
|
|
|
|
|
28
|
|
|
use JsonSerializable; |
|
29
|
|
|
use OCP\IUser; |
|
30
|
|
|
use OCP\AppFramework\Db\Entity; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @method int getPollId() |
|
34
|
|
|
* @method void setPollId(integer $value) |
|
35
|
|
|
* @method string getUserId() |
|
36
|
|
|
* @method void setUserId(string $value) |
|
37
|
|
|
* @method int getVoteOptionId() |
|
38
|
|
|
* @method void setVoteOptionId(integer $value) |
|
39
|
|
|
* @method string getVoteOptionText() |
|
40
|
|
|
* @method void setVoteOptionText(string $value) |
|
41
|
|
|
* @method string getVoteAnswer() |
|
42
|
|
|
* @method void setVoteAnswer(string $value) |
|
43
|
|
|
*/ |
|
44
|
|
|
class Vote extends Entity implements JsonSerializable { |
|
45
|
|
|
|
|
46
|
|
|
/** @var int $pollId */ |
|
47
|
|
|
protected $pollId; |
|
48
|
|
|
|
|
49
|
|
|
/** @var string $userId */ |
|
50
|
|
|
protected $userId; |
|
51
|
|
|
|
|
52
|
|
|
/** @var int $voteOptionId */ |
|
53
|
|
|
protected $voteOptionId; |
|
54
|
|
|
|
|
55
|
|
|
/** @var string $voteOptionText */ |
|
56
|
|
|
protected $voteOptionText; |
|
57
|
|
|
|
|
58
|
|
|
/** @var string $voteAnswer */ |
|
59
|
|
|
protected $voteAnswer; |
|
60
|
|
|
|
|
61
|
|
|
public function __construct() { |
|
62
|
|
|
$this->addType('id', 'integer'); |
|
63
|
|
|
$this->addType('pollId', 'integer'); |
|
64
|
|
|
$this->addType('voteOptionId', 'integer'); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function jsonSerialize() { |
|
68
|
|
|
return [ |
|
69
|
|
|
'id' => $this->id, |
|
70
|
|
|
'pollId' => $this->pollId, |
|
71
|
|
|
'userId' => $this->userId, |
|
72
|
|
|
'voteOptionId' => $this->voteOptionId, |
|
73
|
|
|
'voteOptionText' => $this->voteOptionText, |
|
74
|
|
|
'voteAnswer' => $this->voteAnswer, |
|
75
|
|
|
'isNoUser' => $this->getIsNoUser(), |
|
76
|
|
|
'displayName' => $this->getDisplayName() |
|
77
|
|
|
]; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function getDisplayName(): string { |
|
81
|
|
|
return $this->getIsNoUser() |
|
82
|
|
|
? $this->userId |
|
83
|
|
|
: \OC::$server->getUserManager()->get($this->userId)->getDisplayName(); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function getIsNoUser(): bool { |
|
87
|
|
|
return !(\OC::$server->getUserManager()->get($this->userId) instanceof IUser); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|