Permalink
Browse files

small fixes

  • Loading branch information...
1 parent 4cc1d81 commit 13079cd2df41324750fc61514888b625f78aff60 Sorien committed Jul 4, 2012
@@ -13,6 +13,8 @@
use Symfony\Component\Security\Core\SecurityContextInterface;
use Sorien\DataGridBundle\Grid\Helper\FilterStorageBag;
+use Sorien\DataGridBundle\Grid\Row;
+use Sorien\DataGridBundle\Grid\Filter;
abstract class Column
{
@@ -66,7 +68,7 @@
* Default Column constructor
*
* @param array $params
- * @return \Sorien\DataGridBundle\Grid\Column\Column
+ * @return Column
*/
public function __construct($params = null)
{
@@ -114,7 +116,7 @@ public function renderFilter($gridHash)
* Draw cell
*
* @param string $value
- * @param \Sorien\DataGridBundle\Grid\Row $row
+ * @param Row $row
* @param $router
* @return string
*/
@@ -134,7 +136,7 @@ public function renderCell($value, $row, $router)
* Set column callback
*
* @param $callback
- * @return \Sorien\DataGridBundle\Grid\Column\Column
+ * @return Column
*/
public function setCallback($callback)
{
@@ -147,7 +149,7 @@ public function setCallback($callback)
* Set column identifier
*
* @param $id
- * @return \Sorien\DataGridBundle\Grid\Column\Column
+ * @return Column
*/
public function setId($id)
{
@@ -170,7 +172,7 @@ public function getId()
* Set column title
*
* @param string $title
- * @return \Sorien\DataGridBundle\Grid\Column\Column
+ * @return Column
*/
public function setTitle($title)
{
@@ -278,7 +280,7 @@ public function isSortable()
* Set column order
*
* @param string $order asc|desc
- * @return \Sorien\DataGridBundle\Grid\Column\Column
+ * @return Column
*/
public function setOrder($order)
{
@@ -316,7 +318,7 @@ public function getFiltersConnection()
* Get column data filters
* todo: maybe change to own class not array
*
- * @return \Sorien\DataGridBundle\Grid\Filter[]
+ * @return Filter[]
*/
public function getFilters()
{
@@ -327,7 +329,7 @@ public function getFilters()
* Set column width
*
* @param int $size in pixels
- * @return \Sorien\DataGridBundle\Grid\Column\Column
+ * @return Column
*/
public function setSize($size)
{
@@ -366,7 +368,7 @@ public function getOrderUrl()
* Set filter data from Storage or Request
*
* @param FilterStorageBag $data
- * @return \Sorien\DataGridBundle\Grid\Column\Column
+ * @return Column
*/
public function setData(FilterStorageBag $data)
{
@@ -388,7 +390,7 @@ public function getData()
* Set column visibility for source class
*
* @param $value
- * @return \Sorien\DataGridBundle\Grid\Column\Column
+ * @return Column
*/
public function setIsVisibleForSource($value)
{
@@ -436,6 +438,7 @@ public function setPrimary($primary)
* Set column align
*
* @param string $align left/right/center
+ * @throws \InvalidArgumentException
*/
public function setAlign($align)
{
@@ -12,8 +12,9 @@
namespace Sorien\DataGridBundle\Grid\Column;
use Sorien\DataGridBundle\Grid\Filter;
+use Sorien\DataGridBundle\Grid\Helper\FilterStorageBag;
-class DateColumn extends TextColumn
+class DateColumn extends Column
{
private $format;
private $pattern;
@@ -48,6 +49,21 @@ public function renderCell($value, $row, $router)
return '';
}
}
+
+ public function setData(FilterStorageBag $data)
+ {
+ if ($data->get('value', '') != '')
+ {
+ $this->data->assign($data);
+ }
+
+ return $this;
+ }
+
+ public function isFiltered()
+ {
+ return $this->data->has('value');
+ }
public function getType()
{
@@ -14,7 +14,7 @@
use Sorien\DataGridBundle\Grid\Filter;
use Sorien\DataGridBundle\Grid\Helper\FilterStorageBag;
-class RangeColumn extends Column
+class RangeColumn extends TextColumn
{
private $inputType;
@@ -25,35 +25,34 @@ public function __initialize(array $params)
/**
* defined like ":foo, :faa - :foo"
*/
- $this->pattern = $this->getParam('pattern', '');
+ $this->pattern = $this->getParam('pattern', ':'.$this->getId());
$this->columns = $this->getParam('columns', array());
}
public function getFilters()
{
- $result = array();
+ $result = array(new Filter(self::OPERATOR_REGEXP, '/.*'.$this->data->get('value', '').'.*/i'));
+
if (!empty($this->columns))
{
foreach ($this->columns as $column)
{
$result[] = new Filter(self::OPERATOR_REGEXP, '/.*'.$this->data->get('value', '').'.*/i', $column);
}
}
- else
- {
- $result[] = new Filter(self::OPERATOR_REGEXP, '/.*'.$this->data->get('value', '').'.*/i');
- }
return $result;
}
public function renderCell($value, $row, $router)
{
+ $value = str_replace(":".$this->getId(), $value, $this->pattern);
+
if (!empty($this->columns))
{
foreach ($this->columns as $column)
{
- $value = str_replace(":"+$column, $row->getField($column), $this->pattern);
+ $value = str_replace(":".$column, $row->getField($column), $value);
}
}
View
@@ -34,9 +34,14 @@ public function __construct(SecurityContextInterface $securityContext)
$this->securityContext = $securityContext;
}
- public function getIterator($showOnlySourceColumns = false)
+ public function getIterator()
{
- return new ColumnsIterator(new \ArrayIterator($this->columns), $showOnlySourceColumns);
+ return new ColumnsIterator(new \ArrayIterator($this->columns), false);
+ }
+
+ public function getSourceColumns()
+ {
+ return new ColumnsIterator(new \ArrayIterator($this->columns), true);
}
/**
View
@@ -392,7 +392,7 @@ public function executeMassActions()
*/
public function prepare()
{
- $this->rows = $this->source->execute($this->columns->getIterator(true), $this->page, $this->limit);
+ $this->rows = $this->source->execute($this->columns, $this->page, $this->limit);
if(!$this->rows instanceof Rows)
{
@@ -74,7 +74,7 @@ public function __construct($entityName)
{
$this->entityName = $entityName;
$this->joins = array();
- $this->hasDqlFunction = true;
+ $this->hasDqlFunction = false;
}
public function initialise($container)
@@ -134,7 +134,7 @@ private function getFieldName($column, $inSelect = true)
{
if ($function != '')
{
- $this->hasDqlFunction = True;
+ $this->hasDqlFunction = true;
$name = $function.'('.$name.')';
}
@@ -185,7 +185,8 @@ private function normalizeValue($operator, $value)
}
/**
- * @param Column[] $columns
+ * @param Column[]|Columns $columns
+ * @return \Doctrine\ORM\QueryBuilder
*/
private function buildQuery($columns)
{
@@ -196,7 +197,7 @@ private function buildQuery($columns)
$where = $this->query->expr()->andx();
- foreach ($columns as $column)
+ foreach ($columns->getSourceColumns() as $column)
{
$this->query->addSelect($this->getFieldName($column));
@@ -214,7 +215,7 @@ private function buildQuery($columns)
$operator = $this->normalizeOperator($filter->getOperator());
$where->add($this->query->expr()->$operator(
- $this->getFieldName($filter->hasId() ? $filter->getId() : $column, false),
+ $this->getFieldName($filter->hasId() ? $columns->getColumnById($filter->getId()) : $column, false),
$this->normalizeValue($filter->getOperator(), $filter->getValue())
));
}
@@ -228,7 +229,7 @@ private function buildQuery($columns)
$operator = $this->normalizeOperator($filter->getOperator());
$sub->add($this->query->expr()->$operator(
- $this->getFieldName($filter->hasId() ? $filter->getId() : $column, false),
+ $this->getFieldName($filter->hasId() ? $columns->getColumnById($filter->getId()) : $column, false),
$this->normalizeValue($filter->getOperator(), $filter->getValue())
));
}
@@ -264,7 +265,7 @@ private function buildQuery($columns)
}
/**
- * @param Column[] $columns
+ * @param Column[]|Columns $columns
* @param int $page Page Number
* @param int $limit Rows Per Page
* @return Rows
@@ -311,7 +312,7 @@ public function execute($columns, $page = 0, $limit = 0)
}
/**
- * @param Columns $columns
+ * @param Column[]|Columns $columns
* @return array
*/
public function getPrimaryKeys($columns)
@@ -322,9 +323,8 @@ public function getPrimaryKeys($columns)
return $query->getQuery()->getResult();
}
-
/**
- * @param Columns $columns
+ * @param Column[]|Columns $columns
* @return int
*/
public function getTotalCount($columns)
@@ -69,7 +69,7 @@ public function setCallback($type, $callback)
* Find data for current page
*
* @abstract
- * @param Column[] $columns
+ * @param Column[]|Columns $columns
* @param int $page
* @param int $limit
*
@@ -80,19 +80,18 @@ public function setCallback($type, $callback)
/**
* Get Total count of data items
*
- * @param Columns $columns
+ * @param Column[]|Columns $columns
*
* @return int
*/
abstract function getTotalCount($columns);
/**
- * @param Columns $columns
+ * @param Column[]|Columns $columns
* @return array
*/
abstract function getPrimaryKeys($columns);
-
/**
* Set container
*

0 comments on commit 13079cd

Please sign in to comment.