Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Version 2.0

  • Loading branch information...
commit c7973484ddd071e8da9b6262dddbf28a9b374a4a 1 parent 5217c18
@Abhoryo authored
Showing with 10,987 additions and 5,333 deletions.
  1. +5 −4 SorienDataGridBundle.php → APYDataGridBundle.php
  2. +68 −4 CHANGELOG.md
  3. +5 −3 DependencyInjection/{SorienDataGridExtension.php → APYDataGridExtension.php}
  4. +42 −42 DependencyInjection/Compiler/GridExtensionPass.php
  5. +0 −85 Form/GridTypeGuesser.php
  6. +4 −3 Grid/Action/DeleteMassAction.php
  7. +61 −8 Grid/Action/MassAction.php
  8. +17 −2 Grid/Action/MassActionInterface.php
  9. +36 −12 Grid/Action/RowAction.php
  10. +19 −4 Grid/Action/RowActionInterface.php
  11. +44 −9 Grid/Column/ActionsColumn.php
  12. +62 −10 Grid/Column/ArrayColumn.php
  13. +0 −27 Grid/Column/BlankColumn.php
  14. +23 −9 Grid/Column/BooleanColumn.php
  15. +748 −497 Grid/Column/Column.php
  16. +69 −42 Grid/Column/DateColumn.php
  17. +0 −48 Grid/Column/DateRangeColumn.php
  18. +69 −75 Grid/Column/DateTimeColumn.php
  19. +0 −184 Grid/Column/DateTimeRangeColumn.php
  20. +21 −11 Grid/Column/MassActionColumn.php
  21. +262 −0 Grid/Column/NumberColumn.php
  22. +0 −8 Grid/Column/PopulatableColumnInterface.php
  23. +0 −99 Grid/Column/RangeColumn.php
  24. +0 −68 Grid/Column/SelectColumn.php
  25. +0 −38 Grid/Column/SourceSelectColumn.php
  26. +53 −37 Grid/Column/TextColumn.php
  27. +25 −0 Grid/Column/TimeColumn.php
  28. +21 −40 Grid/Columns.php
  29. +27 −0 Grid/Export/CSVExport.php
  30. +79 −0 Grid/Export/DSVExport.php
  31. +49 −0 Grid/Export/ExcelExport.php
  32. +644 −0 Grid/Export/Export.php
  33. +28 −0 Grid/Export/JSONExport.php
  34. +29 −0 Grid/Export/PHPExcel2003Export.php
  35. +33 −0 Grid/Export/PHPExcel2007Export.php
  36. +73 −0 Grid/Export/PHPExcel5Export.php
  37. +33 −0 Grid/Export/PHPExcelHTMLExport.php
  38. +39 −0 Grid/Export/PHPExcelPDFExport.php
  39. +23 −0 Grid/Export/SCSVExport.php
  40. +27 −0 Grid/Export/TSVExport.php
  41. +43 −0 Grid/Export/XMLExport.php
  42. +10 −3 Grid/Filter.php
  43. +1,267 −1,280 Grid/Grid.php
  44. +68 −24 Grid/GridManager.php
  45. +32 −32 Grid/Helper/ColumnsIterator.php
  46. +38 −37 Grid/Mapping/Column.php
  47. +141 −158 Grid/Mapping/Driver/Annotation.php
  48. +22 −21 Grid/Mapping/Driver/DriverInterface.php
  49. +90 −92 Grid/Mapping/Metadata/Manager.php
  50. +104 −102 Grid/Mapping/Metadata/Metadata.php
  51. +57 −56 Grid/Mapping/Source.php
  52. +11 −6 Grid/Row.php
  53. +7 −15 Grid/Rows.php
  54. +0 −13 Grid/Source/DistinctFieldRepositoryInterface.php
  55. +391 −290 Grid/Source/Document.php
  56. +184 −117 Grid/Source/Entity.php
  57. +479 −128 Grid/Source/Source.php
  58. +112 −62 Grid/Source/Vector.php
  59. +1 −1  {Resources/meta → }/LICENSE
  60. +102 −49 README.md
  61. +47 −0 Resources/config/columns.xml
  62. +5 −77 Resources/config/services.xml
  63. +0 −164 Resources/doc/columns_configuration.md
  64. +59 −0 Resources/doc/columns_configuration/annotations/association_mapping.md
  65. +35 −0 Resources/doc/columns_configuration/annotations/column_annotation_class.md
  66. +62 −0 Resources/doc/columns_configuration/annotations/column_annotation_property.md
  67. +57 −0 Resources/doc/columns_configuration/annotations/dql_function.md
  68. +34 −0 Resources/doc/columns_configuration/annotations/source_annotation.md
  69. +59 −0 Resources/doc/columns_configuration/filters/create_filter.md
  70. +14 −0 Resources/doc/columns_configuration/filters/input_filter.md
  71. +77 −0 Resources/doc/columns_configuration/filters/select_filter.md
  72. +35 −0 Resources/doc/columns_configuration/types/array_column.md
  73. +26 −0 Resources/doc/columns_configuration/types/boolean_column.md
  74. +125 −0 Resources/doc/columns_configuration/types/create_column.md
  75. +17 −0 Resources/doc/columns_configuration/types/date_column.md
  76. +43 −0 Resources/doc/columns_configuration/types/datetime_column.md
  77. +53 −0 Resources/doc/columns_configuration/types/number_column.md
  78. +37 −0 Resources/doc/columns_configuration/types/text_column.md
  79. +7 −0 Resources/doc/columns_configuration/types/time_column.md
  80. +300 −0 Resources/doc/export/create_export.md
  81. +71 −0 Resources/doc/export/library-dependent_exports/PHPExcel/PHPExcel_HTML_export.md
  82. +75 −0 Resources/doc/export/library-dependent_exports/PHPExcel/PHPExcel_PDF_export.md
  83. +71 −0 Resources/doc/export/library-dependent_exports/PHPExcel/PHPExcel_excel2003_export.md
  84. +71 −0 Resources/doc/export/library-dependent_exports/PHPExcel/PHPExcel_excel2007_export.md
  85. +71 −0 Resources/doc/export/library-dependent_exports/PHPExcel/PHPExcel_excel5_export.md
  86. +22 −0 Resources/doc/export/library-dependent_exports/PHPExcel/PHPExcel_installation.md
  87. +56 −0 Resources/doc/export/native_exports/CSV_export.md
  88. +75 −0 Resources/doc/export/native_exports/DSV_export.md
  89. +46 −0 Resources/doc/export/native_exports/Excel_export.md
  90. +49 −0 Resources/doc/export/native_exports/JSON_export.md
  91. +56 −0 Resources/doc/export/native_exports/SCSV_export.md
  92. +54 −0 Resources/doc/export/native_exports/TSV_export.md
  93. +65 −0 Resources/doc/export/native_exports/XML_export.md
  94. +223 −0 Resources/doc/getting_started.md
  95. +0 −479 Resources/doc/grid_configuration.md
  96. +76 −0 Resources/doc/grid_configuration/add_actions_column.md
  97. +58 −0 Resources/doc/grid_configuration/add_column.md
  98. +19 −0 Resources/doc/grid_configuration/add_delete_mass_action.md
  99. +53 −0 Resources/doc/grid_configuration/add_mass_action.md
  100. +58 −0 Resources/doc/grid_configuration/add_row_action.md
  101. +82 −0 Resources/doc/grid_configuration/grid_response.md
  102. +73 −0 Resources/doc/grid_configuration/hide_show_columns.md
  103. +21 −0 Resources/doc/grid_configuration/manipulate_column.md
  104. +66 −0 Resources/doc/grid_configuration/manipulate_column_render_cell.md
  105. +65 −0 Resources/doc/grid_configuration/manipulate_query.md
  106. +82 −0 Resources/doc/grid_configuration/manipulate_rows_data.md
  107. +126 −0 Resources/doc/grid_configuration/multi_grid_manager.md
  108. +90 −0 Resources/doc/grid_configuration/set_data.md
  109. +74 −0 Resources/doc/grid_configuration/set_default_filters.md
  110. +44 −0 Resources/doc/grid_configuration/set_default_order.md
  111. +19 −0 Resources/doc/grid_configuration/set_default_page.md
  112. +28 −0 Resources/doc/grid_configuration/set_limits.md
  113. +26 −0 Resources/doc/grid_configuration/set_max_results.md
  114. +32 −0 Resources/doc/grid_configuration/set_prefix_titles.md
  115. +46 −0 Resources/doc/grid_configuration/set_separator_actions_column.md
  116. +44 −0 Resources/doc/grid_configuration/set_size_actions_column.md
  117. +117 −0 Resources/doc/grid_configuration/working_example.css
  118. +207 −0 Resources/doc/grid_configuration/working_example.md
  119. BIN  Resources/doc/images/false.png
  120. BIN  Resources/doc/images/screenshot_database.png
  121. BIN  Resources/doc/images/screenshot_en.png
  122. BIN  Resources/doc/images/screenshot_fr.png
  123. BIN  Resources/doc/images/screenshot_full.png
  124. BIN  Resources/doc/images/sort_down.gif
  125. BIN  Resources/doc/images/sort_up.gif
  126. BIN  Resources/doc/images/true.png
  127. +66 −66 Resources/doc/installation.md
  128. +0 −110 Resources/doc/multiple_grids.md
  129. +0 −87 Resources/doc/overriding_templates.md
  130. +83 −0 Resources/doc/source/document_source.md
  131. +78 −0 Resources/doc/source/entity_source.md
  132. +170 −0 Resources/doc/source/vector_source.md
  133. +90 −0 Resources/doc/summary.md
  134. +62 −0 Resources/doc/template/cell_rendering.md
  135. +31 −0 Resources/doc/template/filter_rendering.md
  136. 0  Resources/doc/template/overriding_internal_blocks.md
  137. +49 −0 Resources/doc/template/render_external_filters.md
  138. +75 −0 Resources/doc/template/render_the_grid.md
  139. +0 −121 Resources/doc/vector_configuration.md
  140. +122 −0 Resources/translations/messages.en.xliff
  141. +60 −0 Resources/translations/messages.fr.xliff
  142. +340 −224 Resources/views/blocks.html.twig
  143. +107 −125 Twig/DataGridExtension.php
  144. +121 −0 UPGRADE-2.0.md
  145. +33 −25 composer.json
