mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
API CHANGE: DBField::hasValue() conflicts with ViewableData::hasValue(), use DBField::exists() instead.
This commit is contained in:
parent
501c8f3f31
commit
bdb312c665
@ -596,7 +596,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
||||
if(!array_key_exists($k, $customFields)) continue;
|
||||
|
||||
$dbObj = ($v instanceof DBField) ? $v : $this->dbObject($k);
|
||||
$isEmpty = ($isEmpty && !$dbObj->hasValue());
|
||||
$isEmpty = ($isEmpty && !$dbObj->exists());
|
||||
}
|
||||
}
|
||||
return $isEmpty;
|
||||
@ -3346,7 +3346,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
||||
function hasValue($field, $arguments = null, $cache = true) {
|
||||
$obj = $this->dbObject($field);
|
||||
if($obj) {
|
||||
return $obj->hasValue();
|
||||
return $obj->exists();
|
||||
} else {
|
||||
return parent::hasValue($field, $arguments, $cache);
|
||||
}
|
||||
|
@ -177,6 +177,6 @@ interface CompositeDBField {
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function hasValue();
|
||||
function exists();
|
||||
|
||||
}
|
@ -120,6 +120,7 @@ abstract class DBField extends ViewableData {
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determines if the field has a value which
|
||||
* is not considered to be 'null' in
|
||||
@ -127,15 +128,8 @@ abstract class DBField extends ViewableData {
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function hasValue() {
|
||||
return ($this->value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function exists() {
|
||||
return $this->hasValue();
|
||||
return ($this->value);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -167,7 +161,7 @@ abstract class DBField extends ViewableData {
|
||||
* @param array $manipulation
|
||||
*/
|
||||
function writeToManipulation(&$manipulation) {
|
||||
$manipulation['fields'][$this->name] = $this->hasValue() ? $this->prepValueForDB($this->value) : $this->nullValue();
|
||||
$manipulation['fields'][$this->name] = $this->exists() ? $this->prepValueForDB($this->value) : $this->nullValue();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -128,8 +128,8 @@ class HTMLText extends Text {
|
||||
return ShortcodeParser::get_active()->parse($this->value);
|
||||
}
|
||||
|
||||
public function hasValue() {
|
||||
return parent::hasValue() && $this->value != '<p></p>';
|
||||
public function exists() {
|
||||
return parent::exists() && $this->value != '<p></p>';
|
||||
}
|
||||
|
||||
public function scaffoldFormField($title = null, $params = null) {
|
||||
|
@ -14,8 +14,8 @@ class HTMLVarchar extends Varchar {
|
||||
return ShortcodeParser::get_active()->parse($this->value);
|
||||
}
|
||||
|
||||
public function hasValue() {
|
||||
return parent::hasValue() && $this->value != '<p></p>';
|
||||
public function exists() {
|
||||
return parent::exists() && $this->value != '<p></p>';
|
||||
}
|
||||
|
||||
public function scaffoldFormField($title = null, $params = null) {
|
||||
|
@ -190,7 +190,7 @@ class Money extends DBField implements CompositeDBField {
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
function hasValue() {
|
||||
function exists() {
|
||||
return ($this->getCurrency() && is_numeric($this->getAmount()));
|
||||
}
|
||||
|
||||
|
@ -64,9 +64,9 @@ abstract class StringField extends DBField {
|
||||
|
||||
/**
|
||||
* (non-PHPdoc)
|
||||
* @see core/model/fieldtypes/DBField#hasValue()
|
||||
* @see core/model/fieldtypes/DBField#exists()
|
||||
*/
|
||||
function hasValue() {
|
||||
function exists() {
|
||||
return ($this->value || $this->value == '0') || ( !$this->nullifyEmpty && $this->value === '');
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ class Varchar extends StringField {
|
||||
* Return the first letter of the string followed by a .
|
||||
*/
|
||||
function Initial() {
|
||||
if($this->hasValue()) return $this->value[0] . '.';
|
||||
if($this->exists()) return $this->value[0] . '.';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -157,42 +157,42 @@ class DBFieldTest extends SapphireTest {
|
||||
$this->assertEquals("00:00:00", $time->getValue());
|
||||
}
|
||||
|
||||
function testHasValue() {
|
||||
function testExists() {
|
||||
$varcharField = new Varchar("testfield");
|
||||
$this->assertTrue($varcharField->getNullifyEmpty());
|
||||
$varcharField->setValue('abc');
|
||||
$this->assertTrue($varcharField->hasValue());
|
||||
$this->assertTrue($varcharField->exists());
|
||||
$varcharField->setValue('');
|
||||
$this->assertFalse($varcharField->hasValue());
|
||||
$this->assertFalse($varcharField->exists());
|
||||
$varcharField->setValue(null);
|
||||
$this->assertFalse($varcharField->hasValue());
|
||||
$this->assertFalse($varcharField->exists());
|
||||
|
||||
$varcharField = new Varchar("testfield", 50, array('nullifyEmpty'=>false));
|
||||
$this->assertFalse($varcharField->getNullifyEmpty());
|
||||
$varcharField->setValue('abc');
|
||||
$this->assertTrue($varcharField->hasValue());
|
||||
$this->assertTrue($varcharField->exists());
|
||||
$varcharField->setValue('');
|
||||
$this->assertTrue($varcharField->hasValue());
|
||||
$this->assertTrue($varcharField->exists());
|
||||
$varcharField->setValue(null);
|
||||
$this->assertFalse($varcharField->hasValue());
|
||||
$this->assertFalse($varcharField->exists());
|
||||
|
||||
$textField = new Text("testfield");
|
||||
$this->assertTrue($textField->getNullifyEmpty());
|
||||
$textField->setValue('abc');
|
||||
$this->assertTrue($textField->hasValue());
|
||||
$this->assertTrue($textField->exists());
|
||||
$textField->setValue('');
|
||||
$this->assertFalse($textField->hasValue());
|
||||
$this->assertFalse($textField->exists());
|
||||
$textField->setValue(null);
|
||||
$this->assertFalse($textField->hasValue());
|
||||
$this->assertFalse($textField->exists());
|
||||
|
||||
$textField = new Text("testfield", array('nullifyEmpty'=>false));
|
||||
$this->assertFalse($textField->getNullifyEmpty());
|
||||
$textField->setValue('abc');
|
||||
$this->assertTrue($textField->hasValue());
|
||||
$this->assertTrue($textField->exists());
|
||||
$textField->setValue('');
|
||||
$this->assertTrue($textField->hasValue());
|
||||
$this->assertTrue($textField->exists());
|
||||
$textField->setValue(null);
|
||||
$this->assertFalse($textField->hasValue());
|
||||
$this->assertFalse($textField->exists());
|
||||
}
|
||||
|
||||
function testStringFieldsWithMultibyteData() {
|
||||
|
@ -207,23 +207,23 @@ class MoneyTest extends SapphireTest {
|
||||
);
|
||||
}
|
||||
|
||||
function testHasValue() {
|
||||
function testExists() {
|
||||
$m1 = new Money();
|
||||
$this->assertFalse($m1->hasValue());
|
||||
$this->assertFalse($m1->exists());
|
||||
|
||||
$m2 = new Money();
|
||||
$m2->setValue(array(
|
||||
'Currency' => 'EUR',
|
||||
'Amount' => 3.44
|
||||
));
|
||||
$this->assertTrue($m2->hasValue());
|
||||
$this->assertTrue($m2->exists());
|
||||
|
||||
$m3 = new Money();
|
||||
$m3->setValue(array(
|
||||
'Currency' => 'EUR',
|
||||
'Amount' => 0
|
||||
));
|
||||
$this->assertTrue($m3->hasValue());
|
||||
$this->assertTrue($m3->exists());
|
||||
}
|
||||
|
||||
function testLoadIntoDataObject() {
|
||||
|
Loading…
Reference in New Issue
Block a user