Skip to content
Browse files

few updates which i found during hdd cleaning

  • Loading branch information...
1 parent 5f5129d commit 6b3f2c38fe6f37d96dcf66053caf4f7c2d103439 @Sorien committed Jun 19, 2012
View
52 DependencyInjection/SorienDataGridExtension.php
@@ -1,26 +1,26 @@
-<?php
-
-/*
- * This file is part of the DataGridBundle.
- *
- * (c) Stanislav Turza <sorien@mail.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Sorien\DataGridBundle\DependencyInjection;
-
-use Symfony\Component\HttpKernel\DependencyInjection\Extension;
-use Symfony\Component\DependencyInjection\ContainerBuilder;
-use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
-use Symfony\Component\Config\FileLocator;
-
-class SorienDataGridExtension extends Extension
-{
- public function load(array $config, ContainerBuilder $container)
- {
- $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
- $loader->load('services.xml');
- }
-}
+<?php
+
+/*
+ * This file is part of the DataGridBundle.
+ *
+ * (c) Stanislav Turza <sorien@mail.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Sorien\DataGridBundle\DependencyInjection;
+
+use Symfony\Component\HttpKernel\DependencyInjection\Extension;
+use Symfony\Component\DependencyInjection\ContainerBuilder;
+use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
+use Symfony\Component\Config\FileLocator;
+
+class SorienDataGridExtension extends Extension
+{
+ public function load(array $config, ContainerBuilder $container)
+ {
+ $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
+ $loader->load('services.xml');
+ }
+}
View
52 Grid/Action/DeleteMassAction.php
@@ -1,26 +1,26 @@
-<?php
-
-/*
- * This file is part of the DataGridBundle.
- *
- * (c) Stanislav Turza <sorien@mail.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Sorien\DataGridBundle\Grid\Action;
-
-class DeleteMassAction extends MassAction
-{
- /**
- * Default DeleteMassAction constructor
- *
- * @param boolean $confirm Show confirm message if true
- * @return \Sorien\DataGridBundle\Grid\Action\MassAction
- */
- public function __construct($confirm = false)
- {
- parent::__construct('Delete', 'static::deleteAction', $confirm);
- }
-}
+<?php
+
+/*
+ * This file is part of the DataGridBundle.
+ *
+ * (c) Stanislav Turza <sorien@mail.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Sorien\DataGridBundle\Grid\Action;
+
+class DeleteMassAction extends MassAction
+{
+ /**
+ * Default DeleteMassAction constructor
+ *
+ * @param boolean $confirm Show confirm message if true
+ * @return \Sorien\DataGridBundle\Grid\Action\MassAction
+ */
+ public function __construct($confirm = false)
+ {
+ parent::__construct('Delete', 'static::deleteAction', $confirm);
+ }
+}
View
224 Grid/Action/MassAction.php
@@ -1,103 +1,121 @@
-<?php
-
-/*
- * This file is part of the DataGridBundle.
- *
- * (c) Stanislav Turza <sorien@mail.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Sorien\DataGridBundle\Grid\Action;
-
-class MassAction implements MassActionInterface
-{
- private $title;
- private $callback;
- private $confirm;
-
- /**
- * Default MassAction constructor
- *
- * @param string $title Title of the mass action
- * @param string $callback Callback of the mass action
- * @param boolean $confirm Show confirm message if true
- * @return \Sorien\DataGridBundle\Grid\Action\MassAction
- */
- public function __construct($title, $callback = null, $confirm = false)
- {
- $this->title = $title;
- $this->callback = $callback;
- $this->confirm = $confirm;
- }
-
- /**
- * Set action title
- *
- * @param $title
- * @return \Sorien\DataGridBundle\Grid\Action\MassAction
- */
- public function setTitle($title)
- {
- $this->title = $title;
-
- return $this;
- }
-
- /**
- * get action title
- *
- * @return string
- */
- public function getTitle()
- {
- return $this->title;
- }
-
- /**
- * Set action callback
- *
- * @param $callback
- * @return \Sorien\DataGridBundle\Grid\Action\MassAction
- */
- public function setCallback($callback)
- {
- $this->callback = $callback;
-
- return $this;
- }
-
- /**
- * get action callback
- *
- * @return string
- */
- public function getCallback()
- {
- return $this->callback;
- }
-
- /**
- * Set action confirm
- *
- * @param $confirm
- * @return \Sorien\DataGridBundle\Grid\Action\MassAction
- */
- public function setConfirm($confirm)
- {
- $this->confirm = $confirm;
-
- return $this;
- }
-
- /**
- * get action confirm
- *
- * @return boolean
- */
- public function getConfirm()
- {
- return $this->confirm;
- }
-}
+<?php
+
+/*
+ * This file is part of the DataGridBundle.
+ *
+ * (c) Stanislav Turza <sorien@mail.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Sorien\DataGridBundle\Grid\Action;
+
+class MassAction implements MassActionInterface
+{
+ private $title;
+ private $callback;
+ private $confirm;
+ private $arguments;
+
+ /**
+ * Default MassAction constructor
+ *
+ * @param string $title Title of the mass action
+ * @param string $callback Callback of the mass action
+ * @param boolean $confirm Show confirm message if true
+ * @return MassAction
+ */
+ public function __construct($title, $callback = null, $confirm = '', $arguments = array())
+ {
+ $this->setTitle($title);
+ $this->setCallback($callback);
+ $this->setConfirm($confirm);
+ $this->setArguments($arguments);
+ }
+
+ /**
+ * Set action title
+ *
+ * @param $title
+ * @return MassAction
+ */
+ public function setTitle($title)
+ {
+ $this->title = $title;
+
+ return $this;
+ }
+
+ /**
+ * get action title
+ *
+ * @return string
+ */
+ public function getTitle()
+ {
+ return $this->title;
+ }
+
+ /**
+ * Set action callback
+ *
+ * @param $callback
+ * @return MassAction
+ */
+ public function setCallback($callback)
+ {
+ $this->callback = $callback;
+
+ return $this;
+ }
+
+ /**
+ * get action callback
+ *
+ * @return string
+ */
+ public function getCallback()
+ {
+ return $this->callback;
+ }
+
+ /**
+ * Set action confirm
+ *
+ * @param $confirm
+ * @return MassAction
+ */
+ public function setConfirm($confirm)
+ {
+ $this->confirm = str_replace('{title}', $this->getTitle(), $confirm);
+
+ return $this;
+ }
+
+ /**
+ * get action confirm
+ *
+ * @return string
+ */
+ public function getConfirm()
+ {
+ return $this->confirm;
+ }
+
+ /**
+ * @param $arguments
+ */
+ public function setArguments($arguments)
+ {
+ $this->arguments = $arguments;
+ }
+
+ /**
+ * @return array
+ */
+ public function getArguments()
+ {
+ return $this->arguments;
+ }
+}
View
77 Grid/Action/MassActionInterface.php
@@ -1,36 +1,41 @@
-<?php
-
-/*
- * This file is part of the DataGridBundle.
- *
- * (c) Stanislav Turza <sorien@mail.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Sorien\DataGridBundle\Grid\Action;
-
-interface MassActionInterface
-{
- /**
- * get action title
- *
- * @return string
- */
- public function getTitle();
-
- /**
- * get action callback
- *
- * @return string
- */
- public function getCallback();
-
- /**
- * get action confirm
- *
- * @return boolean
- */
- public function getConfirm();
-}
+<?php
+
+/*
+ * This file is part of the DataGridBundle.
+ *
+ * (c) Stanislav Turza <sorien@mail.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Sorien\DataGridBundle\Grid\Action;
+
+interface MassActionInterface
+{
+ /**
+ * get action title
+ *
+ * @return string
+ */
+ public function getTitle();
+
+ /**
+ * get action callback
+ *
+ * @return string
+ */
+ public function getCallback();
+
+ /**
+ * get action confirm
+ *
+ * @return boolean
+ */
+ public function getConfirm();
+
+ /**
+ * @return array
+ */
+ public function getArguments();
+}
View
378 Grid/Action/RowAction.php
@@ -1,189 +1,189 @@
-<?php
-
-/*
- * This file is part of the DataGridBundle.
- *
- * (c) Stanislav Turza <sorien@mail.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Sorien\DataGridBundle\Grid\Action;
-
-class RowAction implements RowActionInterface
-{
- private $title;
- private $route;
- private $confirm;
- private $confirmMessage;
- private $target;
- private $column = '__actions';
- private $routeParameters = array();
-
- /**
- * Default MassAction constructor
- *
- * @param string $title Title of the mass action
- * @param string $route Route to the row action
- * @param boolean $confirm Show confirm message if true
- * @param string $target Set the target of this action (_slef,_blank,_parent,_top)
- * @return \Sorien\DataGridBundle\Grid\Action\MassAction
- */
- public function __construct($title, $route = null, $confirm = false, $target = '_self')
- {
- $this->title = $title;
- $this->route = $route;
- $this->confirm = $confirm;
- $this->confirmMessage = 'Do you want to '.strtolower($title).' this row?';
- $this->target = $target;
- }
-
- /**
- * Set action title
- *
- * @param $title
- * @return \Sorien\DataGridBundle\Grid\Action\MassAction
- */
- public function setTitle($title)
- {
- $this->title = $title;
-
- return $this;
- }
-
- /**
- * get action title
- *
- * @return string
- */
- public function getTitle()
- {
- return $this->title;
- }
-
- /**
- * Set action route
- *
- * @param $route
- * @return \Sorien\DataGridBundle\Grid\Action\RowAction
- */
- public function setRoute($route)
- {
- $this->route = $route;
-
- return $this;
- }
-
- /**
- * get action route
- *
- * @return string
- */
- public function getRoute()
- {
- return $this->route;
- }
-
- /**
- * Set action confirm
- *
- * @param $confirm
- * @return \Sorien\DataGridBundle\Grid\Action\MassAction
- */
- public function setConfirm($confirm)
- {
- $this->confirm = $confirm;
-
- return $this;
- }
-
- /**
- * get action confirm
- *
- * @return boolean
- */
- public function getConfirm()
- {
- return $this->confirm;
- }
-
- /**
- * Set action confirmMessage
- *
- * @param $confirmMessage
- * @return \Sorien\DataGridBundle\Grid\Action\MassAction
- */
- public function setConfirmMessage($confirmMessage)
- {
- $this->confirmMessage = $confirmMessage;
-
- return $this;
- }
-
- /**
- * get action confirmMessage
- *
- * @return boolean
- */
- public function getConfirmMessage()
- {
- return $this->confirmMessage;
- }
-
- /**
- * Set action target
- *
- * @param $target
- * @return \Sorien\DataGridBundle\Grid\Action\MassAction
- */
- public function setTarget($target)
- {
- $this->target = $target;
-
- return $this;
- }
-
- /**
- * get action target
- *
- * @return boolean
- */
- public function getTarget()
- {
- return $this->target;
- }
-
- /**
- * Set action column
- *
- * @param $column
- * @return \Sorien\DataGridBundle\Grid\Action\MassAction
- */
- public function setColumn($column)
- {
- $this->column = $column;
-
- return $this;
- }
-
- /**
- * get action column
- *
- * @return boolean
- */
- public function getColumn()
- {
- return $this->column;
- }
-
- public function setRouteParameters(array $routeParameters)
- {
- $this->routeParameters = $routeParameters;
- }
-
- public function getRouteParameters()
- {
- return $this->routeParameters;
- }
-}
+<?php
+
+/*
+ * This file is part of the DataGridBundle.
+ *
+ * (c) Stanislav Turza <sorien@mail.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Sorien\DataGridBundle\Grid\Action;
+
+class RowAction implements RowActionInterface
+{
+ private $title;
+ private $route;
+ private $confirm;
+ private $confirmMessage;
+ private $target;
+ private $column = '__actions';
+ private $routeParameters = array();
+
+ /**
+ * Default MassAction constructor
+ *
+ * @param string $title Title of the mass action
+ * @param string $route Route to the row action
+ * @param boolean $confirm Show confirm message if true
+ * @param string $target Set the target of this action (_slef,_blank,_parent,_top)
+ * @return \Sorien\DataGridBundle\Grid\Action\MassAction
+ */
+ public function __construct($title, $route = null, $confirm = false, $target = '_self')
+ {
+ $this->title = $title;
+ $this->route = $route;
+ $this->confirm = $confirm;
+ $this->confirmMessage = 'Do you want to '.strtolower($title).' this row?';
+ $this->target = $target;
+ }
+
+ /**
+ * Set action title
+ *
+ * @param $title
+ * @return \Sorien\DataGridBundle\Grid\Action\MassAction
+ */
+ public function setTitle($title)
+ {
+ $this->title = $title;
+
+ return $this;
+ }
+
+ /**
+ * get action title
+ *
+ * @return string
+ */
+ public function getTitle()
+ {
+ return $this->title;
+ }
+
+ /**
+ * Set action route
+ *
+ * @param $route
+ * @return \Sorien\DataGridBundle\Grid\Action\RowAction
+ */
+ public function setRoute($route)
+ {
+ $this->route = $route;
+
+ return $this;
+ }
+
+ /**
+ * get action route
+ *
+ * @return string
+ */
+ public function getRoute()
+ {
+ return $this->route;
+ }
+
+ /**
+ * Set action confirm
+ *
+ * @param $confirm
+ * @return \Sorien\DataGridBundle\Grid\Action\MassAction
+ */
+ public function setConfirm($confirm)
+ {
+ $this->confirm = $confirm;
+
+ return $this;
+ }
+
+ /**
+ * get action confirm
+ *
+ * @return boolean
+ */
+ public function getConfirm()
+ {
+ return $this->confirm;
+ }
+
+ /**
+ * Set action confirmMessage
+ *
+ * @param $confirmMessage
+ * @return \Sorien\DataGridBundle\Grid\Action\MassAction
+ */
+ public function setConfirmMessage($confirmMessage)
+ {
+ $this->confirmMessage = $confirmMessage;
+
+ return $this;
+ }
+
+ /**
+ * get action confirmMessage
+ *
+ * @return boolean
+ */
+ public function getConfirmMessage()
+ {
+ return $this->confirmMessage;
+ }
+
+ /**
+ * Set action target
+ *
+ * @param $target
+ * @return \Sorien\DataGridBundle\Grid\Action\MassAction
+ */
+ public function setTarget($target)
+ {
+ $this->target = $target;
+
+ return $this;
+ }
+
+ /**
+ * get action target
+ *
+ * @return boolean
+ */
+ public function getTarget()
+ {
+ return $this->target;
+ }
+
+ /**
+ * Set action column
+ *
+ * @param $column
+ * @return \Sorien\DataGridBundle\Grid\Action\MassAction
+ */
+ public function setColumn($column)
+ {
+ $this->column = $column;
+
+ return $this;
+ }
+
+ /**
+ * get action column
+ *
+ * @return boolean
+ */
+ public function getColumn()
+ {
+ return $this->column;
+ }
+
+ public function setRouteParameters(array $routeParameters)
+ {
+ $this->routeParameters = $routeParameters;
+ }
+
+ public function getRouteParameters()
+ {
+ return $this->routeParameters;
+ }
+}
View
114 Grid/Action/RowActionInterface.php
@@ -1,57 +1,57 @@
-<?php
-
-/*
- * This file is part of the DataGridBundle.
- *
- * (c) Stanislav Turza <sorien@mail.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Sorien\DataGridBundle\Grid\Action;
-
-interface RowActionInterface
-{
- /**
- * get action title
- *
- * @return string
- */
- public function getTitle();
-
- /**
- * get action route
- *
- * @return string
- */
- public function getRoute();
-
- /**
- * get action confirm
- *
- * @return boolean
- */
- public function getConfirm();
-
- /**
- * get action confirmMessage
- *
- * @return boolean
- */
- public function getConfirmMessage();
-
- /**
- * get action target
- *
- * @return boolean
- */
- public function getTarget();
-
- /**
- * get action column
- *
- * @return boolean
- */
- public function getColumn();
-}
+<?php
+
+/*
+ * This file is part of the DataGridBundle.
+ *
+ * (c) Stanislav Turza <sorien@mail.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Sorien\DataGridBundle\Grid\Action;
+
+interface RowActionInterface
+{
+ /**
+ * get action title
+ *
+ * @return string
+ */
+ public function getTitle();
+
+ /**
+ * get action route
+ *
+ * @return string
+ */
+ public function getRoute();
+
+ /**
+ * get action confirm
+ *
+ * @return boolean
+ */
+ public function getConfirm();
+
+ /**
+ * get action confirmMessage
+ *
+ * @return boolean
+ */
+ public function getConfirmMessage();
+
+ /**
+ * get action target
+ *
+ * @return boolean
+ */
+ public function getTarget();
+
+ /**
+ * get action column
+ *
+ * @return boolean
+ */
+ public function getColumn();
+}
View
98 Grid/Column/ActionsColumn.php
@@ -1,49 +1,49 @@
-<?php
-
-/*
- * This file is part of the DataGridBundle.
- *
- * (c) Stanislav Turza <sorien@mail.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Sorien\DataGridBundle\Grid\Column;
-
-use Sorien\DataGridBundle\Grid\Action\RowAction;
-
-class ActionsColumn extends Column
-{
- private $rowActions;
-
- public function __construct($column, $title, array $rowActions = array())
- {
- $this->rowActions = $rowActions;
- parent::__construct(array('id' => $column, 'title' => $title, 'sortable' => false, 'source' => false));
- }
-
- public function getRouteParameters($row, $action)
- {
- $routeParameters = array_merge(
- array($row->getPrimaryField() => $row->getPrimaryFieldValue()),
- $action->getRouteParameters()
- );
-
- return $routeParameters;
- }
-
- public function getRowActions()
- {
- return $this->rowActions;
- }
-
- public function setRowActions(array $rowActions) {
- $this->rowActions = $rowActions;
- }
-
- public function getType()
- {
- return 'actions';
- }
-}
+<?php
+
+/*
+ * This file is part of the DataGridBundle.
+ *
+ * (c) Stanislav Turza <sorien@mail.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Sorien\DataGridBundle\Grid\Column;
+
+use Sorien\DataGridBundle\Grid\Action\RowAction;
+
+class ActionsColumn extends Column
+{
+ private $rowActions;
+
+ public function __construct($column, $title, array $rowActions = array())
+ {
+ $this->rowActions = $rowActions;
+ parent::__construct(array('id' => $column, 'title' => $title, 'sortable' => false, 'source' => false));
+ }
+
+ public function getRouteParameters($row, $action)
+ {
+ $routeParameters = array_merge(
+ array($row->getPrimaryField() => $row->getPrimaryFieldValue()),
+ $action->getRouteParameters()
+ );
+
+ return $routeParameters;
+ }
+
+ public function getRowActions()
+ {
+ return $this->rowActions;
+ }
+
+ public function setRowActions(array $rowActions) {
+ $this->rowActions = $rowActions;
+ }
+
+ public function getType()
+ {
+ return 'actions';
+ }
+}
View
79 Grid/Column/BooleanColumn.php
@@ -1,40 +1,39 @@
-<?php
-
- /*
- * This file is part of the DataGridBundle.
- *
- * (c) Stanislav Turza <sorien@mail.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Sorien\DataGridBundle\Grid\Column;
-
-class BooleanColumn extends SelectColumn
-{
- public function __initialize(array $params)
- {
- if (!isset($params['values']))
- {
- $params['values'] = array(1 => 'true', 0 => 'false');
- }
-
- parent::__initialize($params);
- }
-
- public function renderCell($value, $row, $router)
- {
- return parent::renderCell((int)$value, $row, $router);
- }
-
- public function getType()
- {
- return 'boolean';
- }
-
- public function getParentType()
- {
- return 'select';
- }
-}
+<?php
+/*
+ * This file is part of the DataGridBundle.
+ *
+ * (c) Stanislav Turza <sorien@mail.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Sorien\DataGridBundle\Grid\Column;
+
+class BooleanColumn extends SelectColumn
+{
+ public function __initialize(array $params)
+ {
+ if (!isset($params['values']))
+ {
+ $params['values'] = array(1 => 'true', 0 => 'false');
+ }
+
+ parent::__initialize($params);
+ }
+
+ public function renderCell($value, $row, $router)
+ {
+ return parent::renderCell($value, $row, $router);
+ }
+
+ public function getType()
+ {
+ return 'boolean';
+ }
+
+ public function getParentType()
+ {
+ return 'select';
+ }
+}
View
15 Grid/Column/Column.php
@@ -12,6 +12,7 @@
namespace Sorien\DataGridBundle\Grid\Column;
use Symfony\Component\Security\Core\SecurityContextInterface;
+use Sorien\DataGridBundle\Grid\Helper\FilterStorageBag;
abstract class Column
{
@@ -57,7 +58,7 @@
private $securityContext;
/**
- * @todo make private
+ * @var FilterStorageBag
*/
protected $data;
@@ -88,6 +89,8 @@ public function __initialize(array $params)
$this->setField($this->getParam('field'));
$this->setRole($this->getParam('role'));
$this->setOrder($this->getParam('order'));
+
+ $this->data = new FilterStorageBag();
}
protected function getParam($id, $default = null)
@@ -238,7 +241,7 @@ public function getSortable()
*/
public function isFiltered()
{
- return $this->data != null;
+ return !$this->data->isEmpty();
}
public function setFilterable($filterable)
@@ -362,19 +365,19 @@ public function getOrderUrl()
/**
* Set filter data from Storage or Request
*
- * @param $data
+ * @param FilterStorageBag $data
* @return \Sorien\DataGridBundle\Grid\Column\Column
*/
- public function setData($data)
+ public function setData(FilterStorageBag $data)
{
- $this->data = $data;
+ $this->data->assign($data);
return $this;
}
/**
* Get filter data for Storage
*
- * @return array data
+ * @return FilterStorageBag data
*/
public function getData()
{
View
80 Grid/Column/MassActionColumn.php
@@ -1,40 +1,40 @@
-<?php
-
-/*
- * This file is part of the DataGridBundle.
- *
- * (c) Stanislav Turza <sorien@mail.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Sorien\DataGridBundle\Grid\Column;
-
-class MassActionColumn extends Column
-{
- const ID = '__action';
-
- private $gridHash;
-
- public function __construct($gridHash)
- {
- $this->gridHash = $gridHash;
- parent::__construct(array('id' => self::ID, 'title' => '', 'size' => 15, 'sortable' => false, 'source' => false, 'align' => 'center'));
- }
-
- public function renderFilter($gridHash)
- {
- return '<input type="checkbox" class="grid-mass-selector" onclick="'.$gridHash.'_mark_visible(this.checked); return true;"/>';
- }
-
- public function renderCell($value, $row, $router)
- {
- return '<input type="checkbox" class="action" value="1" name="'.$this->gridHash.'['.self::ID.']['.$row->getPrimaryFieldValue().']"/>';
- }
-
- public function getType()
- {
- return 'massaction';
- }
-}
+<?php
+
+/*
+ * This file is part of the DataGridBundle.
+ *
+ * (c) Stanislav Turza <sorien@mail.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Sorien\DataGridBundle\Grid\Column;
+
+class MassActionColumn extends Column
+{
+ const ID = '__action';
+
+ private $gridHash;
+
+ public function __construct($gridHash)
+ {
+ $this->gridHash = $gridHash;
+ parent::__construct(array('id' => self::ID, 'title' => '', 'size' => 15, 'sortable' => false, 'source' => false, 'align' => 'center'));
+ }
+
+// public function renderFilter($gridHash)
+// {
+// return '<input type="checkbox" class="grid-mass-selector" onclick="'.$gridHash.'_mark_visible(this.checked); return true;"/>';
+// }
+
+// public function renderCell($value, $row, $router)
+// {
+// return '<input type="checkbox" class="action" value="1" name="'.$this->gridHash.'['.self::ID.']['.$row->getPrimaryFieldValue().']"/>';
+// }
+
+ public function getType()
+ {
+ return 'massaction';
+ }
+}
View
45 Grid/Column/RangeColumn.php
@@ -12,6 +12,7 @@
namespace Sorien\DataGridBundle\Grid\Column;
use Sorien\DataGridBundle\Grid\Filter;
+use Sorien\DataGridBundle\Grid\Helper\FilterStorageBag;
class RangeColumn extends Column
{
@@ -37,59 +38,37 @@ public function getFilters()
{
$result = array();
- if ($this->data['from'] != '')
+ if ($this->data->has('from'))
{
- $result[] = new Filter(self::OPERATOR_GTE, (int)$this->data['from']);
+ $result[] = new Filter(self::OPERATOR_GTE, $this->data->getInt('from'));
}
- if ($this->data['to'] != '')
+ if ($this->data->has('to'))
{
- $result[] = new Filter(self::OPERATOR_LTE, (int)$this->data['to']);
+ $result[] = new Filter(self::OPERATOR_LTE, $this->data->getInt('to'));
}
return $result;
}
- public function setData($data)
+ public function setData(FilterStorageBag $data)
{
- $this->data = array('from' => '', 'to' => '');
-
- if (is_array($data))
- {
- if (isset($data['from']) && is_string($data['from']))
- {
- $this->data['from'] = $data['from'];
- }
-
- if (isset($data['to']) && is_string($data['to']))
- {
- $this->data['to'] = $data['to'];
- }
- }
-
- return $this;
- }
-
- public function getData()
- {
- $result = array();
-
- if ($this->data['from'] != '')
+ if ($data->get('from', 0) != 0)
{
- $result['from'] = $this->data['from'];
+ $this->data->set('from', $data->get('from'));
}
- if ($this->data['to'] != '')
+ if ($data->get('to', 0) != 0)
{
- $result['to'] = $this->data['to'];
+ $this->data->set('to', $data->get('to'));
}
- return $result;
+ return $this;
}
public function isFiltered()
{
- return $this->data['from'] != '' || $this->data['to'] != '';
+ return ($this->data->has('from') || $this->data->has('to'));
}
public function getType()
View
132 Grid/Column/SelectColumn.php
@@ -1,62 +1,70 @@
-<?php
-
- /*
- * This file is part of the DataGridBundle.
- *
- * (c) Stanislav Turza <sorien@mail.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Sorien\DataGridBundle\Grid\Column;
-
-use Sorien\DataGridBundle\Grid\Filter;
-
-class SelectColumn extends Column
-{
- const BLANK = '_default';
-
- private $values;
-
- public function __initialize(array $params)
- {
- parent::__initialize($params);
- $this->values = $this->getParam('values', array());
- }
-
- public function setData($data)
- {
- if ((is_string($data) || is_integer($data)) && $data != $this::BLANK && key_exists($data, $this->values))
- {
- $this->data = $data;
- }
-
- return $this;
- }
-
- public function getFilters()
- {
- return array(new Filter(self::OPERATOR_EQ, $this->data));
- }
-
- public function getValues()
- {
- return $this->values;
- }
-
- public function renderCell($value, $row, $router)
- {
- if (key_exists((string)$value, $this->values))
- {
- $value = $this->values[$value];
- }
-
- return parent::renderCell($value, $row, $router);
- }
-
- public function getType()
- {
- return 'select';
- }
-}
+<?php
+
+ /*
+ * This file is part of the DataGridBundle.
+ *
+ * (c) Stanislav Turza <sorien@mail.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Sorien\DataGridBundle\Grid\Column;
+
+use Sorien\DataGridBundle\Grid\Filter;
+use Sorien\DataGridBundle\Grid\Helper\FilterStorageBag;
+
+class SelectColumn extends Column
+{
+ const BLANK = '_default';
+
+ private $values;
+
+ public function __initialize(array $params)
+ {
+ parent::__initialize($params);
+ $this->values = $this->getParam('values', array());
+ }
+
+ public function setData(FilterStorageBag $data)
+ {
+ if ($data->get('value', $this::BLANK) !== $this::BLANK)
+ {
+ $this->data->assign($data);
+ }
+
+ return $this;
+ }
+
+ public function getFilters()
+ {
+ return array(new Filter(self::OPERATOR_EQ, $this->data->get('value')));
+ }
+
+ public function isFiltered()
+ {
+ return $this->data->has('value');
+ }
+
+ public function getValues()
+ {
+ return $this->values;
+ }
+
+ public function renderCell($value, $row, $router)
+ {
+ $value = is_bool($value) ? (int)$value : $value;
+
+ if (key_exists((string)$value, $this->values))
+ {
+ $value = $this->values[$value];
+ }
+
+ return parent::renderCell($value, $row, $router);
+ }
+
+ public function getType()
+ {
+ return 'select';
+ }
+}
View
16 Grid/Column/TextColumn.php
@@ -12,24 +12,30 @@
namespace Sorien\DataGridBundle\Grid\Column;
use Sorien\DataGridBundle\Grid\Filter;
+use Sorien\DataGridBundle\Grid\Helper\FilterStorageBag;
class TextColumn extends Column
{
public function getFilters()
{
- return array(new Filter(self::OPERATOR_REGEXP, '/.*'.$this->data.'.*/i'));
+ return array(new Filter(self::OPERATOR_REGEXP, '/.*'.$this->data->get('value', '').'.*/i'));
}
- public function setData($data)
+ public function setData(FilterStorageBag $data)
{
- if (is_string($data) && $data != '')
+ if ($data->get('value', '') != '')
{
- $this->data = $data;
+ $this->data->assign($data);
}
return $this;
}
-
+
+ public function isFiltered()
+ {
+ return $this->data->has('value');
+ }
+
public function getType()
{
return 'text';
View
283 Grid/Columns.php
@@ -1,142 +1,143 @@
-<?php
-
-/*
- * This file is part of the DataGridBundle.
- *
- * (c) Stanislav Turza <sorien@mail.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Sorien\DataGridBundle\Grid;
-
-use Sorien\DataGridBundle\Grid\Column\Column;
-use Sorien\DataGridBundle\Grid\Helper\ColumnsIterator;
-use Symfony\Component\Security\Core\SecurityContextInterface;
-
-class Columns implements \IteratorAggregate, \Countable
-{
- /**
- * @var \Sorien\DataGridBundle\Grid\Column\Column[]
- */
- private $columns;
- private $extensions;
-
- /**
- * @var \Symfony\Component\Security\Core\SecurityContextInterface
- */
- private $securityContext;
-
- public function __construct(SecurityContextInterface $securityContext)
- {
- $this->columns = array();
- $this->securityContext = $securityContext;
- }
-
- public function getIterator($showOnlySourceColumns = false)
- {
- return new ColumnsIterator(new \ArrayIterator($this->columns), $showOnlySourceColumns);
- }
-
- /**
- * Add column, column object have to extend Column
- * @param Column $column
- * @param int $position
- * @return Grid
- */
- public function addColumn($column, $position = 0)
- {
- if (!$column instanceof Column)
- {
- throw new \InvalidArgumentException('Your column needs to extend class Column.');
- }
-
- $column->setSecurityContext($this->securityContext);
-
- if ($position > 0)
- {
- $position--;
- $head = array_slice($this->columns, 0, $position);
- $tail = array_slice($this->columns, $position);
- $this->columns = array_merge($head, array($column), $tail);
- }
- else
- {
- $this->columns[] = $column;
- }
-
- return $this;
- }
-
- public function getColumnById($columnId)
- {
- $column = $this->hasColumnById($columnId, true);
-
- if ($column === false) {
- throw new \InvalidArgumentException(sprintf('Column with id "%s" doesn\'t exists', $columnId));
- }
-
- return $column;
- }
-
- public function hasColumnById($columnId, $returnColumn = false)
- {
- foreach ($this->columns as $column)
- {
- if ($column->getId() == $columnId)
- {
- return $returnColumn ? $column : true;
- }
- }
-
- return false;
- }
-
- public function getPrimaryColumn()
- {
- foreach ($this->columns as $column)
- {
- if ($column->isPrimary())
- {
- return $column;
- }
- }
-
- throw new \InvalidArgumentException('Primary column doesn\'t exists');
- }
-
- public function count()
- {
- return count($this->columns);
- }
-
- public function addExtension($extension)
- {
- $this->extensions[strtolower($extension->getType())] = $extension;
- }
-
- public function hasExtensionForColumnType($type)
- {
- return isset($this->extensions[$type]);
- }
-
- public function getExtensionForColumnType($type)
- {
- return $this->extensions[$type];
- }
-
- /**
- * Internal function
- * @return string
- */
- public function getHash()
- {
- $hash = '';
- foreach ($this->columns as $column)
- {
- $hash .= $column->getId();
- }
- return $hash;
- }
+<?php
+
+/*
+ * This file is part of the DataGridBundle.
+ *
+ * (c) Stanislav Turza <sorien@mail.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Sorien\DataGridBundle\Grid;
+
+use Sorien\DataGridBundle\Grid\Column\Column;
+use Sorien\DataGridBundle\Grid\Helper\ColumnsIterator;
+use Symfony\Component\Security\Core\SecurityContextInterface;
+
+class Columns implements \IteratorAggregate, \Countable
+{
+ /**
+ * @var Column[]
+ */
+ private $columns;
+ private $extensions;
+
+ /**
+ * @var SecurityContextInterface
+ */
+ private $securityContext;
+
+ public function __construct(SecurityContextInterface $securityContext)
+ {
+ $this->columns = array();
+ $this->securityContext = $securityContext;
+ }
+
+ public function getIterator($showOnlySourceColumns = false)
+ {
+ return new ColumnsIterator(new \ArrayIterator($this->columns), $showOnlySourceColumns);
+ }
+
+ /**
+ * Add column, column object have to extend Column
+ *
+ * @param Column $column
+ * @param int $position
+ * @return Grid
+ */
+ public function addColumn($column, $position = 0)
+ {
+ if (!$column instanceof Column)
+ {
+ throw new \InvalidArgumentException('Your column needs to extend class Column.');
+ }
+
+ $column->setSecurityContext($this->securityContext);
+
+ if ($position > 0)
+ {
+ $position--;
+ $head = array_slice($this->columns, 0, $position);
+ $tail = array_slice($this->columns, $position);
+ $this->columns = array_merge($head, array($column), $tail);
+ }
+ else
+ {
+ $this->columns[] = $column;
+ }
+
+ return $this;
+ }
+
+ public function getColumnById($columnId)
+ {
+ $column = $this->hasColumnById($columnId, true);
+
+ if ($column === false) {
+ throw new \InvalidArgumentException(sprintf('Column with id "%s" doesn\'t exists', $columnId));
+ }
+
+ return $column;
+ }
+
+ public function hasColumnById($columnId, $returnColumn = false)
+ {
+ foreach ($this->columns as $column)
+ {
+ if ($column->getId() == $columnId)
+ {
+ return $returnColumn ? $column : true;
+ }
+ }
+
+ return false;
+ }
+
+ public function getPrimaryColumn()
+ {
+ foreach ($this->columns as $column)
+ {
+ if ($column->isPrimary())
+ {
+ return $column;
+ }
+ }
+
+ throw new \InvalidArgumentException('Primary column doesn\'t exists');
+ }
+
+ public function count()
+ {
+ return count($this->columns);
+ }
+
+ public function addExtension($extension)
+ {
+ $this->extensions[strtolower($extension->getType())] = $extension;
+ }
+
+ public function hasExtensionForColumnType($type)
+ {
+ return isset($this->extensions[$type]);
+ }
+
+ public function getExtensionForColumnType($type)
+ {
+ return $this->extensions[$type];
+ }
+
+ /**
+ * Internal function
+ * @return string
+ */
+ public function getHash()
+ {
+ $hash = '';
+ foreach ($this->columns as $column)
+ {
+ $hash .= $column->getId();
+ }
+ return $hash;
+ }
}
View
120 Grid/Filter.php
@@ -1,60 +1,60 @@
-<?php
-
-/*
- * This file is part of the DataGridBundle.
- *
- * (c) Stanislav Turza <sorien@mail.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-namespace Sorien\DataGridBundle\Grid;
-
-class Filter
-{
- private $value;
- private $operator;
- private $id;
-
- public function __construct($operator, $value, $id = null)
- {
- $this->value = $value;
- $this->operator = $operator;
- $this->id = $id;
- }
-
- public function setOperator($operator)
- {
- $this->operator = $operator;
- }
-
- public function getOperator()
- {
- return $this->operator;
- }
-
- public function setValue($value)
- {
- $this->value = $value;
- }
-
- public function getValue()
- {
- return $this->value;
- }
-
- public function hasId()
- {
- return $this->id !== null;
- }
-
- public function setId($id)
- {
- $this->id = $id;
- }
-
- public function getId()
- {
- return $this->id;
- }
-}
+<?php
+
+/*
+ * This file is part of the DataGridBundle.
+ *
+ * (c) Stanislav Turza <sorien@mail.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+namespace Sorien\DataGridBundle\Grid;
+
+class Filter
+{
+ private $value;
+ private $operator;
+ private $id;
+
+ public function __construct($operator, $value, $id = null)
+ {
+ $this->value = $value;
+ $this->operator = $operator;
+ $this->id = $id;
+ }
+
+ public function setOperator($operator)
+ {
+ $this->operator = $operator;
+ }
+
+ public function getOperator()
+ {
+ return $this->operator;
+ }
+
+ public function setValue($value)
+ {
+ $this->value = $value;
+ }
+
+ public function getValue()
+ {
+ return $this->value;
+ }
+
+ public function hasId()
+ {
+ return $this->id !== null;
+ }
+
+ public function setId($id)
+ {
+ $this->id = $id;
+ }
+
+ public function getId()
+ {
+ return $this->id;
+ }
+}
View
81 Grid/Grid.php
@@ -13,6 +13,7 @@
namespace Sorien\DataGridBundle\Grid;
use Symfony\Component\HttpFoundation\RedirectResponse;
+use Symfony\Component\HttpFoundation\Response;
use Sorien\DataGridBundle\Grid\Columns;
use Sorien\DataGridBundle\Grid\Rows;
@@ -22,6 +23,7 @@
use Sorien\DataGridBundle\Grid\Column\MassActionColumn;
use Sorien\DataGridBundle\Grid\Column\ActionsColumn;
use Sorien\DataGridBundle\Grid\Source\Source;
+use Sorien\DataGridBundle\Grid\Helper\FilterStorageBag;
class Grid
{
@@ -101,6 +103,11 @@ class Grid
private $massActions = array();
/**
+ * @var int
+ */
+ private $massActionsCounter = 0;
+
+ /**
* @var \Sorien\DataGridBundle\Grid\Action\RowAction[]
*/
private $rowActions = array();
@@ -188,7 +195,7 @@ private function store($key, $value, $default = null)
{
$storage = $this->session->has($this->getHash()) ? $this->session->get($this->getHash()) : array();
- if ((key_exists($key, $storage) && $value == null) or ($value == $default))
+ if ((key_exists($key, $storage) && $value == null) or ($value === $default))
{
unset($storage[$key]);
}
@@ -266,19 +273,23 @@ private function processFiltersData()
{
foreach ($this->columns as $column)
{
- $storedData = $this->load($column->getId(), false, true);
+ /** Last data in Session */
+ $storedData = new FilterStorageBag($this->load($column->getId(), false, true, array()));
- $column->setData($this->load($column->getId()));
+ /** Store Combined Data */
+ $column->setData(new FilterStorageBag($this->load($column->getId(), true, true, array())));
+ /** Retrieve data from filter */
$storeData = $column->getData();
- //filter has changed reset page
- if ($storedData !== $storeData)
+ /** Filter has changed reset page */
+ if ($storedData->equals($storeData) === false)
{
$this->store(self::REQUEST_QUERY_PAGE, null);
}
- $this->store($column->getId(), $storeData);
+ /** Store Data */
+ $this->store($column->getId(), $storeData->all(), array());
}
}
@@ -334,36 +345,43 @@ private function processGridData()
public function executeMassActions()
{
$actionId = $this->load(Grid::REQUEST_QUERY_MASS_ACTION, true, false);
-
$actionAllKeys = $this->load(Grid::REQUEST_QUERY_MASS_ACTION_ALL_KEYS_SELECTED, true, false);
-
- $actionKeys = $actionAllKeys == false ? $this->load(MassActionColumn::ID, true, false) : array();
+ $actionKeys = $actionAllKeys ? $this->source->getPrimaryKeys($this->columns) : array_keys($this->load(MassActionColumn::ID, true, false, array()));
if ($actionId > -1 && is_array($actionKeys))
{
- if (array_key_exists($actionId, $this->massActions))
+ foreach ($this->massActions as $group)
{
- $action = $this->massActions[$actionId];
-
- if (is_callable($action->getCallback()))
- {
- //call closure or static method
- call_user_func($action->getCallback(), array_keys($actionKeys), $actionAllKeys, $this->session);
- }
- elseif (substr_count($action->getCallback(), ':') == 2)
+ foreach ($group as $massAction)
{
- //call controller action
- $this->container->get('http_kernel')->forward($action->getCallback(), array('primaryKeys' => array_keys($actionKeys), 'allPrimaryKeys' => $actionAllKeys));
- }
- else
- {
- throw new \RuntimeException(sprintf('Callback %s is not callable or Controller action', $action->getCallback()));
+ if ($massAction['id'] == $actionId)
+ {
+ /** @var MassActionInterface $action */
+ $action = $massAction['action'];
+
+ if (is_callable($action->getCallback()))
+ {
+ //call closure or static method
+ call_user_func($action->getCallback(), $actionKeys, $action->getArguments(), $this->session);
+ }
+ elseif (substr_count($action->getCallback(), ':') == 2)
+ {
+ //clear Request Id to prevent infinite loop when redirecting back from mass action
+ //call controller action
+ $this->container->get('http_kernel')->forward($action->getCallback(), array_merge(array('keys' => $actionKeys), $action->getArguments() ));
+ //
+ }
+ else
+ {
+ throw new \RuntimeException(sprintf('Callback %s is not callable or Controller action', $action->getCallback()));
+ }
+
+ return;
+ }
}
}
- else
- {
- throw new \OutOfBoundsException(sprintf('Action %s is not defined.', $actionId));
- }
+
+ throw new \OutOfBoundsException(sprintf('Action %s is not defined.', $actionId));
}
}
@@ -512,10 +530,9 @@ public function getColumns()
* @param Action\MassActionInterface $action
* @return Grid
*/
- public function addMassAction(MassActionInterface $action)
+ public function addMassAction(MassActionInterface $action, $group = '_default')
{
- $this->massActions[] = $action;
-
+ $this->massActions[$group][] = array('id' => $this->massActionsCounter++, 'action' => $action);
return $this;
}
@@ -843,7 +860,7 @@ function __clone()
*
* @return Response A Response instance
*/
- public function gridResponse(array $parameters = array(), $view = null, Response $response = null)
+ public function response($view = null, array $parameters = array(), Response $response = null)
{
if ($this->getState() == self::GRID_STATE_REDIRECT)
{
View
236 Grid/GridManager.php
@@ -1,118 +1,118 @@
-<?php
-
-/*
- * This file is part of the DataGridBundle.
- *
- * (c) Stanislav Turza <sorien@mail.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Sorien\DataGridBundle\Grid;
-
-use Symfony\Component\HttpFoundation\RedirectResponse;
-
-class GridManager implements \IteratorAggregate, \Countable
-{
- private $container;
-
- /**
- * @var Grids[]
- */
- private $grids;
-
- private $routeUrl = null;
-
- public function __construct($container)
- {
- $this->container = $container;
- $this->grids = new \SplObjectStorage();
- }
-
- public function getIterator()
- {
- return $this->grids;
- }
-
- public function count()
- {
- return $this->grids->count();
- }
-
- public function createGrid()
- {
- $grid = $this->container->get('grid');
-
- // route url is the same for all grids
- if (is_null($this->routeUrl)) {
- $this->routeUrl = $grid->getRouteUrl();
- }
-
- $this->grids->attach($grid);
-
- return $grid;
- }
-
- public function isReadyForRedirect()
- {
- if ($this->grids->count()==0) {
- throw new \RuntimeException('No grid has been added to the manager.');
- }
-
- $checkHash = array();
-
- $this->grids->rewind();
- while($this->grids->valid()) {
- /* @var $grid Sorien\DataGridBundle\Grid\Grid */
- $grid = $this->grids->current();
-
- if (in_array($grid->getHash(), $checkHash))
- {
- throw new \RuntimeException('Some grids seem similar. Please set an Indentifier for your grids.');
- }
- else {
- $checkHash[] = $grid->getHash();
- }
-
- if ($grid->isReadyForRedirect()){
- return true;
- }
-
- $this->grids->next();
- }
-
- return false;
- }
-
- /**
- * Renders a view.
- *
- * @param array $parameters An array of parameters to pass to the view
- * @param string $view The view name
- * @param Response $response A response instance
- *
- * @return Response A Response instance
- */
- public function gridManagerResponse(array $parameters = array(), $view = null, Response $response = null)
- {
- if ($this->isReadyForRedirect())
- {
- return new RedirectResponse($this->getRouteUrl());
- }
- else
- {
- if (is_null($view)) {
- return $parameters;
- }
- else {
- return $this->container->get('templating')->renderResponse($view, $parameters, $response);
- }
- }
- }
-
- public function getRouteUrl()
- {
- return $this->routeUrl;
- }
-}
+<?php
+
+/*
+ * This file is part of the DataGridBundle.
+ *
+ * (c) Stanislav Turza <sorien@mail.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Sorien\DataGridBundle\Grid;
+
+use Symfony\Component\HttpFoundation\RedirectResponse;
+
+class GridManager implements \IteratorAggregate, \Countable
+{
+ private $container;
+
+ /**
+ * @var Grids[]
+ */
+ private $grids;
+
+ private $routeUrl = null;
+
+ public function __construct($container)
+ {
+ $this->container = $container;
+ $this->grids = new \SplObjectStorage();
+ }
+
+ public function getIterator()
+ {
+ return $this->grids;
+ }
+
+ public function count()
+ {
+ return $this->grids->count();
+ }
+
+ public function createGrid()
+ {
+ $grid = $this->container->get('grid');
+
+ // route url is the same for all grids
+ if (is_null($this->routeUrl)) {
+ $this->routeUrl = $grid->getRouteUrl();
+ }
+
+ $this->grids->attach($grid);