summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHannes Kindströmmer <hannes@kindstrommer.se>2017-03-07 15:31:38 +0100
committerHannes Kindströmmer <hannes@kindstrommer.se>2017-03-07 15:32:10 +0100
commitd513e6ceeeffc96b0e61adfecdf666b13b5ebe2f (patch)
treed42db41d12ca45bfcc3e12a4835bffab782ce528 /src
parent33a5b9bbdfb92a6ecb0f6fbdef8bfbba6c87fb4f (diff)
downloadip1-php-sdk-d513e6ceeeffc96b0e61adfecdf666b13b5ebe2f.zip
ip1-php-sdk-d513e6ceeeffc96b0e61adfecdf666b13b5ebe2f.tar.gz
ip1-php-sdk-d513e6ceeeffc96b0e61adfecdf666b13b5ebe2f.tar.bz2
Add ProcessedMembership
Diffstat (limited to 'src')
-rw-r--r--src/Recipient/ProcessedMembership.php55
-rw-r--r--src/Recipient/RecipientFactory.php26
2 files changed, 81 insertions, 0 deletions
diff --git a/src/Recipient/ProcessedMembership.php b/src/Recipient/ProcessedMembership.php
new file mode 100644
index 0000000..cd3f71c
--- /dev/null
+++ b/src/Recipient/ProcessedMembership.php
@@ -0,0 +1,55 @@
+<?php
+/**
+* Contains the ProcessedMembership class
+* PHP version 7.1.1
+* @author Hannes Kindströmmer <hannes@kindstrommer.se>
+* @copyright 2017 IP1 SMS
+*/
+namespace IP1\RESTClient\Recipient;
+
+use IP1\RESTClient\Core\Communicator;
+use IP1\RESTClient\Core\ProcessedComponent;
+
+class ProcessedMembership extends Membership implements ProcessedComponent
+{
+
+ /**
+ * The ID of the Membership.
+ * @var int $id
+ */
+ private $id;
+ /**
+ * When the membership was added to the API
+ * @var DateTime $created
+ */
+ private $created;
+ /**
+ * ProcessedMembership Constructor
+ * @param int $groupID
+ * @param int $contactID
+ * @param int $id
+ * @param \DateTime $created
+ */
+ public function __construct(int $groupID, int $contactID, int $id, \DateTime $created)
+ {
+ parent::__construct($groupID, $contactID);
+ $this->id = $id;
+ $this->created = $created;
+ }
+
+ /** {@inheritDoc} */
+ public function getID(): int
+ {
+ return $this->id;
+ }
+ /** {@inheritDoc} */
+ public function getCreated(\DateTimeZone $timezone = null): ?\DateTime
+ {
+ if (!is_null($timezone)) {
+ $returnDate = clone $this->created;
+ $returnDate->setTimeZone($timezone);
+ return $returnDate;
+ }
+ return $this->created ?? null;
+ }
+}
diff --git a/src/Recipient/RecipientFactory.php b/src/Recipient/RecipientFactory.php
index 61e145b..d7178b5 100644
--- a/src/Recipient/RecipientFactory.php
+++ b/src/Recipient/RecipientFactory.php
@@ -9,6 +9,7 @@ namespace IP1\RESTClient\Recipient;
use IP1\RESTClient\Recipient\ProcessedGroup;
use IP1\RESTClient\Recipient\ProcessedContact;
+use IP1\RESTClient\Recipient\ProcessedMembership;
/**
* Handles construction of Recipients.
@@ -139,4 +140,29 @@ class RecipientFactory
new \DateTime($stdContact->Modified)
);
}
+ public static function createProcessedMembershipFromJSON(string $jsonMembership): ProcessedMembership
+ {
+ return self::createProcessedMembershipFromStdClass(json_decode($jsonMembership));
+ }
+ public static function createProcessedMembershipFromStdClass(\stdClass $stdMembership): ProcessedMembership
+ {
+ return new ProcessedMembership(
+ $stdMembership->Group,
+ $stdMembership->Contact,
+ $stdMembership->ID,
+ new \DateTime($stdMembership->Created)
+ );
+ }
+ public static function createProcessedMembershipsFromStdClassArray(array $stdMemberships): array
+ {
+ $memberships = [];
+ foreach ($stdMemberships as $m) {
+ $memberships[] = self::createProcessedMembershipFromStdClass($m);
+ }
+ return $memberships;
+ }
+ public static function createProcessedMembershipsFromStringArray(string $membershipJSONArray): array
+ {
+ return self::createProcessedMembershipsFromStdClassArray(json_decode($membershipJSONArray));
+ }
}