Skip to content

Commit

Permalink
FIX: prevent repeated requests
Browse files Browse the repository at this point in the history
CHG: product campaigns: html flag handling, and method to pass through
raw data for processing with JavaScript
  • Loading branch information
tuegeb committed May 5, 2015
1 parent 98dd7fd commit f68cfaf
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
37 changes: 34 additions & 3 deletions FACTFinder/Adapter/ProductCampaign.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ private function createEmptyCampaignObject(array $campaignData)
* @param mixed[] $campaignData An associative array corresponding to the
* JSON for that campaign.
*/
private function fillCampaignWithFeedback(
protected function fillCampaignWithFeedback(
\FACTFinder\Data\Campaign $campaign,
array $campaignData
) {
Expand All @@ -206,13 +206,20 @@ private function fillCampaignWithFeedback(
foreach ($campaignData['feedbackTexts'] as $feedbackData)
{
// If present, add the feedback to both the label and the ID.
$html = $feedbackData['html'];
$text = $feedbackData['text'];
if (!$html)
{
$text = htmlspecialchars($text, ENT_QUOTES, 'UTF-8');
}

$label = $feedbackData['label'];
if ($label !== '')
$feedback[$label] = $feedbackData['text'];
$feedback[$label] = $text;

$id = $feedbackData['id'];
if ($id !== null)
$feedback[$id] = $feedbackData['text'];
$feedback[$id] = $text;
}

$campaign->addFeedback($feedback);
Expand Down Expand Up @@ -245,4 +252,28 @@ private function fillCampaignWithPushedProducts(
$campaign->addPushedProducts($pushedProducts);
}
}

/**
* Get the product campaigns from FACT-Finder as the string returned by the
* server.
*
* @param string $format Optional. Either 'json' or 'jsonp'. Use to
* overwrite the 'format' parameter.
* @param string $callback Optional name to overwrite the 'callback'
* parameter, which determines the name of the
* callback the response is wrapped in.
*
* @return string
*/
public function getRawProductCampaigns($format = null, $callback = null)
{
$this->usePassthroughResponseContentProcessor();

if (!is_null($format))
$this->parameters['format'] = $format;
if (!is_null($callback))
$this->parameters['callback'] = $callback;

return $this->getResponseContent();
}
}
11 changes: 10 additions & 1 deletion FACTFinder/Core/Server/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ class Request
*/
private $connectionData;

/**
* @var ConnectionData
*/
protected $blLoaded;

/**
* @var AbstractDataProvider
*/
Expand All @@ -41,6 +46,7 @@ public function __construct(

$this->connectionData = $connectionData;
$this->dataProvider = $dataProvider;
$this->blLoaded = false;
}

public function __destruct()
Expand Down Expand Up @@ -101,7 +107,10 @@ public function setTimeout($timeout)
*/
public function getResponse()
{
$this->dataProvider->loadResponse($this->id);
if(!$this->blLoaded) {
$this->dataProvider->loadResponse($this->id);
$this->blLoaded = true;
}
return $this->connectionData->getResponse();
}
}

0 comments on commit f68cfaf

Please sign in to comment.