statistika completed
This commit is contained in:
parent
e45c062e11
commit
afe821a220
|
|
@ -4,7 +4,9 @@
|
||||||
namespace Tps\Reklama\Controllers;
|
namespace Tps\Reklama\Controllers;
|
||||||
use Backend\Classes\Controller;
|
use Backend\Classes\Controller;
|
||||||
use Backend\Facades\BackendMenu;
|
use Backend\Facades\BackendMenu;
|
||||||
|
use Carbon\Carbon;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
use Tps\Reklama\Models\Reklama;
|
use Tps\Reklama\Models\Reklama;
|
||||||
use Tps\Reklama\Models\Statistika;
|
use Tps\Reklama\Models\Statistika;
|
||||||
use Tps\Reklama\Widgets\Stats;
|
use Tps\Reklama\Widgets\Stats;
|
||||||
|
|
@ -19,11 +21,21 @@ class StatisticsController extends Controller
|
||||||
|
|
||||||
BackendMenu::setContext('Tps.Reklama', 'main-menu-item', 'side-menu-item3');
|
BackendMenu::setContext('Tps.Reklama', 'main-menu-item', 'side-menu-item3');
|
||||||
|
|
||||||
|
$config = $this->makeConfig('$/tps/reklama/controllers/statisticscontroller/config_filter.yaml');
|
||||||
|
|
||||||
|
$widget = $this->makeWidget('Backend\Widgets\Filter',$config);
|
||||||
|
|
||||||
|
$this->vars['widget'] = $widget;
|
||||||
|
|
||||||
|
$widget->bindEvent('filter.update', function () use($widget){
|
||||||
|
return $this->onFilteer();
|
||||||
|
});
|
||||||
|
|
||||||
|
$widget->bindToController();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
// $config = $this->makeConfig('$/tps/reklama/models/statistika/fields.yaml');
|
|
||||||
$this->pageTitle = 'Statistics';
|
$this->pageTitle = 'Statistics';
|
||||||
|
|
||||||
$this->vars['stats'] = Statistika::groupBy('item_id')
|
$this->vars['stats'] = Statistika::groupBy('item_id')
|
||||||
|
|
@ -32,26 +44,58 @@ class StatisticsController extends Controller
|
||||||
->take(20)
|
->take(20)
|
||||||
->get()
|
->get()
|
||||||
->toArray();
|
->toArray();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onLoad(){
|
protected function getCurrentFilters() {
|
||||||
$item_id = input('item_id');
|
$filters = [];
|
||||||
|
foreach (\Session::get('widget', []) as $name => $item) {
|
||||||
if($item_id){
|
if (str_contains($name, 'Filter')) {
|
||||||
$stats = Db::table('tps_reklama_statistika')
|
$filter = @unserialize(@base64_decode($item));
|
||||||
->select(Db::raw("item_id,sum(view) as v, sum(click) as c, extract(year from date) as y, extract(month from date) as m"))
|
if ($filter) {
|
||||||
->where('item_id',$item_id)
|
//$filters[] = $filter;
|
||||||
->whereNotNull('date')
|
array_push($filters, $filter);
|
||||||
->groupBy(Db::raw("item_id, extract(year from date), extract(month from date)"))
|
}
|
||||||
->orderBy('y')
|
}
|
||||||
->orderBy('m')
|
|
||||||
->get()
|
|
||||||
->toArray();
|
|
||||||
return [
|
|
||||||
'result' => $stats
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $filters[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onFilteer(){
|
||||||
|
|
||||||
|
$this->vars['reklama'] = 'Reklama';
|
||||||
|
|
||||||
|
$filters = $this->getCurrentFilters();
|
||||||
|
|
||||||
|
$reklamas = $filters['scope-reklama'];
|
||||||
|
|
||||||
|
$dates = $filters['scope-date'];
|
||||||
|
|
||||||
|
if($reklamas)
|
||||||
|
{
|
||||||
|
$ids = array_keys($reklamas);
|
||||||
|
|
||||||
|
$stats = Db::table('tps_reklama_statistika')
|
||||||
|
->select(Db::raw("item_id,view, click, date"))
|
||||||
|
->whereIn('item_id',$ids);
|
||||||
|
|
||||||
|
if($dates){
|
||||||
|
$stats->where('date','>=',$dates[0])
|
||||||
|
->where('date','<=',$dates[1]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$stats->where('date','<=',Carbon::today()->startOfMonth());
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->vars['reklams'] = $reklamas;
|
||||||
|
|
||||||
|
$this->vars['reklam_stats'] = $stats->get();
|
||||||
|
|
||||||
|
return ['#linechart' => $this->makePartial('linechart')];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
<div
|
||||||
|
class="row m-y"
|
||||||
|
id="chart_div" style="width:100%; height:<?=count($stats)*60?>px">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<script>
|
||||||
|
google.charts.load('current', {packages: ['corechart', 'bar']});
|
||||||
|
google.charts.setOnLoadCallback(drawMultSeries);
|
||||||
|
|
||||||
|
function drawMultSeries() {
|
||||||
|
var data = google.visualization.arrayToDataTable([
|
||||||
|
['Reklama', 'Views', 'Clicks'],
|
||||||
|
<?php foreach($stats as $stat){
|
||||||
|
echo "['{$stat['title']}',{$stat['views']},{$stat['clicks']}],";
|
||||||
|
} ?>
|
||||||
|
]);
|
||||||
|
|
||||||
|
var options = {
|
||||||
|
title: 'Reklama views and clicks',
|
||||||
|
|
||||||
|
chartArea: {width: '60%'},
|
||||||
|
hAxis: {
|
||||||
|
title: 'Views and Clicks',
|
||||||
|
minValue: 0
|
||||||
|
},
|
||||||
|
vAxis: {
|
||||||
|
title: 'Reklamalar'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var chart = new google.visualization.BarChart(document.getElementById('chart_div'));
|
||||||
|
chart.draw(data, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
<?php foreach($reklams as $id => $reklam):?>
|
||||||
|
<div
|
||||||
|
class="tab-pane active"
|
||||||
|
id="curve_chart_<?=$id?>" style="width:100%; height:400px; margin-top: 10px;">
|
||||||
|
</div>
|
||||||
|
<script>
|
||||||
|
google.charts.load('current', {'packages':['corechart']});
|
||||||
|
google.charts.setOnLoadCallback(drawLineChart_<?=$id?>);
|
||||||
|
|
||||||
|
function drawLineChart_<?=$id?>(){
|
||||||
|
var data = google.visualization.arrayToDataTable([
|
||||||
|
['date', 'views', 'clicks',],
|
||||||
|
<?php foreach($reklam_stats->where('item_id',$id) as $stats):?>
|
||||||
|
['<?=date_format(date_create($stats->date),'m/d')?>', <?=$stats->view?>,<?=$stats->click?>],
|
||||||
|
<?php endforeach; ?>
|
||||||
|
]);
|
||||||
|
var options = {
|
||||||
|
title: '<?=$reklam?>',
|
||||||
|
curveType: 'function',
|
||||||
|
legend: { position: 'bottom' }
|
||||||
|
};
|
||||||
|
var curve_chart = new google.visualization.LineChart(document.getElementById('curve_chart_<?=$id?>'));
|
||||||
|
curve_chart.draw(data, options);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<?php endforeach;?>
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
# ===================================
|
||||||
|
# Filter Scope Definitions
|
||||||
|
# ===================================
|
||||||
|
|
||||||
|
scopes:
|
||||||
|
|
||||||
|
reklama:
|
||||||
|
label: Reklama
|
||||||
|
type: group
|
||||||
|
conditions: item_id = (:filtered)
|
||||||
|
modelClass: Tps\Reklama\Models\Statistika
|
||||||
|
options: filterCategory
|
||||||
|
|
||||||
|
date:
|
||||||
|
label: Date
|
||||||
|
type: daterange
|
||||||
|
conditions: date >= ':afterDate' AND published_at <= ':beforeDate'
|
||||||
|
minDate: '2021-04-01'
|
||||||
|
yearRange: 1
|
||||||
|
|
||||||
|
# status:
|
||||||
|
# label: Active
|
||||||
|
# type: switch
|
||||||
|
# default: 1
|
||||||
|
# conditions:
|
||||||
|
# - active <> true
|
||||||
|
# - active = true
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
|
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
|
||||||
<div class="control-breadcrumb">
|
<div class="control-breadcrumb">
|
||||||
<ul>
|
<ul>
|
||||||
<li>Statistics</li>
|
<li>Statistics</li>
|
||||||
|
|
@ -8,83 +8,15 @@
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="layout-row min-size">
|
<div class="layout-row min-size">
|
||||||
<div
|
<?=$this->makePartial('barchart')?>
|
||||||
class="tab-pane active m-y"
|
|
||||||
id="chart_div" style="width:100%; height:<?=count($stats)*60?>px">
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div class="row m-t-lg">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<?=$widget->render()?>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group m-x m-y">
|
<div id="linechart" class="col-md-12">
|
||||||
<select name = "reklama" class="form-control"
|
|
||||||
onchange="$(this).request('onLoad', {
|
|
||||||
data:{item_id:this.value},
|
|
||||||
success: function(data) {
|
|
||||||
console.log(data);
|
|
||||||
}
|
|
||||||
}); return false;"
|
|
||||||
>
|
|
||||||
<?php foreach($stats as $stat):?>
|
|
||||||
<option value="<?=$stat['id']?>" ><?=$stat['title']?></option>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
class="tab-pane active"
|
|
||||||
id="curve_chart" style="width:100%; height:400px; margin-top: 10px;">
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
|
|
||||||
|
|
||||||
|
|
||||||
<script>
|
|
||||||
google.charts.load('current', {packages: ['corechart', 'bar']});
|
|
||||||
google.charts.setOnLoadCallback(drawMultSeries);
|
|
||||||
|
|
||||||
function drawMultSeries() {
|
|
||||||
var data = google.visualization.arrayToDataTable([
|
|
||||||
['Reklama', 'Views', 'Clicks'],
|
|
||||||
<?php foreach($stats as $stat){
|
|
||||||
echo "['{$stat['title']}',{$stat['views']},{$stat['clicks']}],";
|
|
||||||
} ?>
|
|
||||||
]);
|
|
||||||
|
|
||||||
var options = {
|
|
||||||
title: 'Reklama views and clicks',
|
|
||||||
|
|
||||||
chartArea: {width: '60%'},
|
|
||||||
hAxis: {
|
|
||||||
title: 'Views and Clicks',
|
|
||||||
minValue: 0
|
|
||||||
},
|
|
||||||
vAxis: {
|
|
||||||
title: 'Reklamalar'
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
var chart = new google.visualization.BarChart(document.getElementById('chart_div'));
|
|
||||||
chart.draw(data, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
google.charts.load('current', {'packages':['corechart']});
|
|
||||||
google.charts.setOnLoadCallback(drawChart);
|
|
||||||
|
|
||||||
function drawChart() {
|
|
||||||
var data = google.visualization.arrayToDataTable([
|
|
||||||
['Year', 'views', 'clicks','req3'],
|
|
||||||
['2004', 1000, 400,555],
|
|
||||||
['2005', 1170, 460,444],
|
|
||||||
['2006', 660, 1120,666],
|
|
||||||
['2007', 1030, 540,777]
|
|
||||||
]);
|
|
||||||
|
|
||||||
var options = {
|
|
||||||
title: 'Company Performance',
|
|
||||||
curveType: 'function',
|
|
||||||
legend: { position: 'bottom' }
|
|
||||||
};
|
|
||||||
|
|
||||||
var curve_chart = new google.visualization.LineChart(document.getElementById('curve_chart'));
|
|
||||||
|
|
||||||
curve_chart.draw(data, options);
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
|
||||||
|
|
@ -33,4 +33,15 @@ class Statistika extends Model
|
||||||
'order' => 'name'
|
'order' => 'name'
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
public function filterCategory()
|
||||||
|
{
|
||||||
|
$result = [];
|
||||||
|
|
||||||
|
foreach (Reklama::where('active', 1)->orderBy('title', 'asc')->get()->all() as $item) {
|
||||||
|
$result[$item->id] = $item->title;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
secondaryTabs:
|
tabs:
|
||||||
stretch: true
|
stretch: true
|
||||||
fields:
|
fields:
|
||||||
general_stats:
|
general_stats:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue