first commit
This commit is contained in:
@@ -0,0 +1,182 @@
|
||||
<?php
|
||||
|
||||
|
||||
class appAdsTrackerWidgetBackendActions extends stGadgetActions
|
||||
{
|
||||
|
||||
public function executeAdsTrackerEnteringWidget()
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
$i18n = $this->getContext()->getI18N();
|
||||
|
||||
|
||||
$context = $this->getContext();
|
||||
$this->config = stConfig::getInstance($context);
|
||||
$this->config->setCulture($this->getRequestParameter('culture', stLanguage::getOptLanguage()));
|
||||
|
||||
$currency_config = stConfig::getInstance($this->getContext(), 'stCurrencyPlugin');
|
||||
$this->default_currency = $currency_config->get('default_currency');
|
||||
|
||||
if (!appAdsTracker::getIsAdsTrackerActive()) {
|
||||
$i18n = $this->getContext()->getI18n();
|
||||
$notice = $i18n->__('Moduł analizy reklam nie jest aktywny i nie zbiera danych.')." ".$i18n->__('Aby go aktywować przejdź do konfiguracji modułu.')." ".'<a href="'.$this->getController()->genUrl("appAdsTrackerBackend/config").'" target="_blank">'.$i18n->__('Konfiguracja').'</a>';
|
||||
$this->setFlash("info", $notice, false);
|
||||
}
|
||||
|
||||
|
||||
$filters = $this->getFiltersEntering();
|
||||
|
||||
$this->from_date = $filters['from_date'];
|
||||
$this->to_date = $filters['to_date'];
|
||||
|
||||
$this->getUser()->setAttribute("filters", $filters, 'soteshop/appAdsTrackerPlugin');
|
||||
|
||||
$result = appAdsTracker::getReportsPlatformEnteringValue($filters);
|
||||
|
||||
|
||||
$this->result = $result;
|
||||
|
||||
$this->filters = $filters;
|
||||
|
||||
$this->periods = $this->getPeriods();
|
||||
|
||||
$this->platforms = $this->getPlatforms();
|
||||
|
||||
//$this->labels = $this->getLabels();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected function getFiltersEntering()
|
||||
{
|
||||
$config = stConfig::getInstance($this->getContext(), 'appAdsTrackerBackend');
|
||||
|
||||
|
||||
$filters = $this->getRequestParameter('filters', $this->getDefaultFiltersEntering());
|
||||
|
||||
$periods_array = $this->getDateFromPeriods($filters['period']);
|
||||
|
||||
$filters['from_date'] = $periods_array['from']." 00:00:00";
|
||||
$filters['to_date'] = $periods_array['to']." 23:59:59";
|
||||
|
||||
$filters_default = json_decode($config->get('platform_entering_default_view'));
|
||||
|
||||
|
||||
foreach ($filters_default as $platform_label => $platform_id) {
|
||||
$filters['platform'][$platform_label] = $platform_id;
|
||||
}
|
||||
|
||||
if ($this->getRequest()->hasParameter('filters')) {
|
||||
$config = stConfig::getInstance('appAdsTrackerBackend');
|
||||
$config->set('entering_widget_period', $filters['period']);
|
||||
$config->save();
|
||||
}
|
||||
|
||||
return $filters;
|
||||
}
|
||||
|
||||
protected function getDefaultFiltersEntering()
|
||||
{
|
||||
$config = stConfig::getInstance($this->getContext(), 'appAdsTrackerBackend');
|
||||
|
||||
$filters_platform = json_decode($config->get('platform_entering_default_view'),true);
|
||||
$filters_period = $config->get('entering_widget_period');
|
||||
|
||||
|
||||
if ($filters_period!="") {
|
||||
$periods_array = $this->getDateFromPeriods($filters_period);
|
||||
|
||||
$default_date_from = $periods_array['from']." 00:00:00";
|
||||
$default_date_to = $periods_array['to']." 23:59:59";
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (is_array($filters_platform)) {
|
||||
|
||||
return array('from_date' => $default_date_from, 'to_date' => $default_date_to, 'platform'=>$filters_platform, 'period'=>$filters_period );
|
||||
}
|
||||
|
||||
$c = new Criteria();
|
||||
$c->add(AdsTrackerPlatformPeer::IS_ACTIVE, 1);
|
||||
$c->add(AdsTrackerPlatformPeer::IS_SYSTEM_DEFAULT, 1);
|
||||
$platform = AdsTrackerPlatformPeer::doSelectOne($c);
|
||||
|
||||
|
||||
if ($platform) {
|
||||
return array('from_date' => $default_date_from, 'to_date' => $default_date_to, 'platform'=>array($platform->getAdsName()=>$platform->getId()), 'period'=>$filters_period);
|
||||
} else {
|
||||
return array('from_date' => $default_date_from, 'to_date' => $default_date_to, 'period'=>$filters_period);
|
||||
}
|
||||
}
|
||||
|
||||
public function getDateFromPeriods($period)
|
||||
{
|
||||
|
||||
$date['from'] = "";
|
||||
$date['to'] = "";
|
||||
|
||||
if ($period=="14day") {
|
||||
$date['from'] = date("Y-m-d", strtotime('-14 day'));
|
||||
$date['to'] = date("Y-m-d", strtotime('-1 day'));
|
||||
}
|
||||
|
||||
if ($period=="30day") {
|
||||
$date['from'] = date("Y-m-d", strtotime('-30 day'));
|
||||
$date['to'] = date("Y-m-d", strtotime('-1 day'));
|
||||
}
|
||||
|
||||
|
||||
if ($period=="month") {
|
||||
$date['from'] = date("Y-m-d", strtotime('first day of this month'));
|
||||
$date['to'] = date("Y-m-d", strtotime('today'));
|
||||
}
|
||||
|
||||
if ($period=="custom") {
|
||||
|
||||
}
|
||||
|
||||
return $date;
|
||||
}
|
||||
|
||||
public function getPeriods()
|
||||
{
|
||||
$i18n = $this->getContext()->getI18N();
|
||||
|
||||
// Dzisiaj
|
||||
// Wczoraj
|
||||
// Ostatnie 7 dni
|
||||
// Ostatnie 14 dni
|
||||
// Ostatnie 30 dni
|
||||
// Ostatnie 90 dni
|
||||
// Bieżący miesiąc
|
||||
// Poprzedni miesiąc
|
||||
|
||||
return array(
|
||||
'14day' => $i18n->__('Ostatnie 14 dni'),
|
||||
'30day' => $i18n->__('Ostatnie 30 dni'),
|
||||
'month' => $i18n->__('Bieżący miesiąc'),
|
||||
);
|
||||
}
|
||||
|
||||
public function getPlatforms()
|
||||
{
|
||||
//pobieranie platform
|
||||
|
||||
$c = new Criteria();
|
||||
$c->add(AdsTrackerPlatformPeer::IS_ACTIVE, 1);
|
||||
$platforms = AdsTrackerPlatformPeer::doSelect($c);
|
||||
|
||||
if ($platforms) {
|
||||
|
||||
foreach ($platforms as $platform) {
|
||||
$my_platform[$platform->getId()] = $platform->getAdsName();
|
||||
}
|
||||
|
||||
return $my_platform;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,360 @@
|
||||
<?php use_helper('I18N', 'Text', 'stAdminGenerator', 'ObjectAdmin', 'stDate', 'stProductImage', 'stCurrency') ?>
|
||||
<?php use_helper('stGadget', 'stOrder'); ?>
|
||||
|
||||
<?php
|
||||
use_helper('I18N', 'stAdminGenerator', 'stJQueryTools','stCurrency', 'stOrder', 'stPrice', 'stJQueryTools', 'stProductImage', 'stDiscount','Validation', 'stDate');
|
||||
sfLoader::loadHelpers('stProduct', 'stProduct');
|
||||
?>
|
||||
|
||||
<div id="entering-widget">
|
||||
|
||||
|
||||
<script type="text/javascript" src="/js/backend/chart.min.js"> </script>
|
||||
|
||||
<style>
|
||||
|
||||
.list_filters select, .list_filters input {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
#filters_from_date, #filters_to_date {
|
||||
width: 100px;
|
||||
}
|
||||
|
||||
#date-filters {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
#date-filters li {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
#myChart2{
|
||||
width:100%;
|
||||
height: auto;
|
||||
/*max-height: 400px;*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
</style>
|
||||
|
||||
|
||||
<div>
|
||||
|
||||
<?php
|
||||
$datetime1 = date_create($from_date);
|
||||
$datetime2 = date_create($to_date);
|
||||
$interval = date_diff($datetime1, $datetime2);
|
||||
|
||||
$count_days = count($result['chart']['labels']);
|
||||
|
||||
//echo $interval;
|
||||
|
||||
?>
|
||||
|
||||
<form action="<?php echo url_for('appAdsTrackerWidgetBackend/adsTrackerEnteringWidget') ?>" method="post" style="margin-bottom: 10px">
|
||||
<div class="list_filters">
|
||||
|
||||
<?php
|
||||
/*echo "<pre>";
|
||||
print_r($filters);
|
||||
echo "</pre>";*/
|
||||
|
||||
$link_to_raport = "";
|
||||
|
||||
foreach ($platforms as $platform_id => $platform_label ){
|
||||
|
||||
if ( @$filters['platform'][$platform_label] == $platform_id) {
|
||||
$link_to_raport .= '&filters[platform]['.$platform_label.']='.$platform_id;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
<ul class="header">
|
||||
<li>
|
||||
<div id="filters_period">
|
||||
<label><?php echo __("Zakres") ?></label>
|
||||
<select id="filters_period_select" name="filters[period]">
|
||||
<?php
|
||||
foreach ($periods as $period => $label): ?>
|
||||
<option value="<?php echo $period ?>" <?php
|
||||
if ($filters['period']==$period): ?>selected<?php endif; ?>><?php echo $label ?></option>
|
||||
<?php endforeach ?>
|
||||
</select>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
<li class="filter-control">
|
||||
<label> </label>
|
||||
<button class="button button-search no-label with-icon" type="submit">
|
||||
<span class="svg-icon svg-icon-search" style="-webkit-mask-image: url(/images/backend/icons/svg/search.svg?v=2); mask-image: url(/images/backend/icons/svg/search.svg?v=2); " title=""></span>
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="clr"></div>
|
||||
|
||||
</div>
|
||||
</form>
|
||||
<?php
|
||||
if (appAdsTracker::chartDisplayType($from_date, $to_date)!="none"): ?>
|
||||
|
||||
<div style="text-align: center; font-size: 12px; top: 12px; position: relative;"><?php echo date('d-m-Y', strtotime($from_date)); ?> / <?php echo date('d-m-Y', strtotime($to_date)); ?></div>
|
||||
<div class="chart-container" style="position: relative; width: 100%; height: 240px">
|
||||
<canvas id="myChart2"></canvas>
|
||||
</div>
|
||||
|
||||
<br>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
<?php
|
||||
$change_range_brutto = 0;
|
||||
$change_range_entering = 0;
|
||||
|
||||
$sum_total_entering = 0;
|
||||
$sum_conversion = 0;
|
||||
$sum_total_brutto = 0;
|
||||
|
||||
|
||||
foreach ($result['platform'] as $platform):
|
||||
|
||||
if ($platform['total_brutto']>0) {
|
||||
$change_range_brutto = 1;
|
||||
}
|
||||
|
||||
if ($platform['total_entering']>0) {
|
||||
$change_range_entering = 1;
|
||||
}
|
||||
|
||||
|
||||
$sum_total_entering += $platform['total_entering'];
|
||||
$sum_conversion += $platform['conversion'];
|
||||
$sum_total_brutto += $platform['total_brutto'];
|
||||
|
||||
endforeach;
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
||||
<div style="width: 200px; float: left; padding: 15px;">
|
||||
<b><?php echo __('Wejścia') ?></b><br />
|
||||
|
||||
<?php echo __('Łączna ilość wejść') ?>: <?php echo $sum_total_entering ?><br />
|
||||
|
||||
<?php echo __('Średnia wejść dziennie') ?>: <?php echo round($sum_total_entering/$count_days) ?><br />
|
||||
</div>
|
||||
|
||||
|
||||
<div style="min-width: 300px; float: left; padding: 15px;">
|
||||
<b><?php echo __('Platformy') ?></b> <br />
|
||||
|
||||
<?php foreach ($result['platform'] as $platform): ?>
|
||||
|
||||
<?php echo appAdsTracker::langFilter($platform['name']) ?>: <?php echo $platform['total_entering'] ?><br />
|
||||
|
||||
<?php endforeach; ?>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
<div class="clr"></div>
|
||||
|
||||
<?php
|
||||
|
||||
// echo "<pre>";
|
||||
// print_r($result);
|
||||
// echo "</pre>";
|
||||
|
||||
?>
|
||||
|
||||
<?php
|
||||
|
||||
$chart_labels = json_encode(array_values($result['chart']['labels']));
|
||||
$chart_data = json_encode(array_values($result['chart']['dates']));
|
||||
|
||||
?>
|
||||
|
||||
|
||||
<script>
|
||||
jQuery(function($) {
|
||||
$('#trigger_filters_from_date, #trigger_filters_to_date').click(function() {
|
||||
console.log("wybrano custom");
|
||||
$("#filters_period_select").val("custom");
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
<?php
|
||||
if (appAdsTracker::chartDisplayType($from_date, $to_date)!="none")
|
||||
: ?>
|
||||
|
||||
<script>
|
||||
|
||||
jQuery(function($) {
|
||||
|
||||
var y_label_char = 0;
|
||||
|
||||
<?php
|
||||
$i=0;
|
||||
foreach ($result['chart']['platform'] as $key => $value):
|
||||
?>
|
||||
|
||||
var quantites<?php echo $i ?> = <?php echo json_encode(array_values($value['count'])); ?>
|
||||
|
||||
<?php
|
||||
$i++;
|
||||
endforeach;
|
||||
?>
|
||||
|
||||
|
||||
|
||||
var chart_dates = <?php echo $chart_data ?>;
|
||||
var display_type = "day";
|
||||
|
||||
|
||||
|
||||
|
||||
// wejścia
|
||||
|
||||
|
||||
var chart = $("#myChart2");
|
||||
|
||||
var data2 = {
|
||||
labels: <?php echo $chart_labels ?>,
|
||||
datasets: [
|
||||
|
||||
|
||||
<?php foreach ($result['chart']['platform'] as $key => $value): ?>
|
||||
|
||||
{
|
||||
label: "<?php echo appAdsTracker::langFilter($key) ?>",
|
||||
fill: false,
|
||||
lineTension: 0.1,
|
||||
backgroundColor: "<?php echo '#'.$value['color'] ?>",
|
||||
borderColor: "<?php echo '#'.$value['color'] ?>",
|
||||
borderCapStyle: 'butt',
|
||||
borderDash: [],
|
||||
borderDashOffset: 0.0,
|
||||
borderJoinStyle: 'miter',
|
||||
pointBorderColor: "<?php echo '#'.$value['color'] ?>",
|
||||
pointBackgroundColor: "#fff",
|
||||
pointBorderWidth: 1,
|
||||
pointHoverRadius: 5,
|
||||
pointHoverBackgroundColor: "<?php echo '#'.$value['color'] ?>",
|
||||
pointHoverBorderColor: "rgba(220,220,220,1)",
|
||||
pointHoverBorderWidth: 2,
|
||||
pointRadius: 3,
|
||||
pointHitRadius: 10,
|
||||
pointStyle: "circle",
|
||||
data: <?php echo json_encode(array_values($value['entering'])); ?>,
|
||||
},
|
||||
|
||||
<?php endforeach; ?>
|
||||
|
||||
|
||||
]
|
||||
};
|
||||
|
||||
var options2 = {
|
||||
hover: {
|
||||
onHover: function(data) {
|
||||
if (display_type == "month") {
|
||||
if (data.length && quantites[data[0]._index] > 0) {
|
||||
chart.css({ cursor: 'pointer' });
|
||||
} else {
|
||||
chart.css({ cursor: 'default' });
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
onClick: function(e) {
|
||||
if (display_type == "month") {
|
||||
var elements = this.getElementsAtEvent(e);
|
||||
|
||||
if (elements.length && quantites[elements[0]._index] > 0) {
|
||||
|
||||
window.location = chart.closest('form').attr('action')+'?filters[filter_order_status]='+$('#filters_filter_order_status').val()+'&filters[expand_date]='+chart_dates[elements[0]._index];
|
||||
}
|
||||
}
|
||||
},
|
||||
responsive: true,
|
||||
maintainAspectRatio: false,
|
||||
legend: { display: true },
|
||||
tooltips: {
|
||||
enabled: true,
|
||||
mode: 'single',
|
||||
callbacks: {
|
||||
label: function(tooltipItems, data2) {
|
||||
return "<?php echo __('wejść') ?>: "+tooltipItems.yLabel;
|
||||
},
|
||||
title: function(tooltipItems, data2) {
|
||||
return chart_dates[tooltipItems[0].index];
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
scales: {
|
||||
xAxes: [{
|
||||
stacked: true,
|
||||
barPercentage: 0.5,
|
||||
maxBarThickness: 120,
|
||||
}],
|
||||
yAxes: [{
|
||||
stacked: true,
|
||||
ticks: {
|
||||
|
||||
beginAtZero:true,
|
||||
<?php if ($change_range_entering == 0): ?>
|
||||
stepSize: 50,
|
||||
<?php elseif ($sum_total_entering < 10): ?>
|
||||
stepSize: 1,
|
||||
<?php endif; ?>
|
||||
userCallback: function(value, index, values) {
|
||||
value = Number(value);
|
||||
return value;
|
||||
}
|
||||
},
|
||||
afterDataLimits(scale) {
|
||||
if (scale.max==1) {
|
||||
scale.max = 10;
|
||||
} else {
|
||||
var my_y = scale.max*0.2;
|
||||
scale.max += my_y;
|
||||
}
|
||||
}
|
||||
}]
|
||||
},
|
||||
title: {
|
||||
display: false,
|
||||
text: '<?php echo __('Raport wejść') ?>'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var myLineChart = new Chart(chart.get(0), {
|
||||
type: 'bar',
|
||||
data: data2,
|
||||
options: options2
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
});
|
||||
</script>
|
||||
|
||||
<?php endif; ?>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
Reference in New Issue
Block a user