From d728ba42e955e3f7cc537437f6879155a63038c9 Mon Sep 17 00:00:00 2001 From: vvendin Date: Fri, 22 Mar 2019 18:34:36 +0300 Subject: [PATCH 1/3] Added offset attribute Added offset attribute for progress event --- src/Creative/AbstractLinearCreative.php | 43 +++++++++++++++++++++++-- src/Creative/InLine/Linear.php | 28 ---------------- tests/DocumentTest.php | 1 + tests/data/inlineAd.xml | 1 + 4 files changed, 43 insertions(+), 30 deletions(-) diff --git a/src/Creative/AbstractLinearCreative.php b/src/Creative/AbstractLinearCreative.php index 3834232..3479775 100644 --- a/src/Creative/AbstractLinearCreative.php +++ b/src/Creative/AbstractLinearCreative.php @@ -271,11 +271,12 @@ protected function getTrackingEventsDomElement() /** * @param string $event * @param string $url + * @param string $offset * * @return $this * @throws \Exception */ - public function addTrackingEvent($event, $url) + public function addTrackingEvent($event, $url, $offset = null) { if (!in_array($event, $this->getEventList())) { throw new \Exception(sprintf('Wrong event "%s" specified', $event)); @@ -287,11 +288,49 @@ public function addTrackingEvent($event, $url) // add event attribute $trackingDomElement->setAttribute('event', $event); - + + // add offset attribute + if (isset($offset)) { + if (is_numeric($offset)) { + $offset = $this->secondsToString($offset); + } + $trackingDomElement->setAttribute('offset', $offset); + } + // create cdata $cdata = $this->linearCreativeDomElement->ownerDocument->createCDATASection($url); $trackingDomElement->appendChild($cdata); return $this; } + + + /** + * Convert seconds to H:m:i + * Hours could be more than 24 + * + * @param mixed $seconds + * + * @return string + */ + protected function secondsToString($seconds) + { + $seconds = (int) $seconds; + + $time = array(); + + // get hours + $hours = floor($seconds / 3600); + $time[] = str_pad($hours, 2, '0', STR_PAD_LEFT); + + // get minutes + $seconds = $seconds % 3600; + $time[] = str_pad(floor($seconds / 60), 2, '0', STR_PAD_LEFT); + + // get seconds + $time[] = str_pad($seconds % 60, 2, '0', STR_PAD_LEFT); + + return implode(':', $time); + } + } diff --git a/src/Creative/InLine/Linear.php b/src/Creative/InLine/Linear.php index 0a79024..9805d94 100644 --- a/src/Creative/InLine/Linear.php +++ b/src/Creative/InLine/Linear.php @@ -96,34 +96,6 @@ public function setAdParameters($params) return $this; } - /** - * Convert seconds to H:m:i - * Hours could be more than 24 - * - * @param mixed $seconds - * - * @return string - */ - private function secondsToString($seconds) - { - $seconds = (int) $seconds; - - $time = array(); - - // get hours - $hours = floor($seconds / 3600); - $time[] = str_pad($hours, 2, '0', STR_PAD_LEFT); - - // get minutes - $seconds = $seconds % 3600; - $time[] = str_pad(floor($seconds / 60), 2, '0', STR_PAD_LEFT); - - // get seconds - $time[] = str_pad($seconds % 60, 2, '0', STR_PAD_LEFT); - - return implode(':', $time); - } - /** * @param int|string $time seconds or time in format "H:m:i" * @return $this diff --git a/tests/DocumentTest.php b/tests/DocumentTest.php index 55baf51..4b4e84d 100644 --- a/tests/DocumentTest.php +++ b/tests/DocumentTest.php @@ -32,6 +32,7 @@ public function testCreateInLineAdSection() ->addVideoClicksCustomClick('http://ad.server.com/videoclicks/customclick') ->addTrackingEvent('start', 'http://ad.server.com/trackingevent/start') ->addTrackingEvent('pause', 'http://ad.server.com/trackingevent/stop') + ->addTrackingEvent('progress', 'http://ad.server.com/trackingevent/progress', 10) ->createMediaFile() ->setProgressiveDelivery() ->setType('video/mp4') diff --git a/tests/data/inlineAd.xml b/tests/data/inlineAd.xml index 68a1533..74e12ab 100644 --- a/tests/data/inlineAd.xml +++ b/tests/data/inlineAd.xml @@ -17,6 +17,7 @@ + From 570cdc5bd28f9f541d3d47abf0d5883b23aef0cf Mon Sep 17 00:00:00 2001 From: vendin Date: Sat, 23 Mar 2019 12:28:35 +0300 Subject: [PATCH 2/3] Added addProgressTrackingEvent method --- src/Creative/AbstractLinearCreative.php | 37 ++++++++++++++++++------- tests/DocumentTest.php | 2 +- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/Creative/AbstractLinearCreative.php b/src/Creative/AbstractLinearCreative.php index 3479775..95128ad 100644 --- a/src/Creative/AbstractLinearCreative.php +++ b/src/Creative/AbstractLinearCreative.php @@ -271,12 +271,11 @@ protected function getTrackingEventsDomElement() /** * @param string $event * @param string $url - * @param string $offset * * @return $this * @throws \Exception */ - public function addTrackingEvent($event, $url, $offset = null) + public function addTrackingEvent($event, $url) { if (!in_array($event, $this->getEventList())) { throw new \Exception(sprintf('Wrong event "%s" specified', $event)); @@ -289,22 +288,41 @@ public function addTrackingEvent($event, $url, $offset = null) // add event attribute $trackingDomElement->setAttribute('event', $event); + // create cdata + $cdata = $this->linearCreativeDomElement->ownerDocument->createCDATASection($url); + $trackingDomElement->appendChild($cdata); + + return $this; + } + + /** + * @param string $url + * @param int|string $offset seconds or time in format "H:m:i" + * + * @return $this + */ + public function addProgressTrackingEvent($url, $offset) + { + // create Tracking + $trackingDomElement = $this->linearCreativeDomElement->ownerDocument->createElement('Tracking'); + $this->getTrackingEventsDomElement()->appendChild($trackingDomElement); + + // add event attribute + $trackingDomElement->setAttribute('event', self::EVENT_TYPE_PROGRESS); + // add offset attribute - if (isset($offset)) { - if (is_numeric($offset)) { - $offset = $this->secondsToString($offset); - } - $trackingDomElement->setAttribute('offset', $offset); + if (is_numeric($offset)) { + $offset = $this->secondsToString($offset); } + $trackingDomElement->setAttribute('offset', $offset); // create cdata $cdata = $this->linearCreativeDomElement->ownerDocument->createCDATASection($url); $trackingDomElement->appendChild($cdata); - + return $this; } - /** * Convert seconds to H:m:i * Hours could be more than 24 @@ -332,5 +350,4 @@ protected function secondsToString($seconds) return implode(':', $time); } - } diff --git a/tests/DocumentTest.php b/tests/DocumentTest.php index 4b4e84d..13e0add 100644 --- a/tests/DocumentTest.php +++ b/tests/DocumentTest.php @@ -32,7 +32,7 @@ public function testCreateInLineAdSection() ->addVideoClicksCustomClick('http://ad.server.com/videoclicks/customclick') ->addTrackingEvent('start', 'http://ad.server.com/trackingevent/start') ->addTrackingEvent('pause', 'http://ad.server.com/trackingevent/stop') - ->addTrackingEvent('progress', 'http://ad.server.com/trackingevent/progress', 10) + ->addProgressTrackingEvent('http://ad.server.com/trackingevent/progress', 10) ->createMediaFile() ->setProgressiveDelivery() ->setType('video/mp4') From 270ace8c38b278047d86c349e6e692a74bddd938 Mon Sep 17 00:00:00 2001 From: vendin Date: Sat, 23 Mar 2019 13:21:59 +0300 Subject: [PATCH 3/3] Updated phpdoc for addProgressTrackingEvent method --- src/Creative/AbstractLinearCreative.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Creative/AbstractLinearCreative.php b/src/Creative/AbstractLinearCreative.php index 95128ad..7c64d8b 100644 --- a/src/Creative/AbstractLinearCreative.php +++ b/src/Creative/AbstractLinearCreative.php @@ -297,7 +297,7 @@ public function addTrackingEvent($event, $url) /** * @param string $url - * @param int|string $offset seconds or time in format "H:m:i" + * @param int|string $offset seconds or time in format "H:m:i" or percents in format "n%" * * @return $this */