Author: Leon.van.der.Ree
Date: 2010-03-25 00:41:39 +0100 (Thu, 25 Mar 2010)
New Revision: 28773

Added:
   plugins/sfGridPlugin/trunk/lib/grid/formatter/json/
   
plugins/sfGridPlugin/trunk/lib/grid/formatter/json/sfGridFormatterJson.class.php
   
plugins/sfGridPlugin/trunk/lib/grid/formatter/json/sfGridFormatterJsonRow.class.php
   
plugins/sfGridPlugin/trunk/lib/grid/formatter/sfGridFormatterDynamic.class.php
   
plugins/sfGridPlugin/trunk/lib/grid/formatter/sfGridFormatterDynamicRow.class.php
   plugins/sfGridPlugin/trunk/lib/grid/formatter/sfGridFormatterInterface.php
   plugins/sfGridPlugin/trunk/lib/grid/formatter/sfGridFormatterRowInterface.php
   plugins/sfGridPlugin/trunk/lib/grid/sfWebGridJavaScript.class.php
Removed:
   
plugins/sfGridPlugin/trunk/lib/grid/formatter/sfGridFormatterInterface.class.php
Modified:
   
plugins/sfGridPlugin/trunk/lib/grid/formatter/html/sfGridFormatterHtml.class.php
   
plugins/sfGridPlugin/trunk/lib/grid/formatter/html/sfGridFormatterHtmlRow.class.php
   
plugins/sfGridPlugin/trunk/lib/grid/formatter/text/sfGridFormatterText.class.php
   
plugins/sfGridPlugin/trunk/lib/grid/formatter/text/sfGridFormatterTextRow.class.php
   plugins/sfGridPlugin/trunk/lib/grid/sfGrid.class.php
   plugins/sfGridPlugin/trunk/test/unit/grid/sfGridTest.php
   plugins/sfGridPlugin/trunk/test/unit/mock/sfGridFormatterMock.class.php
Log:
updated formatters and interfaces

Modified: 
plugins/sfGridPlugin/trunk/lib/grid/formatter/html/sfGridFormatterHtml.class.php
===================================================================
--- 
plugins/sfGridPlugin/trunk/lib/grid/formatter/html/sfGridFormatterHtml.class.php
    2010-03-24 22:27:44 UTC (rev 28772)
+++ 
plugins/sfGridPlugin/trunk/lib/grid/formatter/html/sfGridFormatterHtml.class.php
    2010-03-24 23:41:39 UTC (rev 28773)
@@ -9,7 +9,7 @@
  * file that was distributed with this source code.
  */
 
-class sfGridFormatterHtml implements sfGridFormatterInterface
+class sfGridFormatterHtml extends sfGridFormatterDynamic
 {
   const FIRST = "|«";
   const PREV  = "«";
@@ -19,21 +19,7 @@
   const SORT_ASC  = 'sort_asc';
   const SORT_DESC = 'sort_desc';
 
-  /**
-   * @var sfGrid
-   */
-  protected $grid = null;
-
-  /**
-   * The row formatter
-   *
-   * @var sfGridFormatterHtmlRow
-   */
-  protected
-    $row        = null;
-    
   protected    
-    $cursor     = 0,
     $uri        = null,
     $sortable   = array(),
     $sortClass  = array(sfGrid::ASC  => self::SORT_ASC ,
@@ -48,14 +34,19 @@
     }
     return implode("\n", $lines);
   }
-
+  
+  /**
+   * constructor of a Grid Formatter
+   * 
+   * @param sfGrid $grid
+   */
   public function __construct(sfGrid $grid)
   {
-    $this->grid = $grid;
+    parent::__construct($grid);
 
     $this->row = new sfGridFormatterHtmlRow($grid, 0);
   }
-  
+
   /**
    * Sets the css classes used for the actively sorted column
    *
@@ -104,6 +95,11 @@
     return $this->renderHead().$this->renderFoot().$this->renderBody();
   }
 
+  /**
+   * Renders the Head of the grid
+   * 
+   * @return string
+   */  
   public function renderHead()
   {
     $html = "<thead>\n<tr>\n";
@@ -116,6 +112,11 @@
     return $html . "</tr>\n</thead>\n";
   }
 
