Skip to content
This repository was archived by the owner on Mar 10, 2021. It is now read-only.
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
4 changes: 2 additions & 2 deletions Components/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,10 +329,10 @@ public function getFilterType()
/**
* @return Column
*/
public function setTextFilter()
public function setTextFilter($exact = FALSE)
{
$this->parent['gridForm'][$this->parent->name]['filter']->addText($this->name, $this->label.":");
$this->filterType = FilterCondition::TEXT;
$this->filterType = ($exact === FALSE) ? (FilterCondition::TEXT) : (FilterCondition::EQUAL);

return $this;
}
Expand Down
89 changes: 61 additions & 28 deletions FilterCondition.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* NiftyGrid - DataGrid for Nette
*
Expand All @@ -7,15 +8,18 @@
* @license New BSD Licence
* @link http://addons.nette.org/cs/niftygrid
*/

namespace NiftyGrid;

use Nette\Utils\Strings;

/**
* @author Jakub Holub
*/
class FilterCondition extends \Nette\Object
{
/* filter types */

const TEXT = "text";
const SELECT = "select";
const NUMERIC = "numeric";
Expand All @@ -32,10 +36,11 @@ class FilterCondition extends \Nette\Object
const EQUAL = "equal";
const HIGHER = "higher";
const HIGHEREQUAL = "higherEqual";
const EQUALHIGHER = "equalHigher";
const LOWER = "lower";
const LOWEREQUAL = "lowerEqual";
const EQUALLOWER = "equalLower";
const DIFFERENT = "different";

const DATE_EQUAL = "dateEqual";
const DATE_HIGHER = "dateHigher";
const DATE_HIGHEREQUAL = "dateHigherEqual";
Expand All @@ -50,7 +55,7 @@ class FilterCondition extends \Nette\Object
*/
public static function like($s)
{
$escape = array(".", "%","_", "'");
$escape = array(".", "%", "_", "'");
$replace = array("\.", "\%", "\_");
return str_replace($escape, $replace, $s);
}
Expand All @@ -62,12 +67,12 @@ public static function like($s)
*/
public static function getConditionsByType($type)
{
if($type == self::TEXT)
if ($type == self::TEXT)
return array(
self::ENDSWITH => "%",
self::STARTSWITH => "%",
);
elseif($type == self::DATE)
elseif ($type == self::DATE)
return array(
self::DATE_EQUAL => "=",
self::DATE_DIFFERENT => "<>",
Expand All @@ -76,8 +81,10 @@ public static function getConditionsByType($type)
self::DATE_LOWEREQUAL => "<=",
self::DATE_LOWER => "<",
);
elseif($type == self::NUMERIC)
elseif ($type == self::NUMERIC)
return array(
self::EQUALLOWER => "=<",
self::EQUALHIGHER => "=>",
self::EQUAL => "=",
self::DIFFERENT => "<>",
self::HIGHEREQUAL => ">=",
Expand All @@ -95,33 +102,37 @@ public static function getConditionsByType($type)
*/
public static function prepareFilter($value, $type)
{
/* select nebo boolean muze byt pouze equal */
if($type == self::SELECT || $type == self::BOOLEAN)
/* select, boolean a equal muze byt pouze equal */
if (($type == self::SELECT) || ($type == self::BOOLEAN) || ($type == self::EQUAL))
return array(
"condition" => self::EQUAL,
"value" => $value
);
elseif($type == self::TEXT){
foreach(self::getConditionsByType(self::TEXT) as $name => $condition){
if(Strings::endsWith($value, $condition) && !Strings::startsWith($value, $condition) && $name == self::STARTSWITH)
return array(
"condition" => $name,
"value" => Strings::substring($value, 0,"-".Strings::length($condition))
);
elseif(Strings::startsWith($value, $condition) && !Strings::endsWith($value, $condition) && $name == self::ENDSWITH)
return array(
"condition" => $name,
"value" => Strings::substring($value, Strings::length($condition))
);
elseif ($type == self::TEXT)
{
foreach (self::getConditionsByType(self::TEXT) as $name => $condition)
{
if (Strings::endsWith($value, $condition) && !Strings::startsWith($value, $condition) && $name == self::STARTSWITH)
return array(
"condition" => $name,
"value" => Strings::substring($value, 0, "-" . Strings::length($condition))
);
elseif (Strings::startsWith($value, $condition) && !Strings::endsWith($value, $condition) && $name == self::ENDSWITH)
return array(
"condition" => $name,
"value" => Strings::substring($value, Strings::length($condition))
);
}
return array(
"condition" => self::CONTAINS,
"value" => $value
);
}
elseif($type == self::DATE){
foreach(self::getConditionsByType(self::DATE) as $name => $condition){
if(Strings::startsWith($value, $condition))
elseif ($type == self::DATE)
{
foreach (self::getConditionsByType(self::DATE) as $name => $condition)
{
if (Strings::startsWith($value, $condition))
return array(
"condition" => $name,
"value" => Strings::substring($value, Strings::length($condition))
Expand All @@ -132,9 +143,11 @@ public static function prepareFilter($value, $type)
"value" => $value
);
}
elseif($type == self::NUMERIC){
foreach(self::getConditionsByType(self::NUMERIC) as $name => $condition){
if(Strings::startsWith($value, $condition))
elseif ($type == self::NUMERIC)
{
foreach (self::getConditionsByType(self::NUMERIC) as $name => $condition)
{
if (Strings::startsWith($value, $condition))
return array(
"condition" => $name,
"value" => (int) Strings::substring($value, Strings::length($condition))
Expand All @@ -158,7 +171,7 @@ public static function contains($value)
"type" => self::WHERE,
"datatype" => self::TEXT,
"cond" => " LIKE ?",
"value" => "%".self::like($value)."%",
"value" => "%" . self::like($value) . "%",
);
}

Expand Down Expand Up @@ -188,7 +201,7 @@ public static function startsWith($value)
"type" => self::WHERE,
"datatype" => self::TEXT,
"cond" => " LIKE ?",
"value" => self::like($value)."%",
"value" => self::like($value) . "%",
);
}

Expand All @@ -203,7 +216,7 @@ public static function endsWith($value)
"type" => self::WHERE,
"datatype" => self::TEXT,
"cond" => " LIKE ?",
"value" => "%".self::like($value),
"value" => "%" . self::like($value),
);
}

Expand Down Expand Up @@ -237,6 +250,16 @@ public static function higherEqual($value)
);
}

/**
* @static
* @param string $value
* @return array
*/
public static function equalHigher($value)
{
return self::higherEqual($value);
}

/**
* @static
* @param string $value
Expand Down Expand Up @@ -267,6 +290,16 @@ public static function lowerEqual($value)
);
}

/**
* @static
* @param string $value
* @return array
*/
public static function equalLower($value)
{
return self::lowerEqual($value);
}

/**
* @static
* @param string $value
Expand Down
24 changes: 12 additions & 12 deletions Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -482,11 +482,11 @@ protected function filterData()
$filters = array();
foreach($this->filter as $name => $value){
if(!$this->columnExists($name)){
throw new UnknownColumnException("Neexistující sloupec $name");
throw new UnknownColumnException("Unknown column $name");

}
if(!$this['columns-'.$name]->hasFilter()){
throw new UnknownFilterException("Neexistující filtr pro sloupec $name");
throw new UnknownFilterException("Unknown filter for column $name");
}

$type = $this['columns-'.$name]->getFilterType();
Expand All @@ -501,10 +501,10 @@ protected function filterData()
}
$filters[] = $filter;
}else{
throw new InvalidFilterException("Neplatný filtr");
throw new InvalidFilterException("Invalid filter");
}
}else{
throw new InvalidFilterException("Neplatný filtr");
throw new InvalidFilterException("Invalid filter");
}
}
return $this->dataSource->filterData($filters);
Expand All @@ -530,7 +530,7 @@ protected function orderData($order)
if(in_array($order[0], $this->getColumnNames()) && in_array($order[1], array("ASC", "DESC")) && $this['columns']->components[$order[0]]->isSortable()){
$this->dataSource->orderData($order[0], $order[1]);
}else{
throw new InvalidOrderException("Neplatné seřazení.");
throw new InvalidOrderException("Invalid order.");
}
}
catch(InvalidOrderException $e){
Expand Down Expand Up @@ -653,20 +653,20 @@ protected function createComponentGridForm()
$form->addContainer($this->name);

$form[$this->name]->addContainer("rowForm");
$form[$this->name]['rowForm']->addSubmit("send","Uložit");
$form[$this->name]['rowForm']->addSubmit("send","Save");
$form[$this->name]['rowForm']['send']->getControlPrototype()->addClass("grid-editable");

$form[$this->name]->addContainer("filter");
$form[$this->name]['filter']->addSubmit("send","Filtrovat");
$form[$this->name]['filter']->addSubmit("send","Filter");

$form[$this->name]->addContainer("action");
$form[$this->name]['action']->addSelect("action_name","Označené:");
$form[$this->name]['action']->addSubmit("send","Potvrdit")
$form[$this->name]['action']->addSelect("action_name","Mark:");
$form[$this->name]['action']->addSubmit("send","Confirm")
->getControlPrototype()
->addData("select", $form[$this->name]["action"]["action_name"]->getControl()->name);

$form[$this->name]->addContainer('perPage');
$form[$this->name]['perPage']->addSelect("perPage","Záznamů na stranu:", $this->perPageValues)
$form[$this->name]['perPage']->addSelect("perPage","Records per page:", $this->perPageValues)
->getControlPrototype()
->addClass("grid-changeperpage")
->addData("gridname", $this->getGridPath())
Expand Down Expand Up @@ -769,9 +769,9 @@ public function actionFormSubmitted($values, $gridName)
}
catch(NoRowSelectedException $e){
if($subGrid){
$this[$gridName]->flashMessage("Nebyl vybrán žádný záznam.","grid-error");
$this[$gridName]->flashMessage("No record selected","grid-error");
}else{
$this->flashMessage("Nebyl vybrán žádný záznam.","grid-error");
$this->flashMessage("No record selected","grid-error");
}
$this->redirect("this");
}
Expand Down
Loading