(merged from branches/roa. use "svn log -c <changeset> -g <module-svn-path>" for detailed commit message)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@60338 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2008-08-11 03:13:53 +00:00
parent a1b0987c23
commit b932a251b1
2 changed files with 37 additions and 10 deletions

View File

@ -1349,8 +1349,19 @@ class DataObject extends ViewableData implements DataObjectInterface {
// If we explicitly set a field, then construct that // If we explicitly set a field, then construct that
if(isset($spec['field'])) { if(isset($spec['field'])) {
$fieldClass = $spec['field']; // If it's a string, use it as a class name and construct
$field = new $fieldClass($fieldName); if(is_string($spec['field'])) {
$fieldClass = $spec['field'];
$field = new $fieldClass($fieldName);
// If it's a FormField object, then just use that object directly.
} else if($spec['field'] instanceof FormField) {
$field = $spec['field'];
// Otherwise we have a bug
} else {
user_error("Bad value for searchable_fields, 'field' value: " . var_export($spec['field'], true), E_USER_WARNING);
}
// Otherwise, use the database field's scaffolder // Otherwise, use the database field's scaffolder
} else { } else {
@ -1497,10 +1508,20 @@ class DataObject extends ViewableData implements DataObjectInterface {
* Level 2 is more lenient, it will onlr return real data changes, for example a change from 0 to null * Level 2 is more lenient, it will onlr return real data changes, for example a change from 0 to null
* would not be included. * would not be included.
* *
* Example return:
* <code>
* array(
* 'Title' = array('before' => 'Home', 'after' => 'Home-Changed', 'level' => 2)
* )
* </code>
*
* @param boolean $databaseFieldsOnly Get only database fields that have changed * @param boolean $databaseFieldsOnly Get only database fields that have changed
* @param int $changeLevel The strictness of what is defined as change * @param int $changeLevel The strictness of what is defined as change
* @return array
*/ */
public function getChangedFields($databaseFieldsOnly = false, $changeLevel = 1) { public function getChangedFields($databaseFieldsOnly = false, $changeLevel = 1) {
$changedFields = array();
if($databaseFieldsOnly) { if($databaseFieldsOnly) {
$customDatabaseFields = $this->customDatabaseFields(); $customDatabaseFields = $this->customDatabaseFields();
$fields = array_intersect_key($this->changed, $customDatabaseFields); $fields = array_intersect_key($this->changed, $customDatabaseFields);
@ -1517,7 +1538,16 @@ class DataObject extends ViewableData implements DataObjectInterface {
} }
} }
return $fields; foreach($fields as $name => $level) {
if(!isset($this->original[$name])) continue;
$changedFields[$name] = array(
'before' => $this->original[$name],
'after' => $this->record[$name],
'level' => $level
);
}
return $changedFields;
} }
/** /**
@ -1540,13 +1570,10 @@ class DataObject extends ViewableData implements DataObjectInterface {
if(!isset($this->record[$fieldName]) || $this->record[$fieldName] !== $val) { if(!isset($this->record[$fieldName]) || $this->record[$fieldName] !== $val) {
// TODO Add check for php-level defaults which are not set in the db // TODO Add check for php-level defaults which are not set in the db
// TODO Add check for hidden input-fields (readonly) which are not set in the db // TODO Add check for hidden input-fields (readonly) which are not set in the db
if( if(
// Only existing fields // Main non type-based check
$this->fieldExists($fieldName) (isset($this->record[$fieldName]) && $this->record[$fieldName] != $val)
// Catches "0"==NULL
&& (isset($this->record[$fieldName]) && (intval($val) != intval($this->record[$fieldName])))
// Main non type-based check
&& (isset($this->record[$fieldName]) && $this->record[$fieldName] != $val)
) { ) {
// Non-strict check fails, so value really changed, e.g. "abc" != "cde" // Non-strict check fails, so value really changed, e.g. "abc" != "cde"
$this->changed[$fieldName] = 2; $this->changed[$fieldName] = 2;

View File

@ -118,7 +118,7 @@ table.CMSList tbody td.checkbox {
table.TableField tbody tr.over td, table.TableField tbody tr.over td,
.TableListField table.data tbody tr.over td, .TableListField table.data tbody tr.over td,
table.CMSList tbody td.over td{ table.CMSList tbody td.over td{
background-color: #FF6600; background-color: #FFCC66;
} }
table.TableField tbody tr.current td, table.TableField tbody tr.current td,