Passed
Push — master ( 26aef5...2a140e )
by Luca
03:56 queued 01:28
created

RosterItemPayload::getSubscriptionType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * OpenFireRestAPI is based entirely on official documentation of the REST API
4
 * Plugin and you can extend it by following the directives of the documentation
5
 *
6
 * For the full copyright and license information, please read the LICENSE
7
 * file that was distributed with this source code. For the full list of
8
 * contributors, visit https://github.com/gnello/PHPOpenFireRestAPI/contributors
9
 *
10
 * @author Luca Agnello <[email protected]>
11
 * @link https://www.igniterealtime.org/projects/openfire/plugins/restapi/readme.html
12
 */
13
14
namespace Gnello\OpenFireRestAPI\Payloads;
15
16
use Gnello\OpenFireRestAPI\Settings\Settings;
17
use Gnello\OpenFireRestAPI\Settings\SubscriptionType;
18
19
/**
20
 * Payload of RosterItem related REST Endpoint
21
 * Class RosterItemPayload
22
 * @package Gnello\OpenFireRestAPI\Payloads
23
 * @link http://www.igniterealtime.org/projects/openfire/plugins/restapi/readme.html#rosteritem
24
 */
25
class RosterItemPayload extends AbstractPayload
26
{
27
    /**
28
     * The JID of the roster item
29
     * Optional No
30
     * @var string
31
     */
32
    private $jid;
33
34
    /**
35
     * The nickname for the user when used in this roster
36
     * Optional Yes
37
     * @var string
38
     */
39
    private $nickname;
40
41
    /**
42
     * The subscription type
43
     * Possible numeric values are: -1 (remove), 0 (none), 1 (to), 2 (from), 3 (both)
44
     * Optional Yes
45
     * @var integer
46
     */
47
    private $subscriptionType;
48
49
    /**
50
     * A list of groups to organize roster entries under (e.g. friends, co-workers, etc.)
51
     * Optional No
52
     * @var array
53
     */
54
    private $groups;
55
56
    /**
57
     * Returns always the correct jid
58
     * @param $jid
59
     */
60
    public function setJid($jid)
61
    {
62
        $settings = Settings::getInstance();
63
        $server_name = $settings->getServerName();
64
65
        if (strpos('@' . $server_name, $jid) === false) {
66
            $jid .= '@' . $server_name;
67
        }
68
        $this->jid = $jid;;
69
    }
70
71
    /**
72
     * @param $nickname
73
     */
74
    public function setNickname($nickname) {
75
        $this->nickname = $nickname;
76
    }
77
78
    /**
79
     * @param $subscriptionType
80
     * @throws \Exception
81
     */
82
    public function setSubscriptionType($subscriptionType)
83
    {
84
        if (SubscriptionType::isValid($subscriptionType) === false) {
85
            throw new \Exception("SubscriptionType not valid!");
86
        }
87
        $this->subscriptionType = $subscriptionType;
88
    }
89
90
    /**
91
     * @param array $groups
92
     */
93
    public function setGroups(array $groups) {
94
        $this->groups['group'] = $groups;
95
    }
96
97
    /**
98
     * Returns always the correct jid
99
     * @return string
100
     */
101
    public function getJid() {
102
        return $this->jid;
103
    }
104
105
    /**
106
     * @return string
107
     */
108
    public function getNickname() {
109
        return $this->nickname;
110
    }
111
112
    /**
113
     * @return string
114
     */
115
    public function getSubscriptionType() {
116
        return $this->subscriptionType;
117
    }
118
119
    /**
120
     * @return array
121
     */
122
    public function getGroups() {
123
        return $this->groups;
124
    }
125
}
126