summaryrefslogtreecommitdiffstats
path: root/src/Recipient/ProcessedMembership.php
blob: 50c11ef51435e8cdbdb0bae3abe3498143ec282c (plain)
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
/**
* PHP version 7.1.1
* @author Hannes Kindströmmer <hannes@kindstrommer.se>
* @copyright 2017 iP.1 Networks AB
* @license https://www.gnu.org/licenses/lgpl-3.0.txt LGPL-3.0
* @version 0.3.0-beta
* @since File available since Release 0.1.0-beta
* @link http://api.ip1sms.com/Help
* @link https://github.com/iP1SMS/ip1-php-sdk
*/
namespace IP1\RESTClient\Recipient;

use IP1\RESTClient\Core\ProcessedComponentInterface;
use IP1\RESTClient\Core\OwnableInterface;

/**
* ProcessedMembership class.
* Is the relation between contacts and groups.
*/
class ProcessedMembership extends Membership implements ProcessedComponentInterface, OwnableInterface
{

    /**
    * The ID of the Membership.
    * @var integer $membershipID
    */
    private $membershipID;
    /**
    * When the membership was added to the API
    * @var DateTime $created
    */
    private $created;
    /**
    * ID of account owning the membership
    * @var string $ownerID
    */
    private $ownerID;
    /**
    * ProcessedMembership Constructor
    * @param integer   $groupID      The ID of the group.
    * @param integer   $contactID    The ID of the contact.
    * @param integer   $membershipID The ID of the membership.
    * @param string    $ownerID      ID of account owning the membership.
    * @param \DateTime $created      When the Membership was created.
    */
    public function __construct(int $groupID, int $contactID, int $membershipID, string $ownerID, \DateTime $created)
    {
        parent::__construct($groupID, $contactID);
        $this->membershipID = $membershipID;
        $this->ownerID = $ownerID;
        $this->created = $created;
    }

    /**
    * Returns id of the Membership given by the API.
    * @return integer Membership ID given by the API.
    */
    public function getID(): int
    {
        return $this->membershipID;
    }
    /**
    * Returns ID of account owning the Membership
    * @return string ID of account owning the Membership
    */
    public function getOwnerID(): string
    {
        return $this->ownerID;
    }
    /**
    * @param \DateTimeZone $timezone The timezone that the user wants to get the DateTime in. Default is UTC.
    * @return \DateTime|null When the Component was added.
    */
    public function getCreated(\DateTimeZone $timezone = null): ?\DateTime
    {
        if (!is_null($timezone)) {
            $returnDate = clone $this->created;
            $returnDate->setTimeZone($timezone);
            return $returnDate;
        }
        return $this->created ?? null;
    }
    /**
    * Takes the given argument and replaces strings such as {id} to an actual value.
    * @param string $endPoint The endpoint to be corrected.
    * @return void
    */
    public function fillEndPoint(string &$endPoint): void
    {
        $endPoint = str_replace("{membership}", $this->membershipID, $endPoint);
    }
}