| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
abstract class sfWebGridJavaScript extends sfWebGrid |
|---|
| 20 |
{ |
|---|
| 21 |
|
|---|
| 22 |
* formatter to output data (json/xml) |
|---|
| 23 |
* |
|---|
| 24 |
* @var sfGridFormatterInterface |
|---|
| 25 |
*/ |
|---|
| 26 |
protected $dataFormatter; |
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
* formatter that returns (unobtrusive) JavaScript |
|---|
| 30 |
* |
|---|
| 31 |
* @var sfGridFormatterInterface |
|---|
| 32 |
*/ |
|---|
| 33 |
protected $javaScriptFormatter; |
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
* This method should be implemented in your specialised GridClass, to define |
|---|
| 37 |
* the dataFormatter and javaScriptFormatter |
|---|
| 38 |
*/ |
|---|
| 39 |
public function configure() |
|---|
| 40 |
{ |
|---|
| 41 |
|
|---|
| 42 |
parent::configure(); |
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
$this->setDataFormatter(new sfGridFormatterJson($this)); |
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
} |
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
* returns the DataFormatter (to format data in json/xml) |
|---|
| 52 |
* |
|---|
| 53 |
* @return sfGridFormatterInterface |
|---|
| 54 |
*/ |
|---|
| 55 |
public function getDataFormatter() |
|---|
| 56 |
{ |
|---|
| 57 |
return $this->dataFormatter; |
|---|
| 58 |
} |
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
* Sets the data formatter that should be used to render the data of the grid, E.G. in json or xml. |
|---|
| 62 |
* |
|---|
| 63 |
* @param sfGridFormatterInterface $formatter A Data Formatter |
|---|
| 64 |
*/ |
|---|
| 65 |
public function setDataFormatter(sfGridFormatterInterface $formatter) |
|---|
| 66 |
{ |
|---|
| 67 |
$this->dataFormatter = $formatter; |
|---|
| 68 |
} |
|---|
| 69 |
|
|---|
| 70 |
public function renderData() |
|---|
| 71 |
{ |
|---|
| 72 |
|
|---|
| 73 |
if (!$this->getSortColumn() && $this->defaultSortColumn) |
|---|
| 74 |
{ |
|---|
| 75 |
$this->setSort($this->defaultSortColumn, $this->defaultSortOrder); |
|---|
| 76 |
} |
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
$this->getDataSource()->setOffset($this->getPager()->getFirstIndex()); |
|---|
| 80 |
|
|---|
| 81 |
if ($this->getDataFormatter() === null) |
|---|
| 82 |
{ |
|---|
| 83 |
throw new LogicException('A Data formatter must be set before calling renderData()'); |
|---|
| 84 |
} |
|---|
| 85 |
|
|---|
| 86 |
return $this->getDataFormatter()->render(); |
|---|
| 87 |
} |
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 |
* returns the JavaScriptFormatter (to format (the structure) in (unobstrusive) JavaScript) |
|---|
| 92 |
* |
|---|
| 93 |
* @return sfGridFormatterInterface |
|---|
| 94 |
*/ |
|---|
| 95 |
public function getJavaScriptFormatter() |
|---|
| 96 |
{ |
|---|
| 97 |
return $this->javaScriptFormatter; |
|---|
| 98 |
} |
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
* Sets the JavaScript formatter that should be used to render the grid in JavaScript. |
|---|
| 102 |
* |
|---|
| 103 |
* @param sfGridFormatterInterface $formatter A JavaScriptFormatter |
|---|
| 104 |
*/ |
|---|
| 105 |
public function setJavaScriptFormatter(sfGridFormatterInterface $formatter) |
|---|
| 106 |
{ |
|---|
| 107 |
$this->javaScriptFormatter = $formatter; |
|---|
| 108 |
} |
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
* Renders static JavaScript (not based on rows) |
|---|
| 113 |
* |
|---|
| 114 |
* return string |
|---|
| 115 |
*/ |
|---|
| 116 |
public function renderJavaScript() |
|---|
| 117 |
{ |
|---|
| 118 |
if ($this->getJavaScriptFormatter() === null) |
|---|
| 119 |
{ |
|---|
| 120 |
throw new LogicException('A JavaScript formatter must be set before calling renderJavaScript()'); |
|---|
| 121 |
} |
|---|
| 122 |
|
|---|
| 123 |
return $this->getJavaScriptFormatter()->render(); |
|---|
| 124 |
} |
|---|
| 125 |
} |
|---|