Skip to content

Commit

Permalink
Refactor profile summaries into additional classes
Browse files Browse the repository at this point in the history
  • Loading branch information
sgiehl committed Aug 28, 2017
1 parent 6ea692b commit 5679c53
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 43 deletions.
56 changes: 56 additions & 0 deletions ProfileSummary/VisitScopeSummary.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/**
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/

namespace Piwik\Plugins\CustomDimensions\ProfileSummary;

use Piwik\Piwik;
use Piwik\Plugins\CustomDimensions\CustomDimensions;
use Piwik\Plugins\Live\ProfileSummary\ProfileSummaryAbstract;
use Piwik\View;

/**
* Class VisitScopeSummary
*
* @api
*/
class VisitScopeSummary extends ProfileSummaryAbstract
{
/**
* @inheritdoc
*/
public function getName()
{
return Piwik::translate('CustomDimensions_CustomDimensions') . ' ' . Piwik::translate('General_TrackingScopeVisit');
}

/**
* @inheritdoc
*/
public function render()
{
if (empty($this->profile['customDimensions']) || empty($this->profile['customDimensions'][CustomDimensions::SCOPE_VISIT])) {
return '';
}

$view = new View('@CustomDimensions/_profileSummary.twig');
$view->visitorData = $this->profile;
$view->scopeName = Piwik::translate('General_TrackingScopeVisit');
$view->dimensions = $this->profile['customDimensions'][CustomDimensions::SCOPE_VISIT];

return $view->render();
}

/**
* @inheritdoc
*/
public function getOrder()
{
return 10;
}
}
13 changes: 0 additions & 13 deletions VisitorDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,17 +269,4 @@ protected function convertForProfile($customDimensions)

return $convertedDimensions;
}

public function renderProfileSummary($profile)
{
if (empty($profile['customDimensions']) || (
empty($profile['customDimensions'][CustomDimensions::SCOPE_VISIT]) &&
empty($profile['customDimensions'][CustomDimensions::SCOPE_ACTION]) )) {
return [];
}

$view = new View('@CustomDimensions/_profileSummary.twig');
$view->visitorData = $profile;
return [[10, $view->render()]];
}
}
42 changes: 12 additions & 30 deletions templates/_profileSummary.twig
Original file line number Diff line number Diff line change
@@ -1,31 +1,13 @@
{% if visitorData.customDimensions['visit'] is defined and visitorData.customDimensions['visit']|length > 0 %}
<div class="visitor-profile-summary visitor-profile-customdimensions">
<h1>{{ 'CustomDimensions_CustomDimensions'|translate }} ({{ 'General_TrackingScopeVisit'|translate }})</h1>
<div>
{%- for dimension in visitorData.customDimensions['visit'] -%}
<p>
<span>{{ dimension.name }}: </span>
{%- for value in dimension.values -%}
<strong title="{{ value.count }}x">{{ value.value }}</strong>{% if not loop.last %}, {% endif %}
{%- endfor -%}
</p>
{%- endfor -%}
</div>
<div class="visitor-profile-summary visitor-profile-customdimensions">
<h1>{{ 'CustomDimensions_CustomDimensions'|translate }} ({{ scopeName }})</h1>
<div>
{%- for dimension in dimensions -%}
<p>
<span>{{ dimension.name }}: </span>
{%- for value in dimension.values -%}
<strong title="{{ value.count }}x">{{ value.value }}</strong>{% if not loop.last %}, {% endif %}
{%- endfor -%}
</p>
{%- endfor -%}
</div>
{% endif %}

{% if visitorData.customDimensions['action'] is defined and visitorData.customDimensions['action']|length > 0 %}
<div class="visitor-profile-summary visitor-profile-customdimensions">
<h1>{{ 'CustomDimensions_CustomDimensions'|translate }} ({{ 'General_TrackingScopeAction'|translate }})</h1>
<div>
{%- for dimension in visitorData.customDimensions['action'] -%}
<p>
<span>{{ dimension.name }}: </span>
{%- for value in dimension.values -%}
<strong title="{{ value.count }}x">{{ value.value }}</strong>{% if not loop.last %}, {% endif %}
{%- endfor -%}
</p>
{%- endfor -%}
</div>
</div>
{% endif %}
</div>

0 comments on commit 5679c53

Please sign in to comment.