Author: Jonathan.Wage
Date: 2010-02-02 23:21:07 +0100 (Tue, 02 Feb 2010)
New Revision: 27458
Modified:
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalContentListPlugin/lib/model/doctrine/PluginsfSympalContentList.class.php
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalDataGridPlugin/lib/sfSympalDataGrid.class.php
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalPagesPlugin/lib/model/doctrine/PluginsfSympalPageTable.class.php
Log:
[1.4][sfSympalPlugin][1.0] Enhancing data grid to remember the sort, order and
page in session.
Modified:
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalContentListPlugin/lib/model/doctrine/PluginsfSympalContentList.class.php
===================================================================
---
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalContentListPlugin/lib/model/doctrine/PluginsfSympalContentList.class.php
2010-02-02 21:34:06 UTC (rev 27457)
+++
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalContentListPlugin/lib/model/doctrine/PluginsfSympalContentList.class.php
2010-02-02 22:21:07 UTC (rev 27458)
@@ -32,17 +32,16 @@
if ($this->sort_column)
{
- $dataGrid->setSort($this->sort_column);
+ $dataGrid->setDefaultSort($this->sort_column);
if ($this->sort_order)
{
- $dataGrid->setOrder($this->sort_order);
+ $dataGrid->setDefaultSort($this->sort_order);
}
}
$dataGrid->setMaxPerPage(($this->rows_per_page > 0 ? $this->rows_per_page
: sfSympalConfig::get('rows_per_page', null, 10)));
$dataGridRequestInfo = $request->getParameter($dataGrid->getId());
- $dataGrid->setPage(isset($dataGridRequestInfo['page']) ?
$dataGridRequestInfo['page'] : 1);
$dataGrid->init();
return $dataGrid;
Modified:
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalDataGridPlugin/lib/sfSympalDataGrid.class.php
===================================================================
---
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalDataGridPlugin/lib/sfSympalDataGrid.class.php
2010-02-02 21:34:06 UTC (rev 27457)
+++
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalDataGridPlugin/lib/sfSympalDataGrid.class.php
2010-02-02 22:21:07 UTC (rev 27458)
@@ -48,6 +48,11 @@
throw new Doctrine_Exception('First argument should be either the name
of a model or an existing Doctrine_Query object');
}
$this->_table = Doctrine_Core::getTable($this->_modelName);
+
+ if (!self::$_symfonyContext)
+ {
+ throw new sfException('In order to use the Sympal data grid you must set
the Symfony context to use with setSymfonyContext()');
+ }
}
public static function setSymfonyContext(sfContext $symfonyContext)
@@ -61,6 +66,16 @@
return $dataGrid;
}
+ public function getFromSession($key)
+ {
+ return self::$_symfonyContext->getUser()->getAttribute($key, null,
$this->getId());
+ }
+
+ public function setToSession($key, $value)
+ {
+ return self::$_symfonyContext->getUser()->setAttribute($key, $value,
$this->getId());
+ }
+
public function isSortable($bool = null)
{
if ($bool !== null)
@@ -71,9 +86,20 @@
return $this->_isSortable;
}
+ public function setDefaultSort($sort, $order = null)
+ {
+ $this->_sort = $sort;
+ if ($order)
+ {
+ $this->_order = $order;
+ }
+ return $this;
+ }
+
public function setSort($sort, $order = null)
{
$this->_sort = $sort;
+ $this->setToSession('sort', $this->_sort);
if ($order)
{
$this->setOrder($order);
@@ -89,9 +115,23 @@
public function setOrder($order)
{
$this->_order = strtolower($order);
+ $this->setToSession('order', $this->_order);
return $this;
}
+ public function setDefaultOrder($order)
+ {
+ $this->_order = strtolower($order);
+ return $this;
+ }
+
+ public function setPage($page)
+ {
+ $this->setToSession('page', $page);
+ $this->_pager->setPage($page);
+ return $this;
+ }
+
public function getOrder()
{
return $this->_order;
@@ -333,6 +373,7 @@
$this->_query->getSqlQuery(array(), false);
$this->_pager->init();
+
if (!$this->_columns)
{
$this->_populateDefaultColumns();
@@ -340,29 +381,52 @@
$this->_initializeColumns();
}
- $request = self::$_symfonyContext->getRequest();
+ $this->_initializeSortingAndPaging();
- $dataGridRequestInfo = $request->getParameter($this->getId());
- if (isset($dataGridRequestInfo['sort']) && $sort =
$dataGridRequestInfo['sort'])
+ $this->_initialized = true;
+
+ return $this;
+ }
+
+ public function getRecordColumnValue($record, $column)
+ {
+ $current = $record;
+ if (isset($column['dqlAlias']) &&
isset($this->_parents[$column['dqlAlias']]))
{
- $this->_sort = $sort;
+ foreach ($this->_parents[$column['dqlAlias']] as $parent)
+ {
+ if (isset($current[$parent]))
+ {
+ $current = $current[$parent];
+ }
+ }
}
- if (isset($dataGridRequestInfo['order']) && $order =
$dataGridRequestInfo['order'])
+ return $current[$column['fieldName']];
+ }
+
+ public function getSymfonyResource($module, $action = null, $variables =
array())
+ {
+ if (strpos($module, '/'))
{
- $this->_order = $order;
+ $variables = (array) $action;
+ $e = explode('/', $module);
+ list($module, $action) = $e;
}
- if ($this->_sort)
+ self::$_symfonyContext->getConfiguration()->loadHelpers('Partial');
+ $controller = self::$_symfonyContext->getController();
+
+ if ($controller->componentExists($module, $action))
{
- $this->_query->addOrderBy($this->_sort.(isset($this->_order) ? '
'.$this->_order : null));
+ return get_component($module, $action, $variables);
+ } else {
+ return get_partial($module.'/'.$action, $variables);
}
- $this->_initialized = true;
-
- return $this;
+ throw new sfException('Could not find component or partial for the module
"'.$module.'" and action "'.$action.'"');
}
- private function _initializeColumns()
+ protected function _initializeColumns()
{
foreach ($this->_columns as $name => $options)
{
@@ -414,7 +478,7 @@
}
}
- private function _populateDefaultColumns()
+ protected function _populateDefaultColumns()
{
$rootAlias = $this->_query->getRootAlias();
$this->_columns = array();
@@ -428,42 +492,49 @@
}
}
- public function getRecordColumnValue($record, $column)
+ protected function _populateFromSession()
{
- $current = $record;
- if (isset($column['dqlAlias']) &&
isset($this->_parents[$column['dqlAlias']]))
+ if ($sort = $this->getFromSession('sort'))
{
- foreach ($this->_parents[$column['dqlAlias']] as $parent)
- {
- if (isset($current[$parent]))
- {
- $current = $current[$parent];
- }
- }
+ $this->setSort($sort);
}
- return $current[$column['fieldName']];
+
+ if ($order = $this->getFromSession('order'))
+ {
+ $this->setOrder($order);
+ }
+
+ if ($page = $this->getFromSession('page'))
+ {
+ $this->setPage($page);
+ }
}
- public function getSymfonyResource($module, $action = null, $variables =
array())
+ protected function _initializeSortingAndPaging()
{
- if (strpos($module, '/'))
+ $request = self::$_symfonyContext->getRequest();
+
+ $dataGridRequestInfo = $request->getParameter($this->getId());
+ if (isset($dataGridRequestInfo['sort']) && $sort =
$dataGridRequestInfo['sort'])
{
- $variables = (array) $action;
- $e = explode('/', $module);
- list($module, $action) = $e;
+ $this->setSort($sort);
}
+ if (isset($dataGridRequestInfo['order']) && $order =
$dataGridRequestInfo['order'])
+ {
+ $this->setOrder($order);
+ }
- self::$_symfonyContext->getConfiguration()->loadHelpers('Partial');
- $controller = self::$_symfonyContext->getController();
+ if (isset($dataGridRequestInfo['page']) && $dataGridRequestInfo['page'])
+ {
+ $this->setPage($dataGridRequestInfo['page']);
+ }
- if ($controller->componentExists($module, $action))
+ $this->_populateFromSession();
+
+ if ($this->_sort)
{
- return get_component($module, $action, $variables);
- } else {
- return get_partial($module.'/'.$action, $variables);
+ $this->_query->addOrderBy($this->_sort.(isset($this->_order) ? '
'.$this->_order : null));
}
-
- throw new sfException('Could not find component or partial for the module
"'.$module.'" and action "'.$action.'"');
}
public function __call($method, $arguments)
Modified:
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalPagesPlugin/lib/model/doctrine/PluginsfSympalPageTable.class.php
===================================================================
---
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalPagesPlugin/lib/model/doctrine/PluginsfSympalPageTable.class.php
2010-02-02 21:34:06 UTC (rev 27457)
+++
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalPagesPlugin/lib/model/doctrine/PluginsfSympalPageTable.class.php
2010-02-02 22:21:07 UTC (rev 27458)
@@ -16,14 +16,14 @@
->addColumn('crt.title', 'renderer=sympal_page/data_grid_title')
->addColumn('c.date_published')
->addColumn('u.username', 'label=Created By')
- ->setSort('crt.title');
+ ->setDefaultSort('crt.title');
} else {
return $dataGrid
->addColumn('cr.title', 'renderer=sympal_page/data_grid_title')
->addColumn('c.date_published')
->addColumn('u.username', 'label=Created By')
- ->setSort('cr.title');
+ ->setDefaultSort('cr.title');
}
}
}
\ No newline at end of file
--
You received this message because you are subscribed to the Google Groups
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/symfony-svn?hl=en.