Skip to content

Commit

Permalink
MINOR Added DebugInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
yukiawano committed Aug 17, 2012
1 parent 37ff73e commit 03a3621
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 29 deletions.
24 changes: 22 additions & 2 deletions code/blockholder/DefaultBlockHolder.php
Expand Up @@ -97,21 +97,41 @@ public function getContent(CPEnvironment $env) {

if($this->SlideshowMode) {
// Combine them
$blockTitles = array();
$blockArray = new ArrayList();
foreach($blocks as $block) {
$blockArray->push(new ArrayData(array('Body' => $block->getContent())));
array_push($blockTitles, $block->Title);
}

Requirements::javascript(SSCP_DIR . '/javascript/slides.jquery.js');
Requirements::javascript(SSCP_DIR . '/javascript/slideshow.js');


$template = new SSViewer('Slideshow');
return $template->process($this, array('Blocks' => $blockArray));
return array(
'Content' => $template->process($this, array('Blocks' => $blockArray)),
'DebugInfo' => array(
'SlideshowMode' => 'true',
'RenderedBlocks' => join(', ', $blockTitles)
)
);
} else {
$block = $blocks[0];
return $block->getContent();
return array(
'Content' => $block->getContent(),
'DebugInfo' => array(
'SlideshowMode' => 'false',
'RenderedBlock' => $block->Title
)
);
}

/*
* BlockHolderName,
* DebugInfo - Debug info should be key value list.
* */

if(($block = $this->getBlock($env))) {
return array(
'Content' => $block->SnippetBase()->getContent(),
Expand Down
27 changes: 13 additions & 14 deletions code/dataextension/PersonalizablePage.php
Expand Up @@ -56,7 +56,7 @@ public function PersonalizedContent(string $templateKey) {
return "BlockHolder of {$templateKey} is not found.";
} else {
$showDebugToolbar = Permission::check(BlockHolderMain::ADMIN_PERSONALIZATION);
return $this->renderPersonalizedContent($blockHolder->getContent($env), $showDebugToolbar);
return $this->renderPersonalizedContent($blockHolder->getContent($env), $showDebugToolbar, $templateKey);
}
}

Expand All @@ -73,10 +73,9 @@ public function PersonalizedContent(string $templateKey) {
* 'DebugInfo' => array( For more details, check phpdoc of renderDebugInfo. )
* )
*/
private function renderPersonalizedContent($context, $renderDebugInfo) {
return $context;
private function renderPersonalizedContent($context, $renderDebugInfo, $templateKey) {
if($renderDebugInfo) {
return $context['Content'] . $this->renderDebugInfo($context['DebugInfo']);
return $context['Content'] . $this->renderDebugInfo($context['DebugInfo'], $templateKey);
} else {
return $context['Content'];
}
Expand All @@ -95,21 +94,21 @@ private function renderPersonalizedContent($context, $renderDebugInfo) {
* 'RenderedSnippetName' => 'TestSnippet',
* 'BlockHolderName' => 'BannerBlockHolder' );
*/
private function renderDebugInfo($debugInfo) {
private function renderDebugInfo($debugInfo, $templateKey) {
Requirements::css('sscp/css/DebugInfo.css');

$ssViewer = new SSViewer('DebugInfo');

$consideredAudienceTypes = new ArrayList();
foreach($debugInfo['ConsideredAudienceTypes'] as $audienceType) {
$consideredAudienceTypes->add(new DataObject(array('Name' => $audienceType)));
$valueList = new ArrayList();
foreach($debugInfo as $key => $value) {
$valueList->push(new ArrayData(array(
'Key' => $key,
'Value' => $value
)));
}

$ssViewer = new SSViewer('DebugInfo');
return $ssViewer->process(new DataObject(array(
'AppliedAudienceType' => (null === $debugInfo['AppliedAudienceType'] ? 'No AudienceType has matched.' : $debugInfo['AppliedAudienceType']),
'ConsideredAudienceTypes' => $consideredAudienceTypes,
'RenderedSnippetName' => $debugInfo['RenderedSnippetName'],
'BlockHolderName' => $debugInfo['BlockHolderName']
'TemplateKey' => $templateKey,
'ValueList' => $valueList
)));
}
}
18 changes: 5 additions & 13 deletions templates/Includes/DebugInfo.ss
@@ -1,19 +1,11 @@
<div class="DebugInfo">
<p class="Title">$BlockHolderName</p>
<p class="Title">$TemplateKey</p>
<div class="PropertyBox">
<dl>
<dt>Audience Type</dt>
<dd>$AppliedAudienceType</dd>
<dt>Snippet</dt>
<dd>$RenderedSnippetName</dd>
<dt>Considered Audience Types</dt>
<dd>
<ul>
<% loop $ConsideredAudienceTypes %>
<li>$Name</li>
<% end_loop %>
</ul>
</dd>
<% control $ValueList %>
<dt>$Key</dt>
<dd>$Value</dd>
<% end_control %>
</dl>
</div>
</div>

0 comments on commit 03a3621

Please sign in to comment.