Skip to content
This repository has been archived by the owner on Oct 6, 2024. It is now read-only.

Fixed CSV export of birthday date #35

Merged
merged 1 commit into from
Oct 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 24 additions & 14 deletions app/Grid/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace App\Grid;

use Nette\Database\Context;
use Nette\Database\Table\ActiveRow;
use Nette\Utils\DateTime;
use Ublaboo\DataGrid\Column\ColumnText;
use Ublaboo\DataGrid\DataGrid;

Expand Down Expand Up @@ -82,27 +84,35 @@ function showFaculty($faculties)

function showExportCsv()
{
$column_name = new ColumnText($this, 'name', 'data_user.name', 'Name');
$column_surname = (new ColumnText($this, 'surname', 'data_user.surname', 'Surname'));
$column_birthday = (new ColumnText($this, 'birthday', 'data_user.birthday', 'Birthday'));
$column_country = (new ColumnText($this, 'country', 'data_user.country_id', 'Country'));
$column_email = (new ColumnText($this, 'email', 'user.user_id', 'Email'));
$column_registered = (new ColumnText($this, 'registered', 'data_user.registered', 'Registered'));

$name = new ColumnText($this, 'name', 'data_user.name', 'Name');
$surname = (new ColumnText($this, 'surname', 'data_user.surname', 'Surname'));
$birthday = (new ColumnText($this, 'birthday', 'data_user.birthday', 'Birthday'));
$country = (new ColumnText($this, 'country', 'data_user.country_id', 'Country'));
$email = (new ColumnText($this, 'email', 'user.user_id', 'Email'));
$registered = (new ColumnText($this, 'registered', 'data_user.registered', 'Registered'));

$birthday->setRenderer(function (ActiveRow $row) {
/** @var DateTime|NULL $value */
$value = $row->ref('data_user')->birthday;
if (!$value) return '';

$date = $value->format('Y-m-d');
return $date != '1970-01-01' ? $date : NULL;
});

$this->addExportCsvFiltered('Csv export', "fiesta.csv", "UTF-8", ";", true)
->setTitle('Csv export')
->setColumns([
$column_name,
$column_surname,
$column_birthday,
$column_email,
$column_country,
$column_registered
$name,
$surname,
$birthday,
$email,
$country,
$registered
]);
}

function showEditableStatus(callable $onSuccess)
public function showEditableStatus(callable $onSuccess)
{

$this->addColumnStatus('status', 'Status', "user.status:data_user")
Expand Down