Passed
Pull Request — master (#1193)
by René
04:17
created

Share::externalUser()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 2
ccs 0
cts 0
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * @copyright Copyright (c) 2017 Vinzenz Rosenkranz <[email protected]>
4
 *
5
 * @author René Gieling <[email protected]>
6
 *
7
 * @license GNU AGPL version 3 or any later version
8
 *
9
 *  This program is free software: you can redistribute it and/or modify
10
 *  it under the terms of the GNU Affero General Public License as
11
 *  published by the Free Software Foundation, either version 3 of the
12
 *  License, or (at your option) any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU Affero General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU Affero General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
24
namespace OCA\Polls\Db;
25
26
use JsonSerializable;
27
28
use OCP\AppFramework\Db\Entity;
29
use OCA\Polls\Model\UserGroupClass;
30
31
/**
32
 * @method string getId()
33
 * @method void setId(integer $value)
34
 * @method string getToken()
35
 * @method void setToken(string $value)
36
 * @method string getType()
37
 * @method void setType(string $value)
38
 * @method int getPollId()
39
 * @method void setPollId(integer $value)
40
 * @method string getUserId()
41
 * @method void setUserId(string $value)
42
 * @method string getUserEmail()
43
 * @method void setUserEmail(string $value)
44
 * @method int getInvitationSent()
45
 * @method void setInvitationSent(integer $value)
46
 * @method int getDisplayName()
47
 * @method void setDisplayName(string $value)
48
 */
49
class Share extends Entity implements JsonSerializable {
50
	public const TYPE_USER = 'user';
51
	public const TYPE_EMAIL = 'email';
52
	public const TYPE_CIRCLE = 'circle';
53
	public const TYPE_GROUP = 'group';
54
	public const TYPE_CONTACTGROUP = 'contactGroup';
55
	public const TYPE_CONTACT = 'contact';
56
	public const TYPE_PUBLIC = 'public';
57
	public const TYPE_EXTERNAL = 'external';
58
59
	/** @var string $token */
60
	protected $token;
61
62
	/** @var string $type */
63
	protected $type;
64
65
	/** @var int $pollId */
66
	protected $pollId;
67
68
	/** @var string $userId */
69
	protected $userId;
70
71
	/** @var string $userEmail */
72
	protected $userEmail;
73
74
	/** @var string $invitationSent */
75
	protected $invitationSent;
76
77
	/** @var string $displayName */
78
	protected $displayName;
79
80
	public function jsonSerialize() {
81
		return [
82
			'id' => intval($this->id),
83
			'token' => $this->token,
84
			'type' => $this->type,
85
			'pollId' => intval($this->pollId),
86
			'userId' => $this->getUserId(),
87
			'userEmail' => $this->userEmail,
88
			'invitationSent' => intval($this->invitationSent),
89
			'displayName' => $this->displayName,
90
			'isNoUser' => !($this->type === self::TYPE_USER),
91
			'shareeDetail' => UserGroupClass::getUserGroupChild($this->type, $this->getUserId())
92
		];
93
	}
94
95
	public function getUserId() {
96
		if ($this->type === self::TYPE_CONTACTGROUP) {
97
			// contactsgroup had the prefix contactgroup_ until version 1.5
98
			// strip it out
99
			$parts = explode("contactgroup_", $this->userId);
100
			$userId = end($parts);
101
			return $userId;
102
		}
103
		return $this->userId;
104
	}
105
}
106