r52080, r52101, r52102 (merged from branches/roa)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@59897 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2008-08-06 02:43:46 +00:00
parent 8c05c9985a
commit faeea52740
14 changed files with 163 additions and 11 deletions

View File

@ -1124,6 +1124,80 @@ class DataObject extends ViewableData implements DataObjectInterface {
}
return isset($items) ? $items : null;
}
/**
* Generates a SearchContext to be used for building and processing
* a generic search form for properties on this object.
*
* @usedby {@link ModelAdmin}
* @return SearchContext
*/
public function getDefaultSearchContext() {
$c = new SearchContext($this->class);
return $c;
}
/**
* Determine which properties on the DataObject are
* searchable, and map them to their default {@link FormField}
* representations. Useful for scaffolding a searchform for {@link ModelAdmin}.
*
* @usedby {@link SearchContext}
* @return FieldSet
*/
public function scaffoldSearchFields() {
$fields = new FieldSet();
foreach($this->databaseFields() as $fieldName => $fieldType) {
// @todo Pass localized title
$fields->push($this->dbObject($fieldName)->scaffoldSearchField());
}
return $fields;
}
/**
* Scaffold a simple edit form for all properties on this dataobject,
* based on default {@link FormField} mapping in {@link DBField::scaffoldFormField()}
*
* @uses {@link DBField::scaffoldFormField()}
* @return FieldSet
*/
public function scaffoldFormFields() {
$fields = new FieldSet();
foreach($this->databaseFields() as $fieldName => $fieldType) {
// @todo Pass localized title
$fields->push($this->dbObject($fieldName)->scaffoldFormField());
}
return $fields;
}
/**
* Centerpiece of every data administration interface in Silverstripe,
* which returns a {@link FieldSet} suitable for a {@link Form} object.
* If not overloaded, we're using {@link scaffoldFormFields()} to automatically
* generate this set.
*
* <example>
* class MyCustomClass extends DataObject {
* static $db = array('CustomProperty'=>'Boolean');
*
* public function getCMSFields() {
* $fields = parent::getCMSFields();
* $fields->push(new CheckboxField('CustomProperty'));
* return $fields;
* }
* }
* </example>
*
* @see Good example of complex FormField building: {@link SiteTree::getCMSFields()}
*
* @return FieldSet
*/
public function getCMSFields() {
return $this->scaffoldFormFields();
}
/**
* Checks if the given fields have been filled out.

View File

@ -35,6 +35,10 @@ class Boolean extends DBField {
user_error("DBField::saveInto() Called on a nameless '$this->class' object", E_USER_ERROR);
}
}
public function scaffoldFormField($title = null) {
return new CheckboxField($this->name, $title);
}
}
?>

View File

@ -3,6 +3,7 @@
* Single field in the database.
* Every field from the database is represented as a sub-class of DBField. In addition to supporting
* the creation of the field in the database,
*
* @package sapphire
* @subpackage model
*/
@ -102,6 +103,38 @@ abstract class DBField extends ViewableData {
}
}
/**
* Returns a FormField instance used as a default
* for form scaffolding.
*
* @usedby {@link SearchContext}
* @usedby {@link ModelAdmin}
* @usedby {@link DataObject::scaffoldFormFields()}
*
* @param string $title Optional. Localized title of the generated instance
* @return FormField
*/
public function scaffoldFormField($title = null) {
$field = new TextField($this->name, $title);
return $field;
}
/**
* Returns a FormField instance used as a default
* for searchform scaffolding.
*
* @usedby {@link SearchContext}
* @usedby {@link ModelAdmin}
* @usedby {@link DataObject::scaffoldFormFields()}
*
* @param string $title Optional. Localized title of the generated instance
* @return FormField
*/
public function scaffoldSearchField($title = null) {
return $this->scaffoldFormField($title);
}
/**
* Add the field to the underlying database.
*/

View File

@ -235,6 +235,10 @@ class Date extends DBField {
return date("Y-m-d", mktime(0,0,0,$fmonth,$fday,$fyear-1));
}
}
public function scaffoldFormField($title = null) {
return new DateField($this->name, $title);
}
}
?>

View File

@ -39,6 +39,10 @@ if(!class_exists('Datetime')) {
function requireField() {
DB::requireField($this->tableName, $this->name, "datetime");
}
public function scaffoldFormField($title = null) {
return new PopupDateTimeField($this->name, $title);
}
}
}
?>

View File

@ -35,7 +35,11 @@ class Decimal extends DBField {
} else {
user_error("DBField::saveInto() Called on a nameless '" . get_class($this) . "' object", E_USER_ERROR);
}
}
}
public function scaffoldFormField($title = null) {
return new NumericField($this->name, $title);
}
}
?>

View File

@ -12,6 +12,10 @@ class Float extends DBField {
function Nice() {
return number_format($this->value, 2);
}
}
public function scaffoldFormField($title = null) {
return new NumericField($this->name, $title);
}
}
?>

View File

@ -64,6 +64,14 @@ class HTMLText extends Text {
return $summary;
}
public function scaffoldFormField($title = null) {
return new HTMLEditorField($this->name, $title);
}
public function scaffoldSearchField($title = null) {
return new TextField($this->name, $title);
}
}

View File

@ -7,7 +7,14 @@
* @subpackage model
*/
class HTMLVarchar extends Varchar {
public function scaffoldFormField($title = null) {
return new HTMLOneLineField($this->name, $title);
}
public function scaffoldSearchField($title = null) {
return new TextField($this->name, $title);
}
}

View File

@ -38,7 +38,9 @@ class Int extends DBField {
return sprintf( '%d', $this->value );
}
public function scaffoldFormField($title = null) {
return new NumericField($this->name, $title);
}
}

View File

@ -34,10 +34,9 @@ class SSDatetime extends Date {
return date('Y-m-d%20H:i:s', strtotime($this->value));
}
function __construct( $name ) {
// Debug::show( 'Created SSDatetime: ' . $name );
parent::__construct( $name );
public function scaffoldFormField($title = null) {
return new PopupDateTimeField($this->name, $title);
}
}
?>
?>

View File

@ -38,5 +38,9 @@ class Time extends DBField {
function requireField() {
DB::requireField($this->tableName, $this->name, "time");
}
public function scaffoldFormField($title = null) {
return new TimeField($this->name, $title);
}
}
?>

View File

@ -34,5 +34,7 @@ class TextField extends FormField {
if(!$this->value) $this->value = $this->Title();
return $this->Field();
}
}
?>
?>

View File

@ -1,6 +1,9 @@
<?php
/**
* Standard basic search form
* Standard basic search form which conducts a fulltext search on all {@link SiteTree}
* objects.
*
* @see Use {@link ModelController} and {@link SearchContext} for a more generic search implementation based around {@link DataObject}
* @package sapphire
* @subpackage search
*/
@ -199,4 +202,4 @@ class SearchForm extends Form {
}
?>
?>