Skip to content

Commit

Permalink
Adding default mailinglist selector
Browse files Browse the repository at this point in the history
  • Loading branch information
ngroot committed Jan 23, 2014
1 parent e331dea commit e8e8a26
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions lib/CAC/Component/ESP/Api/Engine/EngineApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ public function __construct(array $config)
{
$this->config = array_replace_recursive(
array(
"wsdl" => null,
"secure" => false,
"domain" => "",
"path" => "/soap/server.live.php",
"customer" => "",
"user" => "",
"password" => "",
"trace" => false
"trace" => false,
"mailinglist" => null,
),
$config
);
Expand Down Expand Up @@ -149,17 +151,21 @@ public function sendMailing($mailingId, array $users, $date = null, $mailinglist
$date = date("Y-m-d H:i:s");
}

if (null === $mailinglistId) {
$mailinglistId = $this->config['mailinglist'];
}

// Check if users are set
if (empty($users)) {
throw new EngineApiException("No users to send mailing");
}

$result = $this->performRequest(
'Subscriber_sendMailingToSubscribers',
$mailingId,
intval($mailingId),
$date,
$users,
$mailinglistId
intval($mailinglistId)
);

if (!is_numeric($result)) {
Expand All @@ -172,6 +178,18 @@ public function sendMailing($mailingId, array $users, $date = null, $mailinglist
return $result;
}

/**
* Select a Mailinglist
*
* @param integer $mailinglistId
*
* @return string
*/
public function selectMailinglist($mailinglistId)
{
return $this->performRequest('Mailinglist_select', intval($mailinglistId));
}

/**
* Subscribe a User to a Mailinglist
*
Expand Down Expand Up @@ -330,17 +348,22 @@ protected function getConnection()
if ($this->connection === null) {
// create a connection
$connection = new \SoapClient(
null,
$this->config['wsdl'],
array(
"location" => "http" . (($this->config['secure']) ? 's' : '') . "://" . $this->config["domain"] . $this->config["path"],
"uri" => "http" . (($this->config['secure']) ? 's' : '') . "://" . $this->config["domain"] . $this->config["path"],
//"location" => "http" . (($this->config['secure']) ? 's' : '') . "://" . $this->config["domain"] . $this->config["path"],
//"uri" => "http" . (($this->config['secure']) ? 's' : '') . "://" . $this->config["domain"] . $this->config["path"],
"login" => $this->config["customer"] . "__" . $this->config["user"],
"password" => $this->config["password"],
"trace" => $this->config["trace"]
)
);

$this->connection = $connection;

if ($this->config['mailinglist']) {
// Select the default mailinglist
$this->selectMailinglist($this->config['mailinglist']);
}
}

return $this->connection;
Expand Down

0 comments on commit e8e8a26

Please sign in to comment.