Skip to content

Commit

Permalink
Merge branch 'alexonline82-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Nayjest committed Apr 2, 2015
2 parents 7e6568e + 6cef3c8 commit 67a589e
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/Components/CsvExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ protected function renderCsv()
while ($row = $provider->getRow()) {
$output = [];
foreach ($this->grid->getConfig()->getColumns() as $column) {
if (!$column->isHidden() && !$column->isExportHidden()) {
if (!$column->isHidden()) {
$output[] = $this->escapeString( $column->getValue($row) );
}
}
Expand Down
56 changes: 53 additions & 3 deletions src/Components/ExcelExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Nayjest\Grids\Components\Base\RenderableRegistry;
use Nayjest\Grids\DataProvider;
use Nayjest\Grids\DataRow;
use Nayjest\Grids\FieldConfig;
use Nayjest\Grids\Grid;

/**
Expand Down Expand Up @@ -43,6 +44,10 @@ class ExcelExport extends RenderableComponent
*/
protected $sheetName;

protected $ignored_columns = [];

protected $is_hidden_columns_exported = false;

/**
* @param Grid $grid
* @return null|void
Expand Down Expand Up @@ -137,6 +142,16 @@ protected function resetPagination(DataProvider $provider)
$provider->setCurrentPage(1);
}

/**
* @param FieldConfig $column
* @return bool
*/
protected function isColumnExported(FieldConfig $column)
{
return !in_array($column->getName(), $this->getIgnoredColumns())
and ($this->isHiddenColumnsExported() or !$column->isHidden());
}

protected function getData()
{
// Build array
Expand All @@ -152,8 +167,7 @@ protected function getData()
while ($row = $provider->getRow()) {
$output = [];
foreach ($this->grid->getConfig()->getColumns() as $column) {
if (!$column->isHidden() && !$column->isExportHidden()) {

if ($this->isColumnExported($column)) {
$output[] = $this->escapeString($column->getValue($row));
}
}
Expand Down Expand Up @@ -187,10 +201,46 @@ protected function getHeaderRow()
{
$output = [];
foreach ($this->grid->getConfig()->getColumns() as $column) {
if (!$column->isHidden() && !$column->isExportHidden()) {
if (!$column->isExportHidden()) {
$output[] = $this->escapeString($column->getLabel());
}
}
return $output;
}

/**
* @return string[]
*/
public function getIgnoredColumns()
{
return $this->ignored_columns;
}

/**
* @param string[] $ignored_columns
* @return $this
*/
public function setIgnoredColumns(array $ignored_columns)
{
$this->ignored_columns = $ignored_columns;
return $this;
}

/**
* @return boolean
*/
public function isHiddenColumnsExported()
{
return $this->is_hidden_columns_exported;
}

/**
* @param bool $is_hidden_columns_exported
* @return $this
*/
public function setHiddenColumnsExported($is_hidden_columns_exported)
{
$this->is_hidden_columns_exported = $is_hidden_columns_exported;
return $this;
}
}
19 changes: 0 additions & 19 deletions src/FieldConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ class FieldConfig

protected $is_hidden = false;

protected $is_export_hidden = false;

/**
* @param string|null $name column unique name for internal usage
* @param string|null $label column label
Expand Down Expand Up @@ -86,23 +84,6 @@ public function show()
return $this;
}

public function isExportHidden()
{
return $this->is_export_hidden;
}

public function hideOnExport()
{
$this->is_export_hidden = true;
return $this;
}

public function showOnExport()
{
$this->is_export_hidden = false;
return $this;
}

public function getLabel()
{
return $this->label ? : ucwords(str_replace(array('-', '_', '.'), ' ', $this->name));
Expand Down

0 comments on commit 67a589e

Please sign in to comment.