Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENHANCEMENT Renamed DataGrid to GridField
- Loading branch information
Stig Lindqvist
authored and
Hamish Friedlander
committed
Oct 28, 2011
1 parent
a2c7175
commit b229c17
Showing
19 changed files
with
471 additions
and
368 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,2 +1,2 @@ | |||
.sass-cache | .sass-cache | ||
.DS_Store | .DS_Store |
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,140 @@ | |||
<?php | |||
/** | |||
* Displays a {@link SS_List} in a grid format. | |||
* | |||
* @package sapphire | |||
* @subpackage forms | |||
*/ | |||
class GridField extends FormField { | |||
|
|||
/** | |||
* @var SS_List | |||
*/ | |||
protected $dataSource = null; | |||
|
|||
/** | |||
* @var string | |||
*/ | |||
protected $presenterClassName = "GridFieldPresenter"; | |||
|
|||
/** | |||
* @var GridFieldPresenter | |||
*/ | |||
protected $presenter = null; | |||
|
|||
/** | |||
* @var string - the classname of the DataObject that the GridField will display | |||
*/ | |||
protected $modelClassName = ''; | |||
|
|||
/** | |||
* Creates a new GridField field | |||
* | |||
* @param string $name | |||
* @param string $title | |||
* @param SS_List $datasource | |||
* @param Form $form | |||
* @param string $dataPresenterClassName | |||
*/ | |||
public function __construct($name, $title = null, SS_List $datasource = null, Form $form = null, $dataPresenterClassName = 'GridFieldPresenter') { | |||
parent::__construct($name, $title, null, $form); | |||
|
|||
if ($datasource) { | |||
$this->setDatasource($datasource); | |||
} | |||
|
|||
$this->setPresenter($dataPresenterClassName); | |||
} | |||
|
|||
/** | |||
* @param string $modelClassName | |||
*/ | |||
public function setModelClass($modelClassName) { | |||
$this->modelClassName = $modelClassName; | |||
|
|||
return $this; | |||
} | |||
|
|||
/** | |||
* @throws Exception | |||
* @return string | |||
*/ | |||
public function getModelClass() { | |||
if ($this->modelClassName) { | |||
return $this->modelClassName; | |||
} | |||
if ($this->datasource->dataClass) { | |||
return $this->datasource->dataClass; | |||
} | |||
|
|||
throw new Exception(get_class($this).' does not have a modelClassName'); | |||
} | |||
|
|||
/** | |||
* @param string|GridFieldPresenter | |||
* | |||
* @throws Exception | |||
*/ | |||
public function setPresenter($presenter) { | |||
if(!$presenter){ | |||
throw new Exception('setPresenter() for GridField must be set with a class'); | |||
} | |||
|
|||
if(is_object($presenter)) { | |||
$this->presenter = $presenter; | |||
$this->presenter->setGridField($this); | |||
|
|||
return; | |||
} | |||
|
|||
if(!class_exists($presenter)){ | |||
throw new Exception('DataPresenter for GridField must be set with an existing class, '.$presenter.' does not exists.'); | |||
} | |||
|
|||
if($presenter !='GridFieldPresenter' && !ClassInfo::is_subclass_of($presenter, 'GridFieldPresenter')) { | |||
throw new Exception(sprintf( | |||
'DataPresenter "%s" must subclass GridFieldPresenter', $presenter | |||
)); | |||
} | |||
|
|||
$this->presenter = new $presenter; | |||
$this->presenter->setGridField($this); | |||
|
|||
return $this; | |||
} | |||
|
|||
/** | |||
* @return GridFieldPresenter | |||
*/ | |||
public function getPresenter(){ | |||
return $this->presenter; | |||
} | |||
|
|||
/** | |||
* Set the datasource | |||
* | |||
* @param SS_List $datasource | |||
*/ | |||
public function setDataSource(SS_List $datasource) { | |||
$this->datasource = $datasource; | |||
|
|||
return $this; | |||
} | |||
|
|||
/** | |||
* Get the datasource | |||
* | |||
* @return SS_List | |||
*/ | |||
public function getDataSource() { | |||
return $this->datasource; | |||
} | |||
|
|||
/** | |||
* @return string - html for the form | |||
*/ | |||
function FieldHolder() { | |||
return $this->getPresenter()->render(); | |||
} | |||
} | |||
|
Oops, something went wrong.