index.php
5.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
use artbox\webcomment\models\CommentModel;
use artbox\webcomment\models\CommentModelSearch;
use MongoDB\Driver\Exception\ExecutionTimeoutException;
use yii\data\ActiveDataProvider;
use yii\grid\GridView;
use yii\helpers\Html;
use yii\helpers\StringHelper;
use yii\web\View;
use yii\widgets\Pjax;
use yii\helpers\Url;
use yii\helpers\Json;
/**
* @var ActiveDataProvider $dataProvider
* @var CommentModelSearch $searchModel
* @var string $commentModel
* @var View $this
*/
$this->title = \Yii::t('artbox-comment', 'Комментарии');
$this->params[ 'breadcrumbs' ][] = $this->title;
$statuses = [
$searchModel::STATUS_ACTIVE => \Yii::t('artbox-comment', 'Активный'),
$searchModel::STATUS_HIDDEN => \Yii::t('artbox-comment', 'Скрытый'),
$searchModel::STATUS_DELETED => \Yii::t('artbox-comment', 'Удаленный'),
];
Pjax::begin();
if (( $success = \Yii::$app->session->getFlash('artbox_comment_success') ) != null) {
echo Html::tag('p', $success);
}
echo GridView::widget(
[
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
'id',
[
'attribute' => 'created_at',
'format' => [
'date',
'php:d.m.Y',
],
'filter' => false,
],
[
'label' => \Yii::t('artbox-comment', 'Комментарий'),
'content' => function (CommentModel $model) {
return StringHelper::truncate($model->text, 40, '...');
},
],
[
'label' => \Yii::t('artbox-comment', 'Сущность '),
'content' => function (CommentModel $model) {
try {
$entity = call_user_func($model->entity . '::find');
} catch (Exception $exception) {
return \Yii::$app->formatter->asText('');
}
$item = $entity->where([ 'id' => $model->entity_id ])
->with(
[
'lang',
'lang.alias',
]
)
->one();
if ($item !== null) {
if ($urlManagerFrontend = \Yii::$app->get('urlManagerFrontend', false)) {
return "<a href='" . $urlManagerFrontend->createUrl(
Json::decode($item->lang->alias->route)
) . "'>" . $item->lang->title . "</a>";
}
return $item->lang->title;
}
return 'Товар удален';
},
],
[
'attribute' => 'customer_id',
'value' => function ($model) {
/**
* @var CommentModel $model
*/
if (!empty($model->customer)) {
return $model->customer->username . ' (id:' . $model->customer->id . ')';
} else {
return $model->username . ' ' . $model->email . ' (' . \Yii::t(
'artbox-comment',
'Гость'
) . ')';
}
},
],
[
'attribute' => 'status',
'filter' => $statuses,
'value' => function ($model) use ($statuses) {
/**
* @var CommentModel $model
*/
if (array_key_exists($model->status, $statuses)) {
return $statuses[ $model->status ];
} else {
return null;
}
},
],
[
'attribute' => 'ratingValue',
'value' => function ($model) {
/**
* @var CommentModel $model
*/
if (!empty($model->rating)) {
return $model->rating->value;
}
return null;
},
],
[
'attribute' => 'childrenCount',
'value' => function ($model) {
/**
* @var CommentModel $model
*/
return count($model->children);
},
],
[
'class' => 'yii\grid\ActionColumn',
'buttons' => [
'answer' => function (string $url) {
return Html::a(Html::tag('i', '', [ 'class' => 'glyphicon glyphicon-bullhorn' ]), $url);
},
],
'template' => '{update} {answer} {delete}',
],
],
]
);
Pjax::end();