+  /**
+   * renders the pager for this grid
+   * 
+   * @return string
+   */
   public function renderPager()
   {
     sfProjectConfiguration::getActive()->loadHelpers(array('Url'));
@@ -161,6 +162,11 @@
     return $html . "</div>\n";
   }
 
+  /**
+   * Renders the Footer of the grid
+   * 
+   * @return string
+   */
   public function renderFoot()
   {
     $pager = $this->grid->getPager();
@@ -181,7 +187,12 @@
 
     return $html."\n  </th>\n</tr>\n</tfoot>\n";
   }
-
+  
+  /**
+   * Renders the Body of the grid
+   * 
+   * @return string
+   */
   public function renderBody()
   {
     $html = "<tbody>\n";
@@ -202,7 +213,7 @@
   }
 
   /**
-   * Enter description here...
+   * Renders the ColumnHead for the grid
    *
    * @param string $column
    * @return string html formatted string
@@ -253,56 +264,6 @@
     return tag('th', $arrOptions, true).$html.'</th>';
   }
 
-  public function current()
-  {
-    $this->row->initialize($this->grid, $this->cursor);
 
-    return $this->row;
-  }
-
-  public function next()
-  {
-    ++$this->cursor;
-  }
-
-  public function key()
-  {
-    return $this->cursor;
-  }
-
-  public function rewind()
-  {
-    $this->cursor = 0;
-  }
-
-  public function valid()
-  {
-    return $this->cursor < count($this);
-  }
-
-  public function count()
-  {
-    return count($this->grid);
-  }
-
-//  TODO: this can be removed?! using the url_for method from symfony...
-//  static public function makeUri($uri, array $params)
-//  {
-//    // split the uri
-//    $uri = explode('?', $uri);
-//
-//    // extract the query string
-//    $values = array();
-//    if (count($uri) > 1)
-//    {
-//      $query = explode('#', $uri[1]);
-//      parse_str($query[0], $values);
-//    }
-//    $params = array_merge($values, $params);
-//
-//    // build the new uri
-////    return $uri[0] . '?' . http_build_query($params, '', '&');
-//    return url_for($module_action . '?' . http_build_query($params, '', 
'&'));
-//  }
 }
 

Modified: 
plugins/sfGridPlugin/trunk/lib/grid/formatter/html/sfGridFormatterHtmlRow.class.php
===================================================================
--- 
plugins/sfGridPlugin/trunk/lib/grid/formatter/html/sfGridFormatterHtmlRow.class.php
 2010-03-24 22:27:44 UTC (rev 28772)
+++ 
plugins/sfGridPlugin/trunk/lib/grid/formatter/html/sfGridFormatterHtmlRow.class.php
 2010-03-24 23:41:39 UTC (rev 28773)
@@ -14,14 +14,11 @@
  * A formatter that renders the HTML of a row
  *
  */
