summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHannes Kindströmmer <hannes@kindstrommer.se>2017-03-02 17:06:31 +0100
committerHannes Kindströmmer <hannes@kindstrommer.se>2017-03-02 17:06:31 +0100
commitab3b1b5f7146b8ac4cc2a87af1167956bf902322 (patch)
treed1a5dad22ac773b2e4f9600f60b292309b0989db /src
parenta0e20e913b906b8ead1b6206364dbfba29c7d507 (diff)
downloadip1-php-sdk-ab3b1b5f7146b8ac4cc2a87af1167956bf902322.zip
ip1-php-sdk-ab3b1b5f7146b8ac4cc2a87af1167956bf902322.tar.gz
ip1-php-sdk-ab3b1b5f7146b8ac4cc2a87af1167956bf902322.tar.bz2
Add ProcessedContact and PHPDoc
Added a class called ProcessedContact which is a child of the Contact class. The ProcessedContact class is what you will get in return when adding a Contact to the API or when getting previously added contacts. Tests for this class has also been added together with PHPDoc comments for both the Contact and ProcessedContact class. Signed-off-by: Hannes Kindströmmer <hannes@kindstrommer.se>
Diffstat (limited to 'src')
-rw-r--r--src/Recipient/Contact.php67
-rw-r--r--src/Recipient/ProcessedContact.php103
2 files changed, 163 insertions, 7 deletions
diff --git a/src/Recipient/Contact.php b/src/Recipient/Contact.php
index 67f5787..61a1e87 100644
--- a/src/Recipient/Contact.php
+++ b/src/Recipient/Contact.php
@@ -12,14 +12,14 @@ class Contact implements \JsonSerializable
private $email;
private $notes;
/**
- * @param string $firstName
- * @param string $phoneNumber
- * @param string $lastName
- * @param string $title
- * @param string $organization
- * @param string $email
- * @param string $notes
+ * The Contact constructor
*
+ * @param string $firstName The first name of the contact in question
+ * @param string $phoneNumber Contact phone number: with country code and without spaces and dashes
+ * @param string $lastName (optional) Contact last name
+ * @param string $organization (optional) Contact company or other organization
+ * @param string $email (optional) Contact email address
+ * @param string $notes (optional) Contact notes
*/
public function __construct(
string $firstName,
@@ -44,6 +44,9 @@ class Contact implements \JsonSerializable
$this->email = $email;
$this->notes = $notes;
}
+ /**
+ * @return array
+ */
public function jsonSerialize(): array
{
$returnArray = [
@@ -57,58 +60,108 @@ class Contact implements \JsonSerializable
];
return array_filter($returnArray);
}
+ /**
+ * @param string $firstName Sets the first name of the contact
+ */
public function setFirstName(string $firstName)
{
$this->firstName = $firstName;
}
+
+ /**
+ * @param string $lastName|null Sets the last name of the contact
+ */
public function setLastName(?string $lastName)
{
$this->lastName = $lastName;
}
+
+ /**
+ * @param string $phoneNumber Sets the phone number of the contact
+ */
public function setPhoneNumber(string $phoneNumber)
{
$this->phone = $phoneNumber;
}
+
+ /**
+ * @param string $title|null Sets the title of the contact
+ */
public function setTitle(?string $title)
{
$this->title = $title;
}
+
+ /**
+ * @param string $organization|null Sets the contact company or other organization the contact belongs to
+ */
public function setOrganization(?string $organization)
{
$this->organization = $organization;
}
+
+ /**
+ * @param string $email|null Sets the email adress of the contact
+ */
public function setEmail(?string $email)
{
$this->email = $email;
}
+
+ /**
+ * @param string $firstName Sets the first name of the contact
+ */
public function setNotes(?string $notes)
{
$this->notes = $notes;
}
+ /**
+ * @return string The contacts first name
+ */
public function getFirstName():string
{
return $this->firstName;
}
+ /**
+ * @return string The contacts last name
+ */
public function getLastName():string
{
return $this->lastName ?? "";
}
+ /**
+ * @return string The contacts phone number
+ */
public function getPhoneNumber():string
{
return $this->phone;
}
+ /**
+ * @return string The contacts email
+ */
public function getEmail():string
{
return $this->email ?? "";
}
+
+ /**
+ * @return string The contacts title
+ */
public function getTitle():string
{
return $this->title ?? "";
}
+
+ /**
+ * @return string The contacts company or other organization
+ */
public function getOrganization():string
{
return $this->organization ?? "";
}
+ /**
+ * @return string The contact notes
+ */
public function getNotes():string
{
return $this->notes ?? "";
diff --git a/src/Recipient/ProcessedContact.php b/src/Recipient/ProcessedContact.php
new file mode 100644
index 0000000..c29fc89
--- /dev/null
+++ b/src/Recipient/ProcessedContact.php
@@ -0,0 +1,103 @@
+<?php
+
+/**
+ *
+ */
+namespace IP1\RESTClient\Recipient;
+
+use \IP1\RESTClient\Core\UpdatableComponent;
+
+class ProcessedContact extends Contact implements UpdatableComponent
+{
+ private $updated;
+ private $contactID;
+ private $created;
+ const IS_READ_ONLY = false;
+ /**
+ * The ProcessedContact constructor
+ *
+ * @param string $firstName The first name of the contact in question
+ * @param string $phoneNumber Contact phone number: with country code and without spaces and dashes
+ * @param int $contactID Contact ID
+ * @param string $lastName (optional) Contact last name
+ * @param string $organization (optional) Contact company or other organization
+ * @param string $email (optional) Contact email address
+ * @param string $notes (optional) Contact notes
+ * @param DateTime $created (optional) Date/time of when the contact was added
+ * @param DateTime $updated (optional) Date/time of when the contact was last updated/modified
+ */
+ public function __construct(
+ string $firstName,
+ string $phoneNumber,
+ int $contactID,
+ ?string $lastName,
+ ?string $title,
+ ?string $organization,
+ ?string $email,
+ ?string $notes,
+ ?\DateTime $created = null,
+ ?\DateTime $updated = null
+ ) {
+ parent::__construct($firstName, $phoneNumber, $lastName, $title, $organization, $email, $notes);
+ $this->contactID = $contactID;
+ $this->created = $created ?? null;
+ $this->updated = $updated ?? null;
+ }
+
+ /**
+ * @param DateTimeZone $timezone (optional) The timezone that the user wants to get the DateTime in.
+ * @return DateTime When the contact was updated/modified last
+ */
+ public function getUpdated(\DateTimeZone $timezone = null): ?\DateTime
+ {
+ if (!is_null($timezone)) {
+ $returnDate = clone $this->updated;
+ $returnDate->setTimeZone($timezone);
+ return $returnDate;
+ }
+ return $this->updated ?? null;
+ }
+ /**
+ * @return bool Wether the object is read only or not
+ */
+ public function getReadOnly(): bool
+ {
+ return self::IS_READ_ONLY;
+ }
+ /**
+ * @param DateTimeZone $timezone (optional) The timezone that the user wants to get the DateTime in.
+ * @return DateTime When the Contact 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;
+ }
+ /**
+ * @return int Contact ID
+ */
+ public function getID():int
+ {
+ return $this->contactID;
+ }
+ /**
+ * @return array
+ */
+ public function jsonSerialize(): array
+ {
+ $contactArray = parent::jsonSerialize();
+ $returnArray = array_merge(
+ ['ID' => $this->contactID],
+ $contactArray,
+ [
+ 'Modified' => $this->updated->format("Y-m-d\TH:i:s."). substr($this->updated->format('u'), 0, 3) ?? null,
+ 'Created' => $this->created->format("Y-m-d\TH:i:s."). substr($this->updated->format('u'), 0, 3) ?? null,
+ ]
+ );
+ return array_filter($returnArray);
+ }
+}