public function run() { $params = Yii::$app->request->getQueryParams(); if (is_callable($this->searchModel)) { $searchModel = call_user_func($this->searchModel, $params); } else { $searchModel = $this->searchModel; } /** @var DataProviderInterface $dataProvider */ $dataProvider = call_user_func($this->dataProvider, $params, $searchModel); /** @var array $gridColumns */ $gridColumns = call_user_func($this->getGridColumns(), $searchModel, $dataProvider, $params); $grid = GridView::widget(['renderAllPages' => true, 'layout' => "{items}", 'showSettings' => false, 'showTotal' => false, 'tableOptions' => ['class' => '', 'border' => 1], 'dataProvider' => $dataProvider, 'columns' => $gridColumns]); $content = strtr(self::EXPORT_TEMPLATE, ['{name}' => $this->reportName, '{grid}' => $grid]); return Yii::$app->response->sendContentAsFile($content, $this->reportName . '.xls', 'application/msexcel'); }
<?php use yii\helpers\Html; use yz\admin\widgets\ActionButtons; use yz\admin\widgets\Box; use yz\admin\grid\GridView; /** * @var yii\web\View $this * @var yii\data\ActiveDataProvider $dataProvider * @var \yz\admin\models\search\UserSearch $searchModel */ $this->title = \yz\admin\models\User::modelTitlePlural(); $this->params['breadcrumbs'][] = $this->title; $this->params['header'] = $this->title; $box = Box::begin(['cssClass' => 'box-primary']); ?> <div class="text-right"> <?php echo ActionButtons::widget(['order' => [['create', 'delete', 'return']], 'gridId' => 'user-grid', 'searchModel' => $searchModel, 'modelClass' => '\\yz\\admin\\models\\User']); ?> </div> <?php echo GridView::widget(['id' => 'user-grid', 'dataProvider' => $dataProvider, 'columns' => [['class' => 'yii\\grid\\CheckboxColumn'], 'id', 'login', 'name', 'email:email', ['attribute' => 'is_identity', 'label' => 'Является идентификатором', 'format' => 'boolean', 'visible' => \yz\admin\models\User::find()->where(['is_identity' => 1])->exists()], 'is_super_admin:boolean', 'is_active:boolean', ['label' => Yii::t('admin/t', 'Roles'), 'value' => function (\yz\admin\models\User $model) { return implode('; ', \yii\helpers\ArrayHelper::getColumn($model->roles, 'description')); }], 'logged_at:datetime', 'created_at:datetime', ['class' => \yz\admin\grid\columns\ActionColumn::class, 'template' => '{update} {delete}']]]); Box::end();
<?php use yii\helpers\Html; use yz\admin\widgets\Box; use yz\admin\grid\GridView; use yz\admin\widgets\ActionButtons; /** * @var yii\web\View $this * @var yii\data\ActiveDataProvider $dataProvider * @var yz\admin\mailer\backend\models\MailSearch $searchModel * @var array $columns */ $this->title = yz\admin\mailer\common\models\Mail::modelTitlePlural(); $this->params['breadcrumbs'][] = $this->title; $this->params['header'] = $this->title; $box = Box::begin(['cssClass' => 'mail-index box-primary']); ?> <div class="text-right"> <?php echo ActionButtons::widget(['order' => [['create', 'delete', 'return']], 'gridId' => 'mail-grid', 'searchModel' => $searchModel, 'modelClass' => 'yz\\admin\\mailer\\common\\models\\Mail']); ?> </div> <?php echo GridView::widget(['id' => 'mail-grid', 'dataProvider' => $dataProvider, 'columns' => array_merge([['class' => 'yii\\grid\\CheckboxColumn']], $columns, [['class' => 'yz\\admin\\widgets\\ActionColumn', 'template' => '{update} {delete}']])]); Box::end();
/** * @param ExportRequest $request * @return bool */ protected function processExportRequest($request) { $controllerClassName = $request->data['controllerClassName']; $actionId = $request->data['actionId']; $requestParams = $request->data['params']; /** @var \backend\base\Controller $originalController */ $originalController = new $controllerClassName('temp-controller', $this->module); /** @var ExportAction $action */ $action = $originalController->createAction($actionId); if (!is_a($action, ExportAction::className())) { return false; } if (is_callable($action->searchModel)) { $searchModel = call_user_func($action->searchModel, $requestParams); } else { $searchModel = $action->searchModel; } /** @var DataProviderInterface $dataProvider */ $dataProvider = call_user_func($action->dataProvider, $requestParams, $searchModel); /** @var array $gridColumns */ $gridColumns = call_user_func($action->getGridColumns(), $searchModel, $dataProvider, $requestParams); try { $exportedContent = GridView::widget(['renderAllPages' => true, 'runInConsoleMode' => true, 'layout' => "{items}", 'tableOptions' => ['class' => ''], 'dataProvider' => $dataProvider, 'columns' => $gridColumns]); } catch (Exception $e) { $request->delete(); SystemEvent::create('error', $request->user_id, Yii::t('admin/export', 'Requested data was not exported, aborting')); return false; } $fileContent = strtr(ExportAction::EXPORT_TEMPLATE, ['{name}' => $action->reportName, '{grid}' => $exportedContent]); $fileName = 'Export_' . $request->id . '_' . strtotime('%d%m%Y%H%i%s') . '.xls'; $request->file = $fileName; $request->is_exported = 1; $request->save(); FileHelper::createDirectory(Yii::getAlias(ExportRequest::FILE_PATH)); file_put_contents(Yii::getAlias($request->fullFileName), $fileContent); SystemEvent::create('success', $request->user_id, Yii::t('admin/export', 'Data requested for exporting is ready'), ['/admin-export/export-requests/index']); return true; }
<?php use yii\helpers\Html; use yii\helpers\Url; use yz\admin\widgets\Box; use yz\admin\grid\GridView; use yz\admin\widgets\ActionButtons; /** * @var yii\web\View $this * @var yii\data\ActiveDataProvider $dataProvider * @var yz\admin\models\search\RoleSearch $searchModel */ $this->title = yz\admin\models\Role::modelTitlePlural(); $this->params['breadcrumbs'][] = $this->title; $this->params['header'] = $this->title; $box = Box::begin(['cssClass' => 'box-primary']); ?> <div class="text-right"> <?php echo ActionButtons::widget(['order' => [['discover'], ['create', 'delete', 'return']], 'buttons' => ['discover' => \yii\bootstrap\ButtonDropdown::widget(['tagName' => 'a', 'label' => Yii::t('admin/t', 'Permissions'), 'encodeLabel' => false, 'options' => ['class' => 'btn btn-default'], 'dropdown' => ['items' => [['label' => Yii::t('admin/t', 'Discover...'), 'url' => Url::to(['discover-auth-items'])], ['label' => Yii::t('admin/t', 'Delete all...'), 'url' => Url::to(['delete-permissions']), 'linkOptions' => ['data-confirm' => Yii::t('admin/t', 'Do you really want to delete all permissions?')]]]]])], 'gridId' => 'role-grid', 'searchModel' => $searchModel, 'modelClass' => 'yz\\admin\\models\\Role']); ?> </div> <?php echo GridView::widget(['id' => 'role-grid', 'dataProvider' => $dataProvider, 'columns' => [['class' => 'yii\\grid\\CheckboxColumn'], 'description:ntext', 'name', ['class' => 'yz\\admin\\widgets\\ActionColumn', 'template' => '{update} {delete}']]]); Box::end();