Skip to content
This repository has been archived by the owner on Feb 8, 2023. It is now read-only.

Commit

Permalink
Merge pull request #18 from methylbro/hyperlink-to-sensors
Browse files Browse the repository at this point in the history
🔗 handle HYPERLINKS_TO_SENSORS attribute
  • Loading branch information
methylbro authored Dec 26, 2016
2 parents 981ca8d + 2b75fb0 commit a69f640
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 1 deletion.
10 changes: 10 additions & 0 deletions doc/Broadcast.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,13 @@ if ($response==Response::SUCCESSFUL) {
}

```

## HYPERLINKS_TO_SENSORS Attribute

Convert all your hyperlinks to sensors in your email :

```php
<?php
$email = new Email();
$email->setHyperlinksToSensors(true);
```
28 changes: 27 additions & 1 deletion src/Broadcast/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ class Email
/**
* @var array
*/
private $content;
private $content = [];

/**
* @var boolean
*/
protected $hyperlinks_to_sensors = false;

/**
* @param string $name The name as defined for the email message properties.
Expand Down Expand Up @@ -244,4 +249,25 @@ public function getContent()
{
return $this->content;
}

/**
* Set this value to TRUE when your hyperlinks must be converted to sensors.
*
* @param boolean $hyperlinks_to_sensors
* @return self
*/
public function setHyperlinksToSensors($hyperlinks_to_sensors = true)
{
$this->hyperlinks_to_sensors = $hyperlinks_to_sensors;

return $this;
}

/**
* @return boolean
*/
public function hasHyperlinksToSensors()
{
return $this->hyperlinks_to_sensors;
}
}
3 changes: 3 additions & 0 deletions src/Request/CreateCampaign.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ private function email(Email $email)
$this->target($email->getTarget());

$this->writer->startElement('CONTENT');
if ($email->hasHyperlinksToSensors()) {
$this->attr('HYPERLINKS_TO_SENSORS', 1);
}
foreach ($email->getContent() as $key => $value) {
$this->writer->startElement($key);
$this->writer->startCData();
Expand Down
58 changes: 58 additions & 0 deletions tests/Broadcast/HyperlinkToSensorsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

/**
* This file is part of the Mediapart Selligent Client API
*
* CC BY-NC-SA <https://github.com/mediapart/selligent>
*
* For the full license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Mediapart\Selligent\Tests\Broadcast;

use \XMLWriter;
use Mediapart\Selligent\Request\CreateCampaign;
use Mediapart\Selligent\Broadcast\Campaign;
use Mediapart\Selligent\Broadcast\Target;
use Mediapart\Selligent\Broadcast\Email;

/**
*
*/
class HyperlinkToSensorsTest extends \PHPUnit_Framework_TestCase
{
/**
*
*/
public function testEmailAttribute()
{
$email = new Email();

$email->setHyperlinksToSensors(true);

$this->assertTrue($email->hasHyperlinksToSensors());
}

/**
*
*/
public function testCreateCampaign()
{
$campaign = new Campaign();
$target = new Target();
$email = new Email();
$email
->setTarget($target)
->setHyperlinksToSensors(true)
;
$campaign->addEmail($email);

$writer = new XMLWriter();
$request = new CreateCampaign($writer);
$xml = $request->basedOn($campaign);

$document = simplexml_load_string($xml);
$this->assertEquals(1, (int) $document->EMAILS->EMAIL[0]->CONTENT->attributes()->HYPERLINKS_TO_SENSORS);
}
}

0 comments on commit a69f640

Please sign in to comment.