1ac35977
Alexey Boroda
-Staistics started
|
1
2
3
4
|
<?php
namespace artweb\artbox\ecommerce\controllers;
|
c130fad8
Alexey Boroda
-Yml fix
|
5
6
|
use artweb\artbox\ecommerce\models\Label;
use artweb\artbox\ecommerce\models\Order;
|
ee0e1df5
Alexey Boroda
-Statistics half ...
|
7
|
use yii\data\ActiveDataProvider;
|
c130fad8
Alexey Boroda
-Yml fix
|
8
9
|
use yii\helpers\ArrayHelper;
use yii\helpers\VarDumper;
|
1ac35977
Alexey Boroda
-Staistics started
|
10
11
|
use yii\web\Controller;
|
1ac35977
Alexey Boroda
-Staistics started
|
12
13
|
class StatisticsController extends Controller
{
|
c130fad8
Alexey Boroda
-Yml fix
|
14
|
public function actionIndex($date_range = NULL, $label = NULL)
|
1ac35977
Alexey Boroda
-Staistics started
|
15
|
{
|
c130fad8
Alexey Boroda
-Yml fix
|
16
17
18
19
20
21
|
/**
* Get a dates range
*/
if (!empty($date_range)) {
$arr = [];
preg_match('@(.*)\s:\s(.*)@', $date_range, $arr);
|
ee0e1df5
Alexey Boroda
-Statistics half ...
|
22
23
24
25
26
27
|
$dateFilter = [
'between',
'created_at',
strtotime($arr[1]),
strtotime($arr[2]),
];
|
c130fad8
Alexey Boroda
-Yml fix
|
28
|
} else {
|
ee0e1df5
Alexey Boroda
-Statistics half ...
|
29
|
$dateFilter = [];
|
c130fad8
Alexey Boroda
-Yml fix
|
30
|
}
|
c130fad8
Alexey Boroda
-Yml fix
|
31
32
|
if (!empty($label)) {
|
ee0e1df5
Alexey Boroda
-Statistics half ...
|
33
34
35
|
$labelFilter = ['label' => $label];
} else {
$labelFilter = [];
|
c130fad8
Alexey Boroda
-Yml fix
|
36
37
|
}
|
ee0e1df5
Alexey Boroda
-Statistics half ...
|
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
/**
* Get labels
*/
$labels = Label::find()
->with('lang')
->all();
/**
* Generate statistics
*/
$labelStatistics = ArrayHelper::map(
$labels,
function($model) {
/**
* @var Label $model
*/
return $model->lang->title;
},
function($model) use ($dateFilter) {
/**
* @var Label $model
*/
return $model->getStatistics($dateFilter);}
);
$dataProvider = new ActiveDataProvider([
'query' => Order::find()->filterWhere($dateFilter)->andFilterWhere($labelFilter),
]);
|
c130fad8
Alexey Boroda
-Yml fix
|
67
68
69
70
|
return $this->render(
'index',
[
'labels' => $labels,
|
ee0e1df5
Alexey Boroda
-Statistics half ...
|
71
72
73
|
'labelStatistics' => $labelStatistics,
'rejectionStatistics' => Order::getRejectionStatistics($dateFilter),
'dataProvider' => $dataProvider,
|
c130fad8
Alexey Boroda
-Yml fix
|
74
75
|
]
);
|
1ac35977
Alexey Boroda
-Staistics started
|
76
77
|
}
}
|