-class sfGridFormatterHtmlRow implements ArrayAccess
+class sfGridFormatterHtmlRow extends sfGridFormatterDynamicRow
 {
   const NO_RESULTS_MESSAGE = 'no results';
   
-  protected
-    $grid             = null,
-    $index            = null,
-    $noResultsMessage;
+  protected $noResultsMessage;
 
   protected $highlightCondition = array();
 
@@ -46,8 +43,8 @@
    */  
   public function initialize(sfGrid $grid, $index, $noResultsMessage = 
self::NO_RESULTS_MESSAGE)
   {
-    $this->grid = $grid;
-    $this->index = $index;
+    parent::initialize($grid, $index);
+    
     $this->noResultsMessage = $noResultsMessage; 
   }
 
@@ -62,16 +59,6 @@
   }
 
   /**
-   * Returns the internal row pointer
-   *
-   * @return int
-   */
-  public function getIndex()
-  {
-    return $this->index;
-  }
-
-  /**
    * Renders a row to html
    *
    * @return string
@@ -167,27 +154,4 @@
       'class'  => $class,
     );
   }
-
-  public function offsetGet($key)
-  {
-    $source = $this->grid->getDataSource();
-    $source->seek($this->index);
-
-    return $source[$key];
-  }
-
-  public function offsetSet($key, $value)
-  {
-    throw new LogicException('Modification of fields is not allowed');
-  }
-
-  public function offsetExists($key)
-  {
-    return $this->grid->hasColumn($key);
-  }
-
-  public function offsetUnset($key)
-  {
-    throw new LogicException('Modification of fields is not allowed');
-  }
 }
\ No newline at end of file

Added: 
plugins/sfGridPlugin/trunk/lib/grid/formatter/json/sfGridFormatterJson.class.php
===================================================================
--- 
plugins/sfGridPlugin/trunk/lib/grid/formatter/json/sfGridFormatterJson.class.php
                            (rev 0)
+++ 
plugins/sfGridPlugin/trunk/lib/grid/formatter/json/sfGridFormatterJson.class.php
    2010-03-24 23:41:39 UTC (rev 28773)
@@ -0,0 +1,53 @@
+<?php
+
+/*
+ * This file is part of the symfony package.
+ * Leon van der Ree <[email protected]> 
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+class sfGridFormatterJson extends sfGridFormatterDynamic
+
+{
+  /**
+   * constructor of a Grid Formatter
+   * 
+   * @param sfGrid $grid
+   */
+  public function __construct(sfGrid $grid)
+  {
+    parent::__construct($grid);
+
+    $this->row = new sfGridFormatterJsonRow($grid, 0);
+  }
+  
+  /**
+   * Renders the row in HTML
+   *
+   * @return string
+   */
+  public function render()
+  {
+    $arrJson = array();
+
+    $arrJson['totalCount'] = $this->grid->getPager()->getRecordCount();
+    $arrJson['data'] = $this->getData();
+
+    return json_encode($arrJson);
+  }
+
+
+  public function getData()
+  {
+    $arrJson = array();
+    foreach ($this as $row)
+    {
+      $arrJson[] = $row->render();
+    }
+
+    return $arrJson;
+  }
+
+}
+


Property changes on: 
plugins/sfGridPlugin/trunk/lib/grid/formatter/json/sfGridFormatterJson.class.php
___________________________________________________________________
Added: svn:executable
   + *

Added: 
plugins/sfGridPlugin/trunk/lib/grid/formatter/json/sfGridFormatterJsonRow.class.php
===================================================================
--- 
plugins/sfGridPlugin/trunk/lib/grid/formatter/json/sfGridFormatterJsonRow.class.php
                         (rev 0)
+++ 
plugins/sfGridPlugin/trunk/lib/grid/formatter/json/sfGridFormatterJsonRow.class.php
 2010-03-24 23:41:39 UTC (rev 28773)
@@ -0,0 +1,47 @@
+<?php
+
+/*
+ * This file is part of the symfony package.
+ * Leon van der Ree <[email protected]> 
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * A formatter that renders a row as JSON
+ *
+ */
+class sfGridFormatterJsonRow extends sfGridFormatterDynamicRow
+{
+
+  /**
+   * Returns the associated grid
+   *
+   * @return sfGrid
+   */
+  public function getGrid()
+  {
+    return $this->grid;
+  }
+
+  /**
+   * Renders a row to an array
+   *
+   * @return string
+   */
+  public function render()
+  {
+    $source = $this->grid->getDataSource();
+    $source->seek($this->index);
+
+    $arrData = array();
+    foreach ($this->grid->getWidgets() as $column => $widget)
+    {
+      $arrData[$column] = $widget->render($column, $source[$column]);
+    }
+
+    return $arrData;
+  }
+
+}
\ No newline at end of file


Property changes on: 
plugins/sfGridPlugin/trunk/lib/grid/formatter/json/sfGridFormatterJsonRow.class.php
___________________________________________________________________
Added: svn:executable
   + *

Added: 
plugins/sfGridPlugin/trunk/lib/grid/formatter/sfGridFormatterDynamic.class.php
===================================================================
--- 
plugins/sfGridPlugin/trunk/lib/grid/formatter/sfGridFormatterDynamic.class.php  
                            (rev 0)
+++ 
plugins/sfGridPlugin/trunk/lib/grid/formatter/sfGridFormatterDynamic.class.php  
    2010-03-24 23:41:39 UTC (rev 28773)
