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 "" . $item->lang->title . ""; } 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();