From 5f796618d6926d9c3caa17e38d9c85e99440dd85 Mon Sep 17 00:00:00 2001 From: Georgi Marinov Date: Fri, 4 Oct 2019 16:01:22 +0100 Subject: [PATCH] map UGC contact options (#297) * add UGC type to ContactMediumEnum * use UGC const from enum in OptionsMapper --- composer.lock | 14 ++++---- src/Domain/Enumeration/ContactMediumEnum.php | 1 + src/Domain/ValueObject/UGCContactDetails.php | 33 +++++++++++++++++++ .../ProgrammesDbToDomain/OptionsMapper.php | 21 ++++++++---- 4 files changed, 56 insertions(+), 13 deletions(-) create mode 100644 src/Domain/ValueObject/UGCContactDetails.php diff --git a/composer.lock b/composer.lock index 81a5b1a6..c4959112 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "97c2bcda23219bcca3c2cd910cd7e17e", + "content-hash": "4bcacd462bd9dc6d95ab2aa8650fc852", "packages": [ { "name": "bbc/doctrine-extensions", @@ -93,16 +93,16 @@ }, { "name": "bbc/programmes-caching-library", - "version": "v1.1.0", + "version": "v1.1.2", "source": { "type": "git", "url": "https://github.com/bbc/programmes-caching-library.git", - "reference": "80751814ab8acdd03930ef8905b067290e0b2328" + "reference": "95c10713c38864b19e65d19fa41feae79acce5bd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/bbc/programmes-caching-library/zipball/80751814ab8acdd03930ef8905b067290e0b2328", - "reference": "80751814ab8acdd03930ef8905b067290e0b2328", + "url": "https://api.github.com/repos/bbc/programmes-caching-library/zipball/95c10713c38864b19e65d19fa41feae79acce5bd", + "reference": "95c10713c38864b19e65d19fa41feae79acce5bd", "shasum": "" }, "require": { @@ -123,10 +123,10 @@ }, "description": "Caching for /programmes projects", "support": { - "source": "https://github.com/bbc/programmes-caching-library/tree/v1.1.0", + "source": "https://github.com/bbc/programmes-caching-library/tree/v1.1.2", "issues": "https://github.com/bbc/programmes-caching-library/issues" }, - "time": "2019-09-10T12:01:30+00:00" + "time": "2019-09-13T15:28:13+00:00" }, { "name": "behat/transliterator", diff --git a/src/Domain/Enumeration/ContactMediumEnum.php b/src/Domain/Enumeration/ContactMediumEnum.php index 406e2d79..83e96457 100644 --- a/src/Domain/Enumeration/ContactMediumEnum.php +++ b/src/Domain/Enumeration/ContactMediumEnum.php @@ -18,4 +18,5 @@ class ContactMediumEnum public const STUMBLEUPON = 'stumbleupon'; public const INSTAGRAM = 'instagram'; public const OTHER = 'other'; + public const UGC = 'ugc'; } diff --git a/src/Domain/ValueObject/UGCContactDetails.php b/src/Domain/ValueObject/UGCContactDetails.php new file mode 100644 index 00000000..c0cf8486 --- /dev/null +++ b/src/Domain/ValueObject/UGCContactDetails.php @@ -0,0 +1,33 @@ +topNav = ($data['top_nav'] ?? false) === true; + $this->title = $data['title'] ?? ''; + } + + public function isInTopNav() : bool + { + return $this->topNav; + } + + public function getTitle() : string + { + return $this->title; + } +} diff --git a/src/Mapper/ProgrammesDbToDomain/OptionsMapper.php b/src/Mapper/ProgrammesDbToDomain/OptionsMapper.php index cc4fcc4d..53729c0d 100644 --- a/src/Mapper/ProgrammesDbToDomain/OptionsMapper.php +++ b/src/Mapper/ProgrammesDbToDomain/OptionsMapper.php @@ -3,7 +3,9 @@ namespace BBC\ProgrammesPagesService\Mapper\ProgrammesDbToDomain; use BBC\ProgrammesPagesService\Domain\Entity\Options; +use BBC\ProgrammesPagesService\Domain\Enumeration\ContactMediumEnum; use BBC\ProgrammesPagesService\Domain\ValueObject\ContactDetails; +use BBC\ProgrammesPagesService\Domain\ValueObject\UGCContactDetails; class OptionsMapper extends AbstractMapper { @@ -77,12 +79,19 @@ public function getDomainModel(array $options, array ...$parentEntities) $contacts = []; foreach ($options['contact_details'] as $contactDetails) { - if ($this->isValidContactDetails($contactDetails)) { - $contacts[] = new ContactDetails( - $contactDetails['type'], - $contactDetails['value'], - $contactDetails['freetext'] - ); + if (!$this->isValidContactDetails($contactDetails)) { + continue; + } + switch (strtolower($contactDetails['type'])) { + case ContactMediumEnum::UGC: + $contacts[] = new UGCContactDetails($contactDetails); + break; + default: + $contacts[] = new ContactDetails( + $contactDetails['type'], + $contactDetails['value'], + $contactDetails['freetext'] + ); } }