ORIENT/plugins/tps/reklama/controllers/StatisticsController.php

58 lines
1.7 KiB
PHP
Raw Normal View History

2021-04-08 08:08:59 +00:00
<?php
namespace Tps\Reklama\Controllers;
use Backend\Classes\Controller;
use Backend\Facades\BackendMenu;
2021-04-13 09:07:38 +00:00
use Illuminate\Support\Facades\DB;
use Tps\Reklama\Models\Reklama;
use Tps\Reklama\Models\Statistika;
use Tps\Reklama\Widgets\Stats;
2021-04-08 08:08:59 +00:00
class StatisticsController extends Controller
{
public $requiredPermissions = ['tps.reklama.statistics'];
public function __construct()
{
parent::__construct();
BackendMenu::setContext('Tps.Reklama', 'main-menu-item', 'side-menu-item3');
2021-04-13 09:07:38 +00:00
2021-04-08 08:08:59 +00:00
}
public function index()
{
2021-04-13 09:07:38 +00:00
// $config = $this->makeConfig('$/tps/reklama/models/statistika/fields.yaml');
$this->pageTitle = 'Statistics';
2021-04-08 08:08:59 +00:00
2021-04-13 09:07:38 +00:00
$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();
2021-04-08 08:08:59 +00:00
}
2021-04-13 09:07:38 +00:00
public function onLoad(){
$item_id = input('item_id');
if($item_id){
$stats = Db::table('tps_reklama_statistika')
->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"))
->where('item_id',$item_id)
->whereNotNull('date')
->groupBy(Db::raw("item_id, extract(year from date), extract(month from date)"))
->orderBy('y')
->orderBy('m')
->get()
->toArray();
return [
'result' => $stats
];
}
2021-04-08 08:08:59 +00:00
}
}