View
9 SorienDataGridBundle.php → APYDataGridBundle.php
@@ -3,19 +3,20 @@
/*
* This file is part of the DataGridBundle.
*
- * (c) Stanislav Turza <sorien@mail.com>
+ * (c) Abhoryo <abhoryo@free.fr>
+ * (c) Stanislav Turza
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
-namespace Sorien\DataGridBundle;
+namespace APY\DataGridBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
-use Sorien\DataGridBundle\DependencyInjection\Compiler\GridExtensionPass;
+use APY\DataGridBundle\DependencyInjection\Compiler\GridExtensionPass;
-class SorienDataGridBundle extends Bundle
+class APYDataGridBundle extends Bundle
{
public function build(ContainerBuilder $container)
{
View
72 CHANGELOG.md
@@ -1,3 +1,68 @@
+`16 Jun 2012`
+
+ * [Bundle] Push the actuel master branch into the new 1.0 branch. The master branch is now the version 2.0 of this bundle.
+
+**New in 2.0:** See [UPGRADE-2.0.md](UPGRADE-2.0) documentation.
+
+ * [BC Break][Bundle] Change the namespace of the bundle
+ * [BC Break][Filters] Add operator selector feature with a default operator
+ * [Filters] Add operators Equals, Not equal to, Lower than, Lower than or equal to, Greater than, Greater than or equal to, Between exclusive, Between inclusive, Contains, Not contains, Starts with, Ends with, Is not defined, Is defined,
+ * [Filters] Add annotation and php support for the operator selector feature and for the default operator
+ * [BC Break][Columns] Remove range, select and sourceselect columns (Include now in all columns with the filter attribute)
+ * [Annotations][Filters] Add an attribute to define the type of the filter (input, select)
+ * [Select filter] Populate select filters from the query result or the source
+ * [Annotations][Select filter] Add an attribute to define the source values of the select filter (From values, the source or the query)
+ * [Annotations][Filters] Add range feature implemented in input and select filter type with the operators between.
+ * [BC Break][Grid::initFilter] Grid::initFilter rename to setDefaultFilters
+ * [BC Break][Grid::initOrder] Grid::initOrder rename to setDefaultOrder
+ * [Columns] Add a way to change the data junction of the filters of a column
+ * [Mass action] Add templates for massaction filter and cell
+ * [Mass action] Add additional parameters passed to the callback
+ * [Columns] Add number column (decimal, money, percent, duration, scientific, spell out)
+ * [Export] Add export feature
+ * [Export] Add DSV, CSV, SCSV, TSV, XML, Excel (with PHPExcel library) and html (with PHPExcel library) exports.
+ * [Grid::setLimits] Add support for a simple array to define limits (e.g. $grid->setLimits(5, 10);)
+ * [BC Break][Sources] Source::setCallBack rename to manipulateRow and manipulateQuery and the first argument is removed
+ * [BC Break][Columns] Column::setCallBack rename to manipulateRenderCell
+ * [Row action] Add addRouteParameters method on rowAction class
+ * [Row action] rowAction::setRouteParameters allows string
+ * [BC Break][Grid::gridResponse] Grid::gridResponse rename to Grid::getGridResponse
+ * [BC Break][Grid::gridManagerResponse] GridManager::gridManagerResponse rename to GridManager::getGridManagerResponse
+ * [Grid::getGridResponse] The view parameters and the view name in Grid::getGridResponse can be set in reverse order to match the Template::render function.
+ * [Grid::getGridResponse] Add array('grid' => $grid) automatically in view parameters with Grid::getGridResponse
+ * [Grid::getGridManagerResponse] GridManager::getGridManagerResponse can be set in reverse order to match the Template::render function.
+ * [Grid::getGridManagerResponse] Add array('grid1' => $grid1, 'grid2' => $grid2, ...) automatically in view parameters with GridManager::getGridManagerResponse
+ * [DQL Functions] Manage a simple parameter for dql aggregate functions (e.g. vars.var:CountIf:3)
+ * [Entity source] Implement setMaxResults feature
+ * [Document source] Implement setMaxResults feature
+ * [Document source] Add all filters with operators
+ * [Document source] Add populate select filters feature
+ * [Vector source] Implement setMaxResults feature
+ * [Vector source] Add guess typing
+ * [Vector source] Add all filters with operators
+ * [Vector source] Add guess type sorting
+ * [Vector source] Add populate select filters feature
+ * [Grid::setData] Implement setMaxResults feature
+ * [Grid::setData] Add all filters with operators
+ * [Grid::setData] Add guess type sorting
+ * [Grid::setData] Add populate select filters feature
+ * [Template] Add some css classes
+ * [Template] Show 'false' in the grid if value === false in boolean column because a false value isn't show in twig)
+ * [Template] Add width attribute on filter th tag too.
+ * [ActionsColumn] Add the method Grid::setActionsColumnSize to set the size of the actions column
+ * [ActionsColumn] Add the method Grid::setActionsColumnSeparator to set the separator of the actions column
+ * [Filter] Disallow url filtering if the column is not filterable
+ * [Sort] Disallow url sorting if the column is not sortable
+ * [Limit] Disallow url limit if the value is not in the limits selector
+ * [Bundle] Update composer
+ * [Bundle] Clean and optimize code
+ * [Bundle] Follow Code Standard of Symfony2
+ * [Docs] Rework the whole documentation with the new features.
+
+`25 May 2012`
+
+ * XMLHttpRequest force the persistence mode
+
`15 May 2012`
* Allow using controllers as services in mass actions (lstrojny)
@@ -44,7 +109,7 @@
* [BC Break] Show a message instead of an empty grid
* Add a way to pass twig variables to override blocks
-
+
`30 Apr 2012`
* Add array Column for Entity sources
@@ -54,7 +119,7 @@
* Add initOrder method
* Add show and hide columns methods
* Fix render bloc ids and manipulate row field ids with mapping fields.
-
+
`29 Apr 2012`
* Add Vector source
@@ -94,8 +159,7 @@
`8 Apr 2012`
- * as far as symfony 2.0 lacks of some important features and 2.1dev is heavily unstable with too many changes every day (which causes too many problems form my company) i've decided to stop using symfony2 for my future projects it basically means that i'll no longer support this bundle, Abhoryo and nurikabe have rights to merge any PR for this bundle
-
+ * as far as symfony 2.0 lacks of some important features and 2.1dev is heavily unstable with too many changes every day (which causes too many problems form my company) i've decided to stop using symfony2 for my future projects it basically means that i'll no longer support this bundle, Abhoryo and nurikabe have rights to merge any PR for this bundle
`20 Oct 2011`
View
8 DependencyInjection/SorienDataGridExtension.php → DependencyInjection/APYDataGridExtension.php
@@ -3,24 +3,26 @@
/*
* This file is part of the DataGridBundle.
*
- * (c) Stanislav Turza <sorien@mail.com>
+ * (c) Abhoryo <abhoryo@free.fr>
+ * (c) Stanislav Turza
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
-namespace Sorien\DataGridBundle\DependencyInjection;
+namespace APY\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
+class APYDataGridExtension extends Extension
{
public function load(array $config, ContainerBuilder $container)
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.xml');
+ $loader->load('columns.xml');
}
}
View
84 DependencyInjection/Compiler/GridExtensionPass.php
@@ -1,42 +1,42 @@
-<?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\Compiler;
-
-use Symfony\Component\DependencyInjection\Reference;
-use Symfony\Component\DependencyInjection\ContainerBuilder;
-use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
-
-class GridExtensionPass implements CompilerPassInterface
-{
- public function process(ContainerBuilder $container)
- {
- if (false === $container->hasDefinition('grid')) {
- return;
- }
-
- $definition = $container->getDefinition('grid');
-
- // Extensions must always be registered before everything else.
- // For instance, global variable definitions must be registered
- // afterward. If not, the globals from the extensions will never
- // be registered.
- $calls = $definition->getMethodCalls();
- $definition->setMethodCalls(array());
-
- foreach ($container->findTaggedServiceIds('grid.column.extension') as $id => $attributes)
- {
- $definition->addMethodCall('addColumnExtension', array(new Reference($id)));
- }
-
- $definition->setMethodCalls(array_merge($definition->getMethodCalls(), $calls));
- }
-}
+<?php
+
+/*
+ * This file is part of the DataGridBundle.
+ *
+ * (c) Abhoryo <abhoryo@free.fr>
+ * (c) Stanislav Turza
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace APY\DataGridBundle\DependencyInjection\Compiler;
+
+use Symfony\Component\DependencyInjection\Reference;
+use Symfony\Component\DependencyInjection\ContainerBuilder;
+use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
+
+class GridExtensionPass implements CompilerPassInterface
+{
+ public function process(ContainerBuilder $container)
+ {
+ if (false === $container->hasDefinition('grid')) {
+ return;
+ }
+
+ $definition = $container->getDefinition('grid');
+
+ // Extensions must always be registered before everything else.
+ // For instance, global variable definitions must be registered
+ // afterward. If not, the globals from the extensions will never
+ // be registered.
+ $calls = $definition->getMethodCalls();
+ $definition->setMethodCalls(array());
+
+ foreach ($container->findTaggedServiceIds('grid.column.extension') as $id => $attributes) {
+ $definition->addMethodCall('addColumnExtension', array(new Reference($id)));
+ }
+
+ $definition->setMethodCalls(array_merge($definition->getMethodCalls(), $calls));
+ }
+}
View
85 Form/GridTypeGuesser.php
@@ -1,85 +0,0 @@
-<?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\Form;
-
-use Symfony\Component\Form\FormTypeGuesserInterface;
-use Symfony\Component\Form\Guess\Guess;
-use Symfony\Component\Form\Guess\TypeGuess;
-use Symfony\Component\Form\Guess\ValueGuess;
-
-class GridTypeGuesser implements FormTypeGuesserInterface
-{
- /**
- * @var \Sorien\DataGridBundle\Grid\Mapping\Metadata\Manager;
- */
- protected $manager;
-
- /**
- * @var \Sorien\DataGridBundle\Grid\Mapping\Metadata\Metadata
- */
- protected $metadata;
-
- /**
- * @param $manager
- */
- public function __construct($manager)
- {
- $this->manager = $manager;
- }
-
- public function guessType($class, $property)
- {
- $metadata = $this->manager->getMetadata($class);
-
- if ($metadata->hasFieldMapping($property))
- {
- $params = $metadata->getFieldMapping($property);
- switch ($metadata->getFieldMappingType($property))
- {
-// case 'text':
-// if (isset($params['title']) && $params['title'] != '') // && strpos($params['id'], '.') === false
-// {
-// return new TypeGuess('text', array('label' => $params['title']), Guess::LOW_CONFIDENCE);
-// }
-// break;
- case 'select':
- if (!empty($params['values']))
- {
- return new TypeGuess('choice', array('choices' => $params['values']), Guess::HIGH_CONFIDENCE);
- }
- break;
- case 'boolean':
- return new TypeGuess('choice', array('choices' => array('1'=>'true','0'=>'false')), Guess::HIGH_CONFIDENCE);
- break;
- default:
- return null;
- }
- }
- }
-
- public function guessRequired($class, $property)
- {
- }
-
- public function guessMaxLength($class, $property)
- {
- }
-
- public function guessMinLength($class, $property)
- {
- }
-
- protected function isMappedClass($class)
- {
- return ;
- }
-}
View
7 Grid/Action/DeleteMassAction.php
@@ -3,13 +3,14 @@
/*
* This file is part of the DataGridBundle.
*
- * (c) Stanislav Turza <sorien@mail.com>
+ * (c) Abhoryo <abhoryo@free.fr>
+ * (c) Stanislav Turza
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
-namespace Sorien\DataGridBundle\Grid\Action;
+namespace APY\DataGridBundle\Grid\Action;
class DeleteMassAction extends MassAction
{
@@ -17,7 +18,7 @@ class DeleteMassAction extends MassAction
* Default DeleteMassAction constructor
*
* @param boolean $confirm Show confirm message if true
- * @return \Sorien\DataGridBundle\Grid\Action\MassAction
+ * @return \APY\DataGridBundle\Grid\Action\MassAction
*/
public function __construct($confirm = false)
{
View
69 Grid/Action/MassAction.php
@@ -3,19 +3,21 @@
/*
* This file is part of the DataGridBundle.
*
- * (c) Stanislav Turza <sorien@mail.com>
+ * (c) Abhoryo <abhoryo@free.fr>
+ * (c) Stanislav Turza
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
-namespace Sorien\DataGridBundle\Grid\Action;
+namespace APY\DataGridBundle\Grid\Action;
class MassAction implements MassActionInterface
{
protected $title;
protected $callback;
protected $confirm;
+ protected $parameters = array();
/**
* Default MassAction constructor
@@ -23,20 +25,23 @@ class MassAction implements MassActionInterface
* @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
+ * @return \APY\DataGridBundle\Grid\Action\MassAction
*/
- public function __construct($title, $callback = null, $confirm = false)
+ public function __construct($title, $callback = null, $confirm = false, $parameters = array())
{
$this->title = $title;
$this->callback = $callback;
$this->confirm = $confirm;
+ $this->confirmMessage = 'Do you want to '.strtolower($title).' the seleted rows?';
+ $this->parameters = $parameters;
}
/**
* Set action title
*
* @param $title
- * @return \Sorien\DataGridBundle\Grid\Action\MassAction
+ *
+ * @return self
*/
public function setTitle($title)
{
@@ -59,7 +64,8 @@ public function getTitle()
* Set action callback
*
* @param $callback
- * @return \Sorien\DataGridBundle\Grid\Action\MassAction
+ *
+ * @return self
*/
public function setCallback($callback)
{
@@ -82,7 +88,8 @@ public function getCallback()
* Set action confirm
*
* @param $confirm
- * @return \Sorien\DataGridBundle\Grid\Action\MassAction
+ *
+ * @return self
*/
public function setConfirm($confirm)
{
@@ -92,7 +99,7 @@ public function setConfirm($confirm)
}
/**
- * get action confirm
+ * Get action confirm
*
* @return boolean
*/
@@ -100,4 +107,50 @@ public function getConfirm()
{
return $this->confirm;
}
+
+ /**
+ * Set action confirmMessage
+ *
+ * @param string $confirmMessage
+ *
+ * @return self
+ */
+ public function setConfirmMessage($confirmMessage)
+ {
+ $this->confirmMessage = $confirmMessage;
+
+ return $this;
+ }
+
+ /**
+ * get action confirmMessage
+ *
+ * @return string
+ */
+ public function getConfirmMessage()
+ {
+ return $this->confirmMessage;
+ }
+
+ /**
+ * Set action/controller parameters
+ *
+ * @param array $parameters
+ */
+ public function setParameters(array $parameters)
+ {
+ $this->parameters = $parameters;
+
+ return $this;
+ }
+
+ /**
+ * Get action/controller parameters
+ *
+ * @return array
+ */
+ public function getParameters()
+ {
+ return $this->parameters;
+ }
}
View
19 Grid/Action/MassActionInterface.php
@@ -3,13 +3,14 @@
/*
* This file is part of the DataGridBundle.
*
- * (c) Stanislav Turza <sorien@mail.com>
+ * (c) Abhoryo <abhoryo@free.fr>
+ * (c) Stanislav Turza
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
-namespace Sorien\DataGridBundle\Grid\Action;
+namespace APY\DataGridBundle\Grid\Action;
interface MassActionInterface
{
@@ -33,4 +34,18 @@ public function getCallback();
* @return boolean
*/
public function getConfirm();
+
+ /**
+ * get action confirmMessage
+ *
+ * @return boolean
+ */
+ public function getConfirmMessage();
+
+ /**
+ * get additional parameters
+ *
+ * @return array
+ */
+ public function getParameters();
}
View
48 Grid/Action/RowAction.php
@@ -3,13 +3,14 @@
/*
* This file is part of the DataGridBundle.
*
- * (c) Stanislav Turza <sorien@mail.com>
+ * (c) Abhoryo <abhoryo@free.fr>
+ * (c) Stanislav Turza
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
-namespace Sorien\DataGridBundle\Grid\Action;
+namespace APY\DataGridBundle\Grid\Action;
class RowAction implements RowActionInterface
{
@@ -25,15 +26,15 @@ class RowAction implements RowActionInterface
/**
* Default RowAction constructor
*
- * @param string $title Title of the mass action
+ * @param string $title Title of the row 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)
+ * @param string $target Set the target of this action (_self,_blank,_parent,_top)
* @param array $attributes Attributes of the anchor tag
*
- * @return \Sorien\DataGridBundle\Grid\Action\RowAction
+ * @return \APY\DataGridBundle\Grid\Action\RowAction
*/
- public function __construct($title, $route = null, $confirm = false, $target = '_self', $attributes = array())
+ public function __construct($title, $route, $confirm = false, $target = '_self', $attributes = array())
{
$this->title = $title;
$this->route = $route;
@@ -48,7 +49,7 @@ public function __construct($title, $route = null, $confirm = false, $target = '
*
* @param string $title
*
- * @return \Sorien\DataGridBundle\Grid\Action\MassAction
+ * @return self
*/
public function setTitle($title)
{
@@ -95,6 +96,7 @@ public function getRoute()
* Set action confirm
*
* @param $confirm
+ *
* @return self
*/
public function setConfirm($confirm)
@@ -165,7 +167,7 @@ public function getTarget()
/**
* Set action column
*
- * @param \Sorien\DataGridBundle\Grid\Column\Column $column
+ * @param string $column Identifier of the action column
*
* @return self
*/
@@ -179,7 +181,7 @@ public function setColumn($column)
/**
* get action column
*
- * @return \Sorien\DataGridBundle\Grid\Column\Column
+ * @return \APY\DataGridBundle\Grid\Column\Column
*/
public function getColumn()
{
@@ -187,15 +189,37 @@ public function getColumn()
}
/**
+ * Add route parameter
+ *
+ * @param array|string $routeParameter
+ *
+ * @return self
+ */
+ public function addRouteParameters($routeParameters)
+ {
+ $routeParameters = (array) $routeParameters;
+
+ foreach ($routeParameters as $key => $routeParameter) {
+ if(is_int($key)) {
+ $this->routeParameters[$routeParameter] = $routeParameter;
+ } else {
+ $this->routeParameters[$key] = $routeParameter;
+ }
+ }
+
+ return $this;
+ }
+
+ /**
* Set route parameters
*
- * @param array $routeParameters
+ * @param array|string $routeParameters
*
* @return self
*/
- public function setRouteParameters(array $routeParameters)
+ public function setRouteParameters($routeParameters)
{
- $this->routeParameters = $routeParameters;
+ $this->routeParameters = (array) $routeParameters;
return $this;
}
View
23 Grid/Action/RowActionInterface.php
@@ -3,13 +3,14 @@
/*
* This file is part of the DataGridBundle.
*
- * (c) Stanislav Turza <sorien@mail.com>
+ * (c) Abhoryo <abhoryo@free.fr>
+ * (c) Stanislav Turza
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
-namespace Sorien\DataGridBundle\Grid\Action;
+namespace APY\DataGridBundle\Grid\Action;
interface RowActionInterface
{
@@ -39,7 +40,7 @@ public function getConfirm();
*
* @return boolean
*/
- public function getConfirmMessage();
+ public function getConfirmMessage();
/**
* get action target
@@ -49,9 +50,23 @@ public function getConfirmMessage();
public function getTarget();
/**
- * get action column
+ * get the action column id
*
* @return boolean
*/
public function getColumn();
+
+ /**
+ * get route parameters
+ *
+ * @return array
+ */
+ public function getRouteParameters();
+
+ /**
+ * get attributes of the link
+ *
+ * @return array
+ */
+ public function getAttributes();
}
View
53 Grid/Column/ActionsColumn.php
@@ -3,38 +3,49 @@
/*
* This file is part of the DataGridBundle.
*
- * (c) Stanislav Turza <sorien@mail.com>
+ * (c) Abhoryo <abhoryo@free.fr>
+ * (c) Stanislav Turza
*
* 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;
+namespace APY\DataGridBundle\Grid\Column;
class ActionsColumn extends Column
{
protected $rowActions;
+ protected $separator;
- public function __construct($column, $title, array $rowActions = array())
+ public function __construct($column, $title, array $rowActions = array(), $separator = ' ')
{
$this->rowActions = $rowActions;
- parent::__construct(array('id' => $column, 'title' => $title, 'sortable' => false, 'source' => false, 'filterable' => false));
+ $this->separator = $separator;
+
+ parent::__construct(array(
+ 'id' => $column,
+ 'title' => $title,
+ 'sortable' => false,
+ 'source' => false,
+ 'filterable' => false
+ ));
}
public function getRouteParameters($row, $action)
{
$actionParameters = $action->getRouteParameters();
- if(!empty($actionParameters)){
+
+ if(!empty($actionParameters)) {
$routeParameters = array();
+
foreach ($actionParameters as $name => $parameter) {
- if(is_numeric($name)){
+ if(is_int($name)) {
$routeParameters[$parameter] = $row->getField($parameter);
} else {
$routeParameters[$name] = $parameter;
}
}
+
return $routeParameters;
}
@@ -49,8 +60,32 @@ public function getRowActions()
return $this->rowActions;
}
- public function setRowActions(array $rowActions) {
+ public function setRowActions(array $rowActions)
+ {
$this->rowActions = $rowActions;
+
+ return $this;
+ }
+
+ public function isVisible($isExported = false)
+ {
+ if ($isExported) {
+ return false;
+ }
+
+ return parent::isVisible();
+ }
+
+ public function setSeparator($separator)
+ {
+ $this->separator = $separator;
+
+ return $this;
+ }
+
+ public function getSeparator()
+ {
+ return $this->separator;
}
public function getType()
View
72 Grid/Column/ArrayColumn.php
@@ -3,15 +3,16 @@
/*
* This file is part of the DataGridBundle.
*
- * (c) Stanislav Turza <sorien@mail.com>
+ * (c) Abhoryo <abhoryo@free.fr>
+ * (c) Stanislav Turza
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
-namespace Sorien\DataGridBundle\Grid\Column;
+namespace APY\DataGridBundle\Grid\Column;
-use Sorien\DataGridBundle\Grid\Filter;
+use APY\DataGridBundle\Grid\Filter;
class ArrayColumn extends Column
{
@@ -20,21 +21,72 @@ class ArrayColumn extends Column
public function __initialize(array $params)
{
parent::__initialize($params);
- $this->separator = $this->getParam('separator', "<br />");
+
+ $this->setSeparator($this->getParam('separator', "<br />"));
+ $this->setOperators($this->getParam('operators', array(
+ self::OPERATOR_LIKE,
+ self::OPERATOR_NLIKE,
+ self::OPERATOR_EQ,
+ self::OPERATOR_NEQ,
+ self::OPERATOR_ISNULL,
+ self::OPERATOR_ISNOTNULL,
+ )));
+ $this->setDefaultOperator($this->getParam('defaultOperator', self::OPERATOR_LIKE));
}
- public function getFilters()
+ public function getFilters($source)
{
- return array(new Filter(self::OPERATOR_REGEXP, '/.*"'.$this->data.'".*/i'));
+ $parentFilters = parent::getFilters($source);
+
+ $filters = array();
+ foreach($parentFilters as $filter) {
+ $len = strlen($filter->getValue());
+ $value = 's:'.$len.':"'.$filter->getValue().'";';
+
+ switch ($filter->getOperator()) {
+ case self::OPERATOR_EQ:
+ case self::OPERATOR_NEQ:
+ $filters[] = new Filter($filter->getOperator(), 'a:1:{'.$value.'}');
+ break;
+ case self::OPERATOR_LIKE:
+ case self::OPERATOR_NLIKE:
+ $filters[] = new Filter($filter->getOperator(), $value);
+ break;
+ case self::OPERATOR_ISNULL:
+ $filters[] = new Filter(self::OPERATOR_ISNULL);
+ $filters[] = new Filter(self::OPERATOR_EQ, 'a:0:{}');
+ $this->setDataJunction(self::DATA_DISJUNCTION);
+ break;
+ case self::OPERATOR_ISNOTNULL:
+ $filters[] = new Filter(self::OPERATOR_ISNOTNULL);
+ $filters[] = new Filter(self::OPERATOR_NEQ, 'a:0:{}');
+ break;
+ default:
+ $filters[] = $filter;
+ }
+ }
+
+ return $filters;
}
- public function setData($data)
+ public function renderCell($values, $row, $router)
{
- if (is_string($data))
- {
- $this->data = $data;
+ if (is_callable($this->callback)) {
+ return call_user_func($this->callback, $values, $row, $router);
}
+ $return = array();
+ foreach ($values as $key => $value) {
+ $return[$key] = (key_exists((string)$value, $this->values)) ? $value = $this->values[$value] : $value;
+ }
+
+ return $return;
+ }
+
+ public function setSeparator($separator)
+ {
+ $this->separator = $separator;
+
return $this;
}
View
27 Grid/Column/BlankColumn.php
@@ -1,27 +0,0 @@
-<?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 BlankColumn extends Column
-{
- public function __initialize(array $params)
- {
- parent::__initialize(array_merge(array('sortable' => false, 'filterable' => false, 'source' => false), $params));
- }
-
- public function getType()
- {
- return 'blank';
- }
-}
View
32 Grid/Column/BooleanColumn.php
@@ -3,33 +3,47 @@
/*
* This file is part of the DataGridBundle.
*
- * (c) Stanislav Turza <sorien@mail.com>
+ * (c) Abhoryo <abhoryo@free.fr>
+ * (c) Stanislav Turza
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
-namespace Sorien\DataGridBundle\Grid\Column;
+namespace APY\DataGridBundle\Grid\Column;
-class BooleanColumn extends SelectColumn
+class BooleanColumn extends Column
{
public function __initialize(array $params)
{
- if (!isset($params['values']))
- {
+ $params['selectFrom'] = 'values';
+
+ if (!isset($params['values'])) {
$params['values'] = array(1 => 'true', 0 => 'false');
}
+ $params['operators'] = array(self::OPERATOR_EQ);
+ $params['defaultOperator'] = self::OPERATOR_EQ;
+ $params['operatorsVisible'] = false;
+ $params['filter'] = 'select';
+
parent::__initialize($params);
+
+ $this->setAlign($this->getParam('align', 'center'));
+ $this->setSize($this->getParam('size', '30'));
}
- public function getType()
+ public function isQueryValid($query)
{
- return 'boolean';
+ if ($query === true || $query === false || $query == 1 || $query == 0) {
+ return true;
+ }
+
+ return false;
}
- public function getParentType()
+ public function getType()
{
- return 'select';
+ return 'boolean';
}
}
View
1,245 Grid/Column/Column.php
@@ -1,497 +1,748 @@
-<?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 Symfony\Component\Security\Core\SecurityContextInterface;
-
-abstract class Column
-{
- const DATA_CONJUNCTION = 0;
- const DATA_DISJUNCTION = 1;
-
- const OPERATOR_EQ = 'eq';
- const OPERATOR_NEQ = 'neq';
- const OPERATOR_LT = 'lt';
- const OPERATOR_LTE = 'lte';
- const OPERATOR_GT = 'gt';
- const OPERATOR_GTE = 'gte';
- const OPERATOR_REGEXP = 'req';
-
- const ALIGN_LEFT = 'left';
- const ALIGN_RIGHT = 'right';
- const ALIGN_CENTER = 'center';
-
- /**
- * Internal parameters
- */
- protected $id;
- protected $title;
- protected $sortable;
- protected $filterable;
- protected $visible;
- protected $callback;
- protected $order = '';
- protected $size;
- protected $visibleForSource;
- protected $primary;
- protected $align;
- protected $field;
- protected $role;
-
- protected $params;
- protected $isSorted = false;
- protected $orderUrl;
-
- /**
- * @var \Symfony\Component\Security\Core\SecurityContextInterface
- */
- protected $securityContext;
-
- protected $data;
-
- /**
- * Default Column constructor
- *
- * @param array $params
- * @return \Sorien\DataGridBundle\Grid\Column\Column
- */
- public function __construct($params = null)
- {
- $this->__initialize((array) $params);
- }
-
- public function __initialize(array $params)
- {
- $this->params = $params;
- $this->setId($this->getParam('id'));
- $this->setTitle($this->getParam('title', ''));
- $this->setSortable($this->getParam('sortable', true));
- $this->setVisible($this->getParam('visible', true));
- $this->setSize($this->getParam('size', -1));
- $this->setFilterable($this->getParam('filterable', true));
- $this->setVisibleForSource($this->getParam('source', false));
- $this->setPrimary($this->getParam('primary', false));
- $this->setAlign($this->getParam('align', self::ALIGN_LEFT));
- $this->setField($this->getParam('field'));
- $this->setRole($this->getParam('role'));
- $this->setOrder($this->getParam('order'));
- }
-
- protected function getParam($id, $default = null)
- {
- return isset($this->params[$id]) ? $this->params[$id] : $default;
- }
-
- /**
- * Draw filter
- *
- * @todo probably make function as abstract
- * @param string $gridHash
- * @return string
- */
- public function renderFilter($gridHash)
- {
- return '';
- }
-
- /**
- * Draw cell
- *
- * @param string $value
- * @param Row $row
- * @param $router
- * @return string
- */
- public function renderCell($value, $row, $router)
- {
- if (is_callable($this->callback))
- {
- return call_user_func($this->callback, $value, $row, $router);
- }
- else
- {
- return $value;
- }
- }
-
- /**
- * Set column callback
- *
- * @param $callback
- * @return \Sorien\DataGridBundle\Grid\Column\Column
- */
- public function setCallback($callback)
- {
- $this->callback = $callback;
-
- return $this;
- }
-
- /**
- * Set column identifier
- *
- * @param $id
- * @return \Sorien\DataGridBundle\Grid\Column\Column
- */
- public function setId($id)
- {
- $this->id = $id;
-
- return $this;
- }
-
- /**
- * get column identifier
- *
- * @return int|string
- */
- public function getId()
- {
- return $this->id;
- }
-
- /**
- * get column render block identifier
- *
- * @return int|string
- */
- public function getRenderBlockId()
- {
- // For Mapping fields and aggregate dql functions
- return str_replace(array('.', ':'), '_', $this->id);
- }
-
- /**
- * Set column title
- *
- * @param string $title
- * @return \Sorien\DataGridBundle\Grid\Column\Column
- */
- public function setTitle($title)
- {
- $this->title = $title;
-
- return $this;
- }
-
- /**
- * Get column title
- *
- * @return string
- */
- public function getTitle()
- {
- return $this->title;
- }
-
- /**
- * Return column visibility
- *
- * @return bool return true when column is visible
- */
- public function isVisible()
- {
- if ($this->visible && $this->securityContext !== null && $this->getRole() != null)
- {
- return $this->securityContext->isGranted($this->getRole());
- }
-
- return $this->visible;
- }
-
- /**
- * Set column visibility
- *
- * @param boolean $visible
- */
- public function setVisible($visible)
- {
- $this->visible = $visible;
- }
-
- /**
- * Return true if column is sorted
- *
- * @return bool return true when column is sorted
- */
- public function isSorted()
- {
- return $this->isSorted;
- }
-
- public function setSortable($sortable)
- {
- $this->sortable = $sortable;
- }
-
- public function getSortable()
- {
- return $this->sortable;
- }
-
- /**
- * Return true if column is filtered
- *
- * @return boolean return true when column is filtered
- */
- public function isFiltered()
- {
- return $this->data != null;
- }
-
- public function setFilterable($filterable)
- {
- $this->filterable = $filterable;
- }
-
- public function getFilterable()
- {
- return $this->filterable;
- }
-
- /**
- * column ability to filter
- *
- * @return bool return true when column can be filtred
- */
- public function isFilterable()
- {
- return $this->filterable;
- }
-
- /**
- * column ability to sort
- *
- * @return bool return true when column can be sorted
- */
- public function isSortable()
- {
- return $this->sortable;
- }
-
- /**
- * set column order
- *
- * @param string $order asc|desc
- * @return \Sorien\DataGridBundle\Grid\Column\Column
- */
- public function setOrder($order)
- {
- if (!$order) {
- return $this;
- }
-
- $this->order = $order;
- $this->isSorted = true;
-
- return $this;
- }
-
- /**
- * get column order
- *
- * @return string asc|desc
- */
- public function getOrder()
- {
- return $this->order;
- }
-
- /**
- * get data filter connection (how column filters are connected with column data)
- *
- * @return bool column::DATA_CONJUNCTION | column::DATA_DISJUNCTION
- */
- public function getFiltersConnection()
- {
- return self::DATA_CONJUNCTION;
- }
-
- /**
- * get column data filters
- * todo: maybe change to own class not array
- *
- * @return \Sorien\DataGridBundle\Grid\Filter[]
- */
- public function getFilters()
- {
- return array();
- }
-
- /**
- * set column width
- *
- * @param int $size in pixels
- * @return \Sorien\DataGridBundle\Grid\Column\Column
- */
- public function setSize($size)
- {
- if ($size >= -1)
- {
- $this->size = $size;
- }
- else throw new \InvalidArgumentException(sprintf('Unsupported column size %s, use positive value or -1 for auto resize', $size));
-
- return $this;
- }
-
- /**
- * get column width
- *
- * @return int column width in pixels
- */
- public function getSize()
- {
- return $this->size;
- }
-
- public function setOrderUrl($url)
- {
- $this->orderUrl = $url;
-
- return $this;
- }
-
- public function getOrderUrl()
- {
- return $this->orderUrl;
- }
-
- /**
- * set filter data from session | request
- *
- * @param $data
- * @return \Sorien\DataGridBundle\Grid\Column\Column
- */
- public function setData($data)
- {
- $this->data = $data;
- return $this;
- }
-
- /**
- * get filter data from session | request
- *
- * @return array data
- */
- public function getData()
- {
- return $this->data;
- }
-
- /**
- * Set column visibility for source class
- * @param $value
- * @return \Sorien\DataGridBundle\Grid\Column\Column
- */
- public function setIsVisibleForSource($value)
- {
- $this->visibleForSource = $value;
-
- return $this;
- }
-
- /**
- * Return true is column in visible for source class
- * @return boolean
- */
- public function isVisibleForSource()
- {
- return $this->visibleForSource;
- }
-
- public function setVisibleForSource($visibleForSource)
- {
- $this->visibleForSource = $visibleForSource;
- }
-
- /**
- * Return true is column in primary
- * @return boolean
- */
- public function isPrimary()
- {
- return $this->primary;
- }
-
- /**
- * Set column as primary
- *
- * @param boolean $primary
- */
- public function setPrimary($primary)
- {
- $this->primary = $primary;
- }
-
- /**
- * Set column align
- * @param string $align left/right/center
- */
- public function setAlign($align)
- {
- if ($align == $this::ALIGN_LEFT || $align == $this::ALIGN_CENTER || $align == $this::ALIGN_RIGHT)
- {
- $this->align = $align;
- }
- else throw new \InvalidArgumentException(sprintf('Unsupported align %s, just left, right and center are supported', $align));
- }
-
- /**
- * get column align
- * @return bool
- */
- public function getAlign()
- {
- return $this->align;
- }
-
- public function setField($field)
- {
- $this->field = $field;
- }
-
- public function getField()
- {
- return $this->field;
- }
-
- public function setRole($role)
- {
- $this->role = $role;
- }
-
- public function getRole()
- {
- return $this->role;
- }
-
- public function getType()
- {
- return '';
- }
-
- public function getParentType()
- {
- return '';
- }
-
- /**
- * Internal function
- *
- * @param $securityContext
- */
- public function setSecurityContext(SecurityContextInterface $securityContext)
- {
- $this->securityContext = $securityContext;
- }
-}
+<?php
+
+/*
+ * This file is part of the DataGridBundle.
+ *
+ * (c) Abhoryo <abhoryo@free.fr>
+ * (c) Stanislav Turza
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace APY\DataGridBundle\Grid\Column;
+
+use Symfony\Component\Security\Core\SecurityContextInterface;
+use APY\DataGridBundle\Grid\Filter;
+
+abstract class Column
+{
+ const DEFAULT_VALUE = null;
+
+ /**
+ * Filter
+ */
+ const DATA_CONJUNCTION = 0;
+ const DATA_DISJUNCTION = 1;
+
+ const OPERATOR_EQ = 'eq';
+ const OPERATOR_NEQ = 'neq';
+ const OPERATOR_LT = 'lt';
+ const OPERATOR_LTE = 'lte';
+ const OPERATOR_GT = 'gt';
+ const OPERATOR_GTE = 'gte';
+ const OPERATOR_BTW = 'btw';
+ const OPERATOR_BTWE = 'btwe';
+ const OPERATOR_LIKE = 'like';
+ const OPERATOR_NLIKE = 'nlike';
+ const OPERATOR_RLIKE = 'rlike';
+ const OPERATOR_LLIKE = 'llike';
+ const OPERATOR_ISNULL = 'isNull';
+ const OPERATOR_ISNOTNULL = 'isNotNull';
+
+ /**
+ * Align
+ */
+ const ALIGN_LEFT = 'left';
+ const ALIGN_RIGHT = 'right';
+ const ALIGN_CENTER = 'center';
+
+ protected static $aligns = array(
+ self::ALIGN_LEFT,
+ self::ALIGN_RIGHT,
+ self::ALIGN_CENTER,
+ );
+
+ /**
+ * Internal parameters
+ */
+ protected $id;
+ protected $title;
+ protected $sortable;
+ protected $filterable;
+ protected $visible;
+ protected $callback;
+ protected $order = '';
+ protected $size;
+ protected $visibleForSource;
+ protected $primary;
+ protected $align;
+ protected $inputType;
+ protected $field;
+ protected $role;
+
+ protected $filterType;
+ protected $filter;
+
+ protected $params;
+ protected $isSorted = false;
+ protected $orderUrl;
+
+ /**
+ * @var \Symfony\Component\Security\Core\SecurityContextInterface
+ */
+ protected $securityContext;
+
+ protected $data;
+
+ protected $operatorsVisible = true;
+
+ protected $operators = array();
+
+ protected $defaultOperator = true;
+
+ protected $dataJunction = self::DATA_CONJUNCTION;
+
+ protected $values = array();
+
+ protected $selectFrom;
+
+ /**
+ * Default Column constructor
+ *
+ * @param array $params
+ */
+ public function __construct($params = null)
+ {
+ $this->__initialize((array) $params);
+ }
+
+ public function __initialize(array $params)
+ {
+ $this->params = $params;
+ $this->setId($this->getParam('id'));
+ $this->setTitle($this->getParam('title', ''));
+ $this->setSortable($this->getParam('sortable', true));
+ $this->setVisible($this->getParam('visible', true));
+ $this->setSize($this->getParam('size', -1));
+ $this->setFilterable($this->getParam('filterable', true));
+ $this->setVisibleForSource($this->getParam('source', false));
+ $this->setPrimary($this->getParam('primary', false));
+ $this->setAlign($this->getParam('align', self::ALIGN_LEFT));
+ $this->setInputType($this->getParam('inputType', 'text'));
+ $this->setField($this->getParam('field'));
+ $this->setRole($this->getParam('role'));
+ $this->setOrder($this->getParam('order'));
+ $this->setFilterType($this->getParam('filter', 'input'));
+ $this->setSelectFrom($this->getParam('selectFrom', 'query'));
+ $this->setValues($this->getParam('values', array()));
+ $this->setOperatorsVisible($this->getParam('operatorsVisible', true));
+ // Order is important for the order display
+ $this->setOperators($this->getParam('operators', array(
+ self::OPERATOR_EQ,
+ self::OPERATOR_NEQ,
+ self::OPERATOR_LT,
+ self::OPERATOR_LTE,
+ self::OPERATOR_GT,
+ self::OPERATOR_GTE,
+ self::OPERATOR_BTW,
+ self::OPERATOR_BTWE,
+ self::OPERATOR_LIKE,
+ self::OPERATOR_NLIKE,
+ self::OPERATOR_RLIKE,
+ self::OPERATOR_LLIKE,
+ self::OPERATOR_ISNULL,
+ self::OPERATOR_ISNOTNULL,
+ )));
+ $this->setDefaultOperator($this->getParam('defaultOperator', self::OPERATOR_LIKE));
+ }
+
+ protected function getParam($id, $default = null)
+ {
+ return isset($this->params[$id]) ? $this->params[$id] : $default;
+ }
+
+ /**
+ * Draw cell
+ *
+ * @param string $value
+ * @param Row $row
+ * @param $router
+ * @return string
+ */
+ public function renderCell($value, $row, $router)
+ {
+ if (is_callable($this->callback)) {
+ return call_user_func($this->callback, $value, $row, $router);
+ }
+
+ if (key_exists((string)$value, $this->values)) {
+ $value = $this->values[$value];
+ }
+
+ return $value;
+ }
+
+ /**
+ * Set column callback
+ *
+ * @param $callback
+ * @return self
+ */
+ public function manipulateRenderCell($callback)
+ {
+ $this->callback = $callback;
+
+ return $this;
+ }
+
+ /**
+ * Set column identifier
+ *
+ * @param $id
+ * @return self
+ */
+ public function setId($id)
+ {
+ $this->id = $id;
+
+ return $this;
+ }
+
+ /**
+ * get column identifier
+ *
+ * @return int|string
+ */
+ public function getId()
+ {
+ return $this->id;
+ }
+
+ /**
+ * get column render block identifier
+ *
+ * @return int|string
+ */
+ public function getRenderBlockId()
+ {
+ // For Mapping fields and aggregate dql functions
+ return str_replace(array('.', ':'), '_', $this->id);
+ }
+
+ /**
+ * Set column title
+ *
+ * @param string $title
+ * @return \APY\DataGridBundle\Grid\Column\Column
+ */
+ public function setTitle($title)
+ {
+ $this->title = $title;
+
+ return $this;
+ }
+
+ /**
+ * Get column title
+ *
+ * @return string
+ */
+ public function getTitle()
+ {
+ return $this->title;
+ }
+
+
+ /**
+ * Set column visibility
+ *
+ * @param boolean $visible
+ */
+ public function setVisible($visible)
+ {
+ $this->visible = $visible;
+
+ return $this;
+ }
+
+ /**
+ * Return column visibility
+ *
+ * @return bool return true when column is visible
+ */
+ public function isVisible()
+ {
+ if ($this->visible && $this->securityContext !== null && $this->getRole() != null) {
+ return $this->securityContext->isGranted($this->getRole());
+ }
+
+ return $this->visible;
+ }
+
+ /**
+ * Return true if column is sorted
+ *
+ * @return bool return true when column is sorted
+ */
+ public function isSorted()
+ {
+ return $this->isSorted;
+ }
+
+ public function setSortable($sortable)
+ {
+ $this->sortable = $sortable;
+
+ return $this;
+ }
+
+ /**
+ * column ability to sort
+ *
+ * @return bool return true when column can be sorted
+ */
+ public function isSortable()
+ {
+ return $this->sortable;
+ }
+
+ /**
+ * Return true if column is filtered
+ *
+ * @return boolean return true when column is filtered
+ */
+ public function isFiltered()
+ {
+ return ( (isset($this->data['from']) && $this->isQueryValid($this->data['from']) && $this->data['from'] != static::DEFAULT_VALUE)
+ || (isset($this->data['to']) && $this->isQueryValid($this->data['to']) && $this->data['to'] != static::DEFAULT_VALUE)
+ || (isset($this->data['operator']) && ($this->data['operator'] === self::OPERATOR_ISNULL || $this->data['operator'] === self::OPERATOR_ISNOTNULL)) );
+ }
+
+ public function setFilterable($filterable)
+ {
+ $this->filterable = $filterable;
+
+ return $this;
+ }
+
+ /**
+ * column ability to filter
+ *
+ * @return bool return true when column can be filtred
+ */
+ public function isFilterable()
+ {
+ return $this->filterable;
+ }
+
+ /**
+ * set column order
+ *
+ * @param string $order asc|desc
+ * @return \APY\DataGridBundle\Grid\Column\Column
+ */
+ public function setOrder($order)
+ {
+ if ($order !== null) {
+ $this->order = $order;
+ $this->isSorted = true;
+ }
+
+ return $this;
+ }
+
+ /**
+ * get column order
+ *
+ * @return string asc|desc
+ */
+ public function getOrder()
+ {
+ return $this->order;
+ }
+
+ /**
+ * Set column width
+ *
+ * @param int $size in pixels
+ * @return \APY\DataGridBundle\Grid\Column\Column
+ */
+ public function setSize($size)
+ {
+ if ($size < -1) {
+ throw new \InvalidArgumentException(sprintf('Unsupported column size %s, use positive value or -1 for auto resize', $size));
+ }
+
+ $this->size = $size;
+
+ return $this;
+ }
+
+ /**
+ * get column width
+ *
+ * @return int column width in pixels
+ */
+ public function getSize()
+ {
+ return $this->size;
+ }
+
+ public function setOrderUrl($orderUrl)
+ {
+ $this->orderUrl = $orderUrl;
+
+ return $this;
+ }
+
+ public function getOrderUrl()
+ {
+ return $this->orderUrl;
+ }
+
+ /**
+ * set filter data from session | request
+ *
+ * @param $data
+ * @return \APY\DataGridBundle\Grid\Column\Column
+ */
+ public function setData($data)
+ {
+ $this->data = array('operator' => $this->getDefaultOperator(), 'from' => static::DEFAULT_VALUE, 'to' => static::DEFAULT_VALUE);
+
+ $hasValue = false;
+ if (isset($data['from']) && $this->isQueryValid($data['from'])) {
+ $this->data['from'] = $data['from'];
+ $hasValue = true;
+ }
+
+ if (isset($data['to']) && $this->isQueryValid($data['to'])) {
+ $this->data['to'] = $data['to'];
+ $hasValue = true;
+ }
+
+ $isNullOperator = (isset($data['operator']) && ($data['operator'] === self::OPERATOR_ISNULL || $data['operator'] === self::OPERATOR_ISNOTNULL) );
+ if (($hasValue || $isNullOperator) && isset($data['operator']) && $this->hasOperator($data['operator'])) {
+ $this->data['operator'] = $data['operator'];
+ }
+
+ return $this;
+ }
+
+ /**
+ * get filter data from session | request
+ *
+ * @return array data
+ */
+ public function getData()
+ {
+ $result = array();
+
+ $hasValue = false;
+ if ($this->data['from'] != $this::DEFAULT_VALUE) {
+ $result['from'] = $this->data['from'];
+ $hasValue = true;
+ }
+
+ if ($this->data['to'] != $this::DEFAULT_VALUE) {
+ $result['to'] = $this->data['to'];
+ $hasValue = true;
+ }
+
+ $isNullOperator = (isset($this->data['operator']) && ($this->data['operator'] === self::OPERATOR_ISNULL || $this->data['operator'] === self::OPERATOR_ISNOTNULL) );
+ if ($hasValue || $isNullOperator) {
+ $result['operator'] = $this->data['operator'];
+ }
+
+ return $result;
+ }
+
+ /**
+ * Return true if filter value is correct (has to be overridden in each Column class that can be filtered, in order to catch wrong values)
+ *
+ * @return boolean
+ */
+ public function isQueryValid($query)
+ {
+ return true;
+ }
+
+ /**
+ * Set column visibility for source class
+ * @param $value
+ * @return \APY\DataGridBundle\Grid\Column\Column