Skip to content

Commit

Permalink
Support for mutiple export (Closes o5#262)
Browse files Browse the repository at this point in the history
Fixed code style

Fixed code style

getExport accepts component name

Default parameter for name in getExport

setExport deprecated

setExport deprecated, fixed tests
  • Loading branch information
AntikCz committed Feb 26, 2016
1 parent 7f69b26 commit 3ce6365
Show file tree
Hide file tree
Showing 16 changed files with 320 additions and 207 deletions.
56 changes: 51 additions & 5 deletions src/Components/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Grido\Components;

use Grido\Components\Exports\BaseExport;
use Grido\Components\Exports\CsvExport;
use Grido\Grid;
use Grido\Helpers;
use Grido\Components\Actions\Action;
Expand Down Expand Up @@ -94,12 +96,37 @@ public function getOperation($need = TRUE)

/**
* Returns export component.
* @param string $name
* @param bool $need
* @return Export
* @return CsvExport
*/
public function getExport($name = NULL, $need = TRUE)
{
if (is_bool($name) || $name === NULL) { // deprecated
trigger_error('This usage of ' . __METHOD__ . '() is deprecated, please write name of export to first parameter.',
E_USER_DEPRECATED);
$export = $this->getComponent(BaseExport::ID, $name);
if ($export) {
$export = $export->getComponent(CsvExport::CSV_ID, is_bool($name) ? $name : TRUE);
}
return $export;
}
return $this->hasExport()
? $this->getComponent(BaseExport::ID)->getComponent(Helpers::formatColumnName($name), $need)
: NULL;
}

/**
* @param bool $need
* @return BaseExport[]
*/
public function getExport($need = TRUE)
public function getExports($need = TRUE)
{
return $this->getComponent(Export::ID, $need);
$export = $this->getComponent(BaseExport::ID, $need);
if ($export) {
$export = $export->getComponents();
}
return $export;
}

/**********************************************************************************************/
Expand Down Expand Up @@ -185,7 +212,7 @@ public function hasExport($useCache = TRUE)
$hasExport = $this->hasExport;

if ($hasExport === NULL || $useCache === FALSE) {
$hasExport = (bool) $this->getComponent(Export::ID, FALSE);
$hasExport = (bool) $this->getExports(FALSE);
$this->hasExport = $useCache ? $hasExport : NULL;
}

Expand Down Expand Up @@ -361,10 +388,29 @@ public function setOperation(array $operations, $onSubmit)
/**
* @param string $label of exporting file
* @return Export
*
* @deprecated
*/
public function setExport($label = NULL)
{
return new Export($this, $label);
trigger_error(__METHOD__ . '() is deprecated; use addExport instead.', E_USER_DEPRECATED);
return $this->addExport(new CsvExport($label), CsvExport::CSV_ID);
}

/**
* @param BaseExport $export
* @param string $name Component name
* @return BaseExport
*/
public function addExport(BaseExport $export, $name)
{
$container = $this->getComponent(BaseExport::ID, FALSE);
if (!$container) {
$container = new \Nette\ComponentModel\Container();
$this->addComponent($container, BaseExport::ID);
}
$container->addComponent($export, $name);
return $export;
}

/**
Expand Down
180 changes: 0 additions & 180 deletions src/Components/Export.php

This file was deleted.

Loading

0 comments on commit 3ce6365

Please sign in to comment.