Skip to content
Open
Show file tree
Hide file tree
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
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