@@ -0,0 +1,84 @@
+<?php
+/*
+ * This file is part of the symfony package.
+ * (c) Bernhard Schussek <[email protected]>
+ * Leon van der Ree <[email protected]> 
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * This abstract class contains basic functionality about how to iterate 
+ * over the rows in your DataSource, to render the grid (into text, html, 
json, xml, etc).
+ *
+ */
+abstract class sfGridFormatterDynamic implements sfGridFormatterInterface, 
Iterator, Countable
+{
+  /**
+   * The row formatter
+   *
+   * @var sfGridFormatter * Row // TODO: define a rowFormatterInterface
+   */
+  protected
+    $row        = null;
+
+  /**
+   * @var sfGrid
+   */
+  protected $grid = null;
+
+  /**
+   * the row-cursor
+   * 
+   * @var int
+   */
+  protected    
+    $cursor     = 0;
+    
+    
+  /**
+   * constructor of a Grid Formatter
+   * 
+   * @param sfGrid $grid
+   */
+  public function __construct(sfGrid $grid)
+  {
+    $this->grid = $grid;
+
+//    $this->row = new sfGridFormatter * Row($grid, 0);
+  }
+    
+
+  public function current()
+  {
+    $this->row->initialize($this->grid, $this->cursor);
+
+    return $this->row;
+  }
+
+  public function next()
+  {
+    ++$this->cursor;
+  }
+
+  public function key()
+  {
+    return $this->cursor;
+  }
+
+  public function rewind()
+  {
+    $this->cursor = 0;
+  }
+
+  public function valid()
+  {
+    return $this->cursor < count($this);
+  }
+
+  public function count()
+  {
+    return count($this->grid);
+  }  
+}
\ No newline at end of file

Added: 
plugins/sfGridPlugin/trunk/lib/grid/formatter/sfGridFormatterDynamicRow.class.php
===================================================================
--- 
plugins/sfGridPlugin/trunk/lib/grid/formatter/sfGridFormatterDynamicRow.class.php
                           (rev 0)
+++ 
plugins/sfGridPlugin/trunk/lib/grid/formatter/sfGridFormatterDynamicRow.class.php
   2010-03-24 23:41:39 UTC (rev 28773)
@@ -0,0 +1,77 @@
+<?php
+/*
+ * This file is part of the symfony package.
+ * (c) Bernhard Schussek <[email protected]>
+ * Leon van der Ree <[email protected]> 
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * This abstract class contains basic functionality about how to iterate 
+ * over the rows in your DataSource, to render the grid (into text, html, 
json, xml, etc).
+ *
+ */
+abstract class sfGridFormatterDynamicRow implements sfGridFormatterRowInterface
+{
+  protected
+    $grid             = null,
+    $index            = null;
+
+  /**
+   * Constructs a new sfGridFormatter Row to render rows
+   *
+   * @param sfGrid $grid  the grid that this row-formatter should render
+   * @param int $index    The index to which to set the internal row pointer
+   */
+  public function __construct(sfGrid $grid, $index)
+  {
+    $this->initialize($grid, $index);
+  }
+
+  /**
+   * Initialises the new sfGridFormatter Row 
+   *
+   * @param sfGrid $grid  the grid that this row-formatter should render
+   * @param int $index    The index to which to set the internal row pointer
+   */  
+  public function initialize(sfGrid $grid, $index)
+  {
+    $this->grid = $grid;
+    $this->index = $index;
+  }  
+  
+  /**
+   * Returns the internal row pointer
+   *
+   * @return int
+   */
+  public function getIndex()
+  {
+    return $this->index;
+  }
+  
+  public function offsetGet($key)
+  {
+    $source = $this->grid->getDataSource();
+    $source->seek($this->index);
+
+    return $source[$key];
+  }
+
+  public function offsetSet($key, $value)
+  {
+    throw new LogicException('Modification of fields is not allowed');
+  }
+
+  public function offsetExists($key)
+  {
+    return $this->grid->hasColumn($key);
+  }
+
+  public function offsetUnset($key)
+  {
+    throw new LogicException('Modification of fields is not allowed');
+  }
+}
\ No newline at end of file

Deleted: 
plugins/sfGridPlugin/trunk/lib/grid/formatter/sfGridFormatterInterface.class.php
===================================================================
--- 
plugins/sfGridPlugin/trunk/lib/grid/formatter/sfGridFormatterInterface.class.php
    2010-03-24 22:27:44 UTC (rev 28772)
+++ 
plugins/sfGridPlugin/trunk/lib/grid/formatter/sfGridFormatterInterface.class.php
    2010-03-24 23:41:39 UTC (rev 28773)
@@ -1,22 +0,0 @@
-<?php
-
-/*
- * This file is part of the symfony package.
- * (c) Bernhard Schussek <[email protected]>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-interface sfGridFormatterInterface extends Iterator, Countable
-{
-  public function render();
-  
-  public function renderHead();
-  
-  public function renderFoot();
-  
-  public function renderBody();
-  
-  public function renderColumnHead($column);
-}
\ No newline at end of file

Added: 
plugins/sfGridPlugin/trunk/lib/grid/formatter/sfGridFormatterInterface.php
===================================================================
--- plugins/sfGridPlugin/trunk/lib/grid/formatter/sfGridFormatterInterface.php  
                        (rev 0)
+++ plugins/sfGridPlugin/trunk/lib/grid/formatter/sfGridFormatterInterface.php  
2010-03-24 23:41:39 UTC (rev 28773)
@@ -0,0 +1,35 @@
+<?php
+
+/*
+ * This file is part of the symfony package.
+ * (c) Bernhard Schussek <[email protected]>
+ * (c) Leon van der Ree <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * This interface is used to render Grids
+ * 
+ * This can be for dynamic renders, like html, text, json, xml, etc-renderers
+ * or static renders, for example for unobtrusive JavaScript (that won't rely 
on the grid-data-content) 
+ *
+ */
+interface sfGridFormatterInterface
+{
+  /**
+   * constructor of a Grid Formatter
+   * 
+   * @param sfGrid $grid
+   */
+  public function __construct(sfGrid $grid);
+  
+  /**
+   * Renders the grid
+   * 
+   * @return string
+   */
+  public function render();
+  
+}
\ No newline at end of file

Added: 
plugins/sfGridPlugin/trunk/lib/grid/formatter/sfGridFormatterRowInterface.php
===================================================================
--- 
plugins/sfGridPlugin/trunk/lib/grid/formatter/sfGridFormatterRowInterface.php   
                            (rev 0)
+++ 
plugins/sfGridPlugin/trunk/lib/grid/formatter/sfGridFormatterRowInterface.php   
    2010-03-24 23:41:39 UTC (rev 28773)
@@ -0,0 +1,40 @@
+<?php
+
+/*
+ * This file is part of the symfony package.
+ * (c) Bernhard Schussek <[email protected]>
+ * (c) Leon van der Ree <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * This interface is used to render rows of a Grid
+ * 
+ */
+interface sfGridFormatterRowInterface extends ArrayAccess
+{
+/**
+   * Constructs a new sfGridFormatter * Row to render rows
+   *
+   * @param sfGrid $grid  the grid that this row-formatter should render
+   * @param int $index    The index to which to set the internal row pointer
+   */
+  public function __construct(sfGrid $grid, $index);
+
+  /**
+   * Initialises the new sfGridFormatter * Row
+   *
+   * @param sfGrid $grid  the grid that this row-formatter should render
+   * @param int $index    The index to which to set the internal row pointer
+   */
+  public function initialize(sfGrid $grid, $index);
+  
+  /**
+   * Renders the row
+   *
+   * @return string
+   */
+  public function render();
+}
\ No newline at end of file

Modified: 
plugins/sfGridPlugin/trunk/lib/grid/formatter/text/sfGridFormatterText.class.php
===================================================================
--- 
plugins/sfGridPlugin/trunk/lib/grid/formatter/text/sfGridFormatterText.class.php
    2010-03-24 22:27:44 UTC (rev 28772)
+++ 
plugins/sfGridPlugin/trunk/lib/grid/formatter/text/sfGridFormatterText.class.php
    2010-03-24 23:41:39 UTC (rev 28773)
@@ -8,7 +8,7 @@
  * file that was distributed with this source code.
  */
 
-class sfGridFormatterText implements sfGridFormatterInterface
+class sfGridFormatterText extends sfGridFormatterDynamic
 {
-  
+  // TODO, I think...
 }
\ No newline at end of file

Modified: 
plugins/sfGridPlugin/trunk/lib/grid/formatter/text/sfGridFormatterTextRow.class.php
===================================================================
--- 
plugins/sfGridPlugin/trunk/lib/grid/formatter/text/sfGridFormatterTextRow.class.php
 2010-03-24 22:27:44 UTC (rev 28772)
+++ 
plugins/sfGridPlugin/trunk/lib/grid/formatter/text/sfGridFormatterTextRow.class.php
 2010-03-24 23:41:39 UTC (rev 28773)
@@ -8,7 +8,7 @@
  * file that was distributed with this source code.
  */
 
-class sfGridFormatterTextRow implements ArrayAccess
+class sfGridFormatterTextRow extends sfGridFormatterRowInterface
 {
-  
+  // TODO: I think
 }
\ No newline at end of file

Modified: plugins/sfGridPlugin/trunk/lib/grid/sfGrid.class.php
===================================================================
--- plugins/sfGridPlugin/trunk/lib/grid/sfGrid.class.php        2010-03-24 
22:27:44 UTC (rev 28772)
+++ plugins/sfGridPlugin/trunk/lib/grid/sfGrid.class.php        2010-03-24 
23:41:39 UTC (rev 28773)
@@ -52,10 +52,23 @@
     $columnTitles = array(),
     $columnTitlesOptions = array(),
     $sortable     = array(),
-    $widgets      = array(),
-    $formatter    = null,
-    $pager        = null,
+    $widgets      = array();
+    
+  /**
+   * formatter that returns (unobtrusive) JavaScript
+   * 
+   * @var sfGridFormatterInterface
+   */
+  protected $formatter    = null;
+  
+  /**
+   * formatter that returns (unobtrusive) JavaScript
+   * 
+   * @var sfDataSourcePager
+   */
+  protected $pager        = null;
 
+  protected 
     $sortColumn   = null,
     $sortOrder    = null,
 

Added: plugins/sfGridPlugin/trunk/lib/grid/sfWebGridJavaScript.class.php
===================================================================
--- plugins/sfGridPlugin/trunk/lib/grid/sfWebGridJavaScript.class.php           
                (rev 0)
+++ plugins/sfGridPlugin/trunk/lib/grid/sfWebGridJavaScript.class.php   
2010-03-24 23:41:39 UTC (rev 28773)
@@ -0,0 +1,127 @@
+<?php
+
+/*
+ * This file is part of the symfony package.
+ * (c) Leon van der Ree <[email protected]>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * This abstract class is there as a base for your JavaScript-Grid class.
+ * You should define the JavaScript formatter in the specialised class
+ * 
+ * All JavaScript Grids "should" still render to HTML, while unobtrusive 
JavaScript should progressive enhance the intactivity of your grid,
+ * To dynamically load new content a dataFormatter can be defined to output 
JSON or XML-data.  
+ * 
+ */
+abstract class sfWebGridJavaScript extends sfWebGrid
+{
+  /**
+   * formatter to output data (json/xml)
+   * 
+   * @var sfGridFormatterInterface
+   */
+  protected $dataFormatter;
+
+  /**
+   * formatter that returns (unobtrusive) JavaScript
+   * 
+   * @var sfGridFormatterInterface
+   */
+  protected $javaScriptFormatter;
+  
+  /**
+   * This method should be implemented in your specialised GridClass, to define
+   * the dataFormatter and javaScriptFormatter
+   */
+  public function configure()
+  {
+    //set html formatter
+    parent::configure();
+    
+    // define the data formatter
+    $this->setDataFormatter(new sfGridFormatterJson($this));
+    
+    // $this->setJavaScriptFormatter(new 
sfGridFormatterYOUR_JS_FORMATTER($this));
+  }
+  
+  /**
+   * returns the DataFormatter (to format data in json/xml) 
+   * 
+   * @return sfGridFormatterInterface
+   */
+  public function getDataFormatter()
+  {
+    return $this->dataFormatter;
+  }
+
+  /**
+   * Sets the data formatter that should be used to render the data of the 
grid, E.G. in json or xml.
+   *
+   * @param  sfGridFormatterInterface $formatter A Data Formatter
+   */
+  public function setDataFormatter(sfGridFormatterInterface $formatter)
+  {
+    $this->dataFormatter = $formatter;
+  }
+  
+  /**
+   * returns the JavaScriptFormatter (to format (the structure) in 
(unobstrusive) JavaScript)
+   * 
+   * @return sfGridFormatterInterface
+   */
+  public function getJavaScriptFormatter()
+  {
+    return $this->javaScriptFormatter;
+  }
+
+  /**
+   * Sets the JavaScript formatter that should be used to render the grid in 
JavaScript.
+   *
+   * @param  sfGridFormatterInterface $formatter A JavaScriptFormatter
+   */
+  public function setJavaScriptFormatter(sfGridFormatterInterface $formatter)
+  {
+    $this->javaScriptFormatter = $formatter;
+  }
+  
+  
+  /**
+   * Re
+   * 
+   * return string
+   */
+  public function renderData()
+  {
+    // set default sort-column, if set
+    if (!$this->getSortColumn() && $this->defaultSortColumn)
+    {
+      $this->setSort($this->defaultSortColumn, $this->defaultSortOrder);
+    }
+
+    // update offset lazy, now is a good time to request last page and check 
if we don't requested a higher pager
+    $this->getDataSource()->setOffset($this->getPager()->getFirstIndex());
+
+    if ($this->getDataFormatter() === null)
+    {
+      throw new LogicException('A Data formatter must be set before calling 
renderData()');
+    }
+
+    return $this->getDataFormatter()->render();
+  }
+  
+  /**
+   * return string
+   */
+  public function renderJavaScript()
+  {
+    if ($this->getJavaScriptFormatter() === null)
+    {
+      throw new LogicException('A JavaScript formatter must be set before 
calling renderJavaScript()');
+    }
+
+    return $this->getJavaScriptFormatter()->render();
+  }
+}
\ No newline at end of file

Modified: plugins/sfGridPlugin/trunk/test/unit/grid/sfGridTest.php
===================================================================
--- plugins/sfGridPlugin/trunk/test/unit/grid/sfGridTest.php    2010-03-24 
22:27:44 UTC (rev 28772)
+++ plugins/sfGridPlugin/trunk/test/unit/grid/sfGridTest.php    2010-03-24 
23:41:39 UTC (rev 28773)
@@ -101,7 +101,7 @@
 $t->diag('->getFormatter(), ->setFormatter()');
 $g = new sfGridTest(new sfDataSourceMock());
 $t->is($g->getFormatter(), null, '->getFormatter() returns "null" when no 
formatter has been associated');
-$f = new sfGridFormatterMock();
+$f = new sfGridFormatterMock($g);
 $g->setFormatter($f);
 $t->is($g->getFormatter(), $f, '->getFormatter() returns the formatter 
associated with the grid');
 
@@ -143,7 +143,7 @@
   $t->pass('->render() throws a "LogicException" if no formatter has been 
set');
 }
 
-$g->setFormatter(new sfGridFormatterMock());
+$g->setFormatter(new sfGridFormatterMock($g));
 $t->is($g->render(), 'rendered', '->render() renders the grid as HTML');
 
 // Countable interface

Modified: 
plugins/sfGridPlugin/trunk/test/unit/mock/sfGridFormatterMock.class.php
===================================================================
--- plugins/sfGridPlugin/trunk/test/unit/mock/sfGridFormatterMock.class.php     
2010-03-24 22:27:44 UTC (rev 28772)
+++ plugins/sfGridPlugin/trunk/test/unit/mock/sfGridFormatterMock.class.php     
2010-03-24 23:41:39 UTC (rev 28773)
@@ -10,19 +10,20 @@
 
 class sfGridFormatterMock implements sfGridFormatterInterface
 {
+  /**
+   * constructor of a Grid Formatter
+   * 
+   * @param sfGrid $grid
+   */
+  public function __construct(sfGrid $grid)
+  {
+  }
+
+  /**
+   * Renders a default text
+   */
   public function render()
   {
     return 'rendered';
   }
-  
-  public function renderHead() {}
-  public function renderFoot() {}
-  public function renderBody() {}
-  public function renderColumnHead($column) {}
-  public function current() {}
-  public function next() {}
-  public function rewind() {}
-  public function key() {}
-  public function valid() {}
-  public function count() {}
 }
\ 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.

Reply via email to