-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
165 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
* @author Matouš Němec <[email protected]> | ||
* | ||
* @method null onSort($data, $itemId) | ||
* @method null onFilter(Extensions\Filter\IFilter $filter) | ||
* @method null onFilter(Extensions\Filter\IFilter|Extensions\SimpleFilter\ISimpleFilter $filter) | ||
*/ | ||
abstract class ExtendedGrid extends BaseGrid | ||
{ | ||
|
@@ -97,9 +97,24 @@ public function enableExport($cacheDir, $fileName = null) | |
*/ | ||
public function enableFilter($inline = true) | ||
{ | ||
if ($this->getExtension('ISimpleFilter', false)) { | ||
throw new Mesour\InvalidStateException('Simple filter is already used.'); | ||
} | ||
return $this->getExtension('IFilter')->setInline($inline); | ||
} | ||
|
||
/** | ||
* @param array $allowedColumns | ||
* @return Extensions\SimpleFilter\ISimpleFilter | ||
*/ | ||
public function enableSimpleFilter(array $allowedColumns = []) | ||
{ | ||
if ($this->getExtension('IFilter', false)) { | ||
throw new Mesour\InvalidStateException('Normal filter is already used.'); | ||
} | ||
return $this->getExtension('ISimpleFilter')->setAllowedColumns($allowedColumns); | ||
} | ||
|
||
/** | ||
* @return Extensions\Selection\ISelection | ||
* @throws Mesour\InvalidArgumentException | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/Mesour/DataGrid/Extensions/SimpleFilter/ISimpleFilter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
/** | ||
* This file is part of the Mesour DataGrid (http://grid.mesour.com) | ||
* | ||
* Copyright (c) 2015-2016 Matouš Němec (http://mesour.com) | ||
* | ||
* For full licence and copyright please view the file licence.md in root of this project | ||
*/ | ||
|
||
namespace Mesour\DataGrid\Extensions\SimpleFilter; | ||
|
||
use Mesour; | ||
|
||
/** | ||
* @author Matouš Němec <[email protected]> | ||
*/ | ||
interface ISimpleFilter extends Mesour\Filter\ISimpleFilter, Mesour\DataGrid\Extensions\IExtension | ||
{ | ||
|
||
public function beforeCreate(); | ||
|
||
} |
106 changes: 106 additions & 0 deletions
106
src/Mesour/DataGrid/Extensions/SimpleFilter/SimpleFilterExtension.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?php | ||
/** | ||
* This file is part of the Mesour DataGrid (http://grid.mesour.com) | ||
* | ||
* Copyright (c) 2015-2016 Matouš Němec (http://mesour.com) | ||
* | ||
* For full licence and copyright please view the file licence.md in root of this project | ||
*/ | ||
|
||
namespace Mesour\DataGrid\Extensions\SimpleFilter; | ||
|
||
use Mesour; | ||
|
||
/** | ||
* @author Matouš Němec <[email protected]> | ||
*/ | ||
class SimpleFilterExtension extends Mesour\UI\SimpleFilter implements ISimpleFilter | ||
{ | ||
|
||
use Mesour\Components\Security\Authorised; | ||
|
||
private $disabled = false; | ||
|
||
/** @var Mesour\Components\Utils\Html|string */ | ||
private $createdFilter; | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function isDisabled() | ||
{ | ||
return $this->disabled; | ||
} | ||
|
||
public function setDisabled($disabled = true) | ||
{ | ||
$this->disabled = (bool) $disabled; | ||
return $this; | ||
} | ||
|
||
public function gridCreate($data = []) | ||
{ | ||
$this->onFilter[] = function (ISimpleFilter $currentFilter) { | ||
$this->updateFilter($currentFilter); | ||
$this->getGrid()->onFilter($currentFilter); | ||
}; | ||
$this->setSource($this->getGrid()->getSource()); | ||
|
||
$this->setOption('data', $data); | ||
$this->createdFilter = $this->create(); | ||
$this->updateFilter($this); | ||
} | ||
|
||
/** | ||
* @return Mesour\DataGrid\ExtendedGrid|Mesour\Components\Control\IControl | ||
*/ | ||
public function getGrid() | ||
{ | ||
return $this->getParent(); | ||
} | ||
|
||
public function createInstance(Mesour\DataGrid\Extensions\IExtension $extension, $name = null) | ||
{ | ||
|
||
} | ||
|
||
public function afterGetCount($count) | ||
{ | ||
|
||
} | ||
|
||
public function beforeFetchData($data = []) | ||
{ | ||
|
||
} | ||
|
||
public function afterFetchData($currentData, $data = [], $rawData = []) | ||
{ | ||
|
||
} | ||
|
||
public function attachToRenderer(Mesour\DataGrid\Renderer\IGridRenderer $renderer, $data = [], $rawData = []) | ||
{ | ||
$filterPrototype = $this->getGrid()->getFilterPrototype(); | ||
$filterPrototype->add($this->createdFilter); | ||
$renderer->setComponent('filter', $filterPrototype); | ||
} | ||
|
||
public function reset($hard = false) | ||
{ | ||
|
||
} | ||
|
||
/** | ||
* @param ISimpleFilter $filter | ||
* @throws | ||
*/ | ||
private function updateFilter(ISimpleFilter $filter) | ||
{ | ||
if (!$this->isDisabled()) { | ||
$source = $this->getGrid()->getSource(); | ||
$source->applySimple($filter->getQuery(), $filter->getAllowedColumns()); | ||
} | ||
} | ||
|
||
} |