105 lines
2.8 KiB
PHP
105 lines
2.8 KiB
PHP
<?php
|
|
|
|
|
|
namespace Tps\Reklama\Controllers;
|
|
use Backend\Classes\Controller;
|
|
use Backend\Facades\BackendMenu;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Tps\Reklama\Models\Reklama;
|
|
use Tps\Reklama\Models\Statistika;
|
|
use Tps\Reklama\Widgets\Stats;
|
|
|
|
class StatisticsController extends Controller
|
|
{
|
|
public $requiredPermissions = ['tps.reklama.statistics'];
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
|
|
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()
|
|
{
|
|
$this->pageTitle = 'Statistics';
|
|
|
|
$this->vars['stats'] = Statistika::groupBy('item_id')
|
|
->selectRaw('tps_reklama_item.id, tps_reklama_item.title, sum(view) as views, sum(click) as clicks')
|
|
->leftJoin('tps_reklama_item','tps_reklama_item.id','=','tps_reklama_statistika.item_id')
|
|
->take(20)
|
|
->get()
|
|
->toArray();
|
|
}
|
|
|
|
protected function getCurrentFilters() {
|
|
$filters = [];
|
|
foreach (\Session::get('widget', []) as $name => $item) {
|
|
if (str_contains($name, 'Filter')) {
|
|
$filter = @unserialize(@base64_decode($item));
|
|
if ($filter) {
|
|
//$filters[] = $filter;
|
|
array_push($filters, $filter);
|
|
}
|
|
}
|
|
}
|
|
|
|
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();
|
|
|
|
dd($stats->get());
|
|
$this->vars['count_view'] = 30;
|
|
|
|
return ['#linechart' => $this->makePartial('linechart')];
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|