Skip to content

Commit

Permalink
TE-9182 Added possibility to download GUI tables as CSV file (#8346)
Browse files Browse the repository at this point in the history
TE-9182 Export Table Views
  • Loading branch information
stereomon authored Jun 30, 2021
1 parent 5ae5836 commit 71dd235
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"php": ">=7.3",
"spryker/country": "^3.0.0",
"spryker/customer-extension": "^1.3.0",
"spryker/gui": "^3.17.0",
"spryker/gui": "^3.39.0",
"spryker/kernel": "^3.52.0",
"spryker/locale": "^3.0.0",
"spryker/mail": "^4.6.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

/**
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
*/

namespace Spryker\Zed\Customer\Communication\Controller;

use Spryker\Zed\Kernel\Communication\Controller\AbstractController;
use Symfony\Component\HttpFoundation\StreamedResponse;

/**
* @method \Spryker\Zed\Customer\Business\CustomerFacadeInterface getFacade()
* @method \Spryker\Zed\Customer\Communication\CustomerCommunicationFactory getFactory()
* @method \Spryker\Zed\Customer\Persistence\CustomerQueryContainerInterface getQueryContainer()
* @method \Spryker\Zed\Customer\Persistence\CustomerRepositoryInterface getRepository()
*/
class DownloadController extends AbstractController
{
/**
* @return \Symfony\Component\HttpFoundation\StreamedResponse
*/
public function indexAction(): StreamedResponse
{
return $this->getFactory()->createCustomerTable()->streamDownload();
}
}
44 changes: 44 additions & 0 deletions src/Spryker/Zed/Customer/Communication/Table/CustomerTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@

use Orm\Zed\Customer\Persistence\Map\SpyCustomerTableMap;
use Orm\Zed\Customer\Persistence\SpyCustomer;
use Propel\Runtime\ActiveQuery\ModelCriteria;
use Propel\Runtime\ActiveRecord\ActiveRecordInterface;
use Propel\Runtime\Collection\ObjectCollection;
use Spryker\Zed\Customer\Communication\Table\PluginExecutor\CustomerTableExpanderPluginExecutorInterface;
use Spryker\Zed\Customer\Dependency\Service\CustomerToUtilDateTimeServiceInterface;
use Spryker\Zed\Customer\Persistence\CustomerQueryContainerInterface;
use Spryker\Zed\Gui\Communication\Table\AbstractTable;
use Spryker\Zed\Gui\Communication\Table\TableConfiguration;
use Spryker\Zed\PropelOrm\Business\Runtime\ActiveQuery\Criteria;

class CustomerTable extends AbstractTable
{
Expand Down Expand Up @@ -99,6 +102,47 @@ protected function configure(TableConfiguration $config)
return $config;
}

/**
* @return string[]
*/
protected function getCsvHeaders(): array
{
return [
static::COL_ID_CUSTOMER => '#',
static::COL_CREATED_AT => 'Registration Date',
static::COL_EMAIL => 'Email',
static::COL_LAST_NAME => 'Last Name',
static::COL_FIRST_NAME => 'First Name',
static::COL_STATUS => 'Status',
];
}

/**
* @return \Orm\Zed\Customer\Persistence\SpyCustomerQuery
*/
protected function getDownloadQuery(): ModelCriteria
{
$customerQuery = $this->prepareQuery();
$customerQuery->orderBy(SpyCustomerTableMap::COL_ID_CUSTOMER, Criteria::DESC);

return $customerQuery;
}

/**
* @param \Orm\Zed\Customer\Persistence\SpyCustomer $entity
*
* @return array
*/
protected function formatCsvRow(ActiveRecordInterface $entity): array
{
$customerRow = $entity->toArray();

$customerRow[static::COL_CREATED_AT] = $this->utilDateTimeService->formatDateTime($entity->getCreatedAt());
$customerRow[static::COL_STATUS] = $entity->getRegistered() ? 'Verified' : 'Unverified';

return $customerRow;
}

/**
* @param \Spryker\Zed\Gui\Communication\Table\TableConfiguration $config
*
Expand Down
1 change: 1 addition & 0 deletions src/Spryker/Zed/Customer/Presentation/Index/index.twig
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

{% block action %}
{{ createActionButton('/customer/add', 'Add Customer' | trans) }}
{{ createActionButton('/customer/download', 'Download as CSV' | trans) }}
{% endblock %}

{% block content %}
Expand Down

0 comments on commit 71dd235

Please sign in to comment.