Skip to content

Commit

Permalink
Merge pull request #25 from Vendin/master
Browse files Browse the repository at this point in the history
Added offset attribute
  • Loading branch information
sokil committed Mar 23, 2019
2 parents 014031e + 270ace8 commit 5a8d5bd
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 30 deletions.
60 changes: 58 additions & 2 deletions src/Creative/AbstractLinearCreative.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,67 @@ public function addTrackingEvent($event, $url)

// 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" or percents in format "n%"
*
* @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 (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);
}
}
28 changes: 0 additions & 28 deletions src/Creative/InLine/Linear.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/DocumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
->addProgressTrackingEvent('http://ad.server.com/trackingevent/progress', 10)
->createMediaFile()
->setProgressiveDelivery()
->setType('video/mp4')
Expand Down
1 change: 1 addition & 0 deletions tests/data/inlineAd.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<TrackingEvents>
<Tracking event="start"><![CDATA[http://ad.server.com/trackingevent/start]]></Tracking>
<Tracking event="pause"><![CDATA[http://ad.server.com/trackingevent/stop]]></Tracking>
<Tracking event="progress" offset="00:00:10"><![CDATA[http://ad.server.com/trackingevent/progress]]></Tracking>
</TrackingEvents>
<MediaFiles>
<MediaFile delivery="progressive" type="video/mp4" height="100" width="100" bitrate="600">
Expand Down

0 comments on commit 5a8d5bd

Please sign in to comment.