Skip to content
This repository has been archived by the owner on Feb 17, 2023. It is now read-only.

Commit

Permalink
add: account related data export, Closes #37, Closes #36
Browse files Browse the repository at this point in the history
stats, media tags, media accounts
  • Loading branch information
jakim committed Sep 3, 2018
1 parent 3ed8d12 commit eb4b1c1
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 2 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"nesbot/carbon": "^1.29",
"bower-asset/ladda": "^2.0",
"bower-asset/spin": "^1.1",
"denostr/yii2-bootstrap-social": "^1.0"
"denostr/yii2-bootstrap-social": "^1.0",
"yii2tech/csv-grid": "^1.0"
},
"require-dev": {
"yiisoft/yii2-debug": "~2.0.0",
Expand Down
49 changes: 48 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions modules/admin/controllers/AccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii2tech\csvgrid\CsvGrid;

/**
* AccountController implements the CRUD actions for Account model.
Expand Down Expand Up @@ -167,6 +168,21 @@ public function actionStats($id)
],
]);

if (Yii::$app->request->get('export')) {
$csv = new CsvGrid([
'dataProvider' => $dataProvider,
'columns' => [
'followed_by',
'follows',
'media',
'er',
'created_at',
],
]);

return $csv->export()->send(sprintf('%s_stats_%s.csv', mb_strtolower($model->username), date('Y-m-d')));
}

return $this->render('stats', [
'model' => $model,
'dataProvider' => $dataProvider,
Expand Down Expand Up @@ -198,6 +214,18 @@ public function actionMediaTags($id)
'name' => SORT_ASC,
];

if (Yii::$app->request->get('export')) {
$csv = new CsvGrid([
'dataProvider' => $dataProvider,
'columns' => [
'name',
'occurs',
],
]);

return $csv->export()->send(sprintf('%s_media-tags_%s.csv', mb_strtolower($model->username), date('Y-m-d')));
}


return $this->render('media-tags', [
'model' => $model,
Expand Down Expand Up @@ -230,6 +258,17 @@ public function actionMediaAccounts($id)
'username' => SORT_ASC,
];

if (Yii::$app->request->get('export')) {
$csv = new CsvGrid([
'dataProvider' => $dataProvider,
'columns' => [
'username',
'occurs',
],
]);

return $csv->export()->send(sprintf('%s_media-accounts_%s.csv', mb_strtolower($model->username), date('Y-m-d')));
}

return $this->render('media-accounts', [
'model' => $model,
Expand Down
3 changes: 3 additions & 0 deletions modules/admin/views/account/media-accounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
<div class="nav-tabs-custom">
<?= $this->render('_tabs', ['model' => $model]) ?>
<div class="tab-content">
<p>
<?= \yii\helpers\Html::a('CSV Export', \yii\helpers\Url::current(['export' => 1])) ?>
</p>
<?= \yii\grid\GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
Expand Down
3 changes: 3 additions & 0 deletions modules/admin/views/account/media-tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
<div class="nav-tabs-custom">
<?= $this->render('_tabs', ['model' => $model]) ?>
<div class="tab-content">
<p>
<?= \yii\helpers\Html::a('CSV Export', \yii\helpers\Url::current(['export' => 1])) ?>
</p>
<?= \yii\grid\GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
Expand Down
3 changes: 3 additions & 0 deletions modules/admin/views/account/stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
<div class="nav-tabs-custom">
<?= $this->render('_tabs', ['model' => $model]) ?>
<div class="tab-content">
<p>
<?= \yii\helpers\Html::a('CSV Export', \yii\helpers\Url::current(['export' => 1])) ?>
</p>
<?= \yii\grid\GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
Expand Down

0 comments on commit eb4b1c1

Please sign in to comment.