diff --git a/model/DataObject.php b/model/DataObject.php index bf6e78323..49f8141f4 100644 --- a/model/DataObject.php +++ b/model/DataObject.php @@ -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); } diff --git a/model/fieldtypes/CompositeDBField.php b/model/fieldtypes/CompositeDBField.php index b562fb99f..b1aa39055 100644 --- a/model/fieldtypes/CompositeDBField.php +++ b/model/fieldtypes/CompositeDBField.php @@ -177,6 +177,6 @@ interface CompositeDBField { * * @return boolean */ - function hasValue(); + function exists(); } \ No newline at end of file diff --git a/model/fieldtypes/DBField.php b/model/fieldtypes/DBField.php index c0c1e9587..12e9714c8 100644 --- a/model/fieldtypes/DBField.php +++ b/model/fieldtypes/DBField.php @@ -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(); } /** diff --git a/model/fieldtypes/HTMLText.php b/model/fieldtypes/HTMLText.php index b90c98681..de7652465 100644 --- a/model/fieldtypes/HTMLText.php +++ b/model/fieldtypes/HTMLText.php @@ -128,8 +128,8 @@ class HTMLText extends Text { return ShortcodeParser::get_active()->parse($this->value); } - public function hasValue() { - return parent::hasValue() && $this->value != '
'; + public function exists() { + return parent::exists() && $this->value != ''; } public function scaffoldFormField($title = null, $params = null) { diff --git a/model/fieldtypes/HTMLVarchar.php b/model/fieldtypes/HTMLVarchar.php index 76cf3e049..b9ccc1859 100644 --- a/model/fieldtypes/HTMLVarchar.php +++ b/model/fieldtypes/HTMLVarchar.php @@ -14,8 +14,8 @@ class HTMLVarchar extends Varchar { return ShortcodeParser::get_active()->parse($this->value); } - public function hasValue() { - return parent::hasValue() && $this->value != ''; + public function exists() { + return parent::exists() && $this->value != ''; } public function scaffoldFormField($title = null, $params = null) { diff --git a/model/fieldtypes/Money.php b/model/fieldtypes/Money.php index 14c6a33ba..ac1f7586a 100644 --- a/model/fieldtypes/Money.php +++ b/model/fieldtypes/Money.php @@ -190,7 +190,7 @@ class Money extends DBField implements CompositeDBField { /** * @return boolean */ - function hasValue() { + function exists() { return ($this->getCurrency() && is_numeric($this->getAmount())); } diff --git a/model/fieldtypes/StringField.php b/model/fieldtypes/StringField.php index 5010679ed..62683c12d 100644 --- a/model/fieldtypes/StringField.php +++ b/model/fieldtypes/StringField.php @@ -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 === ''); } diff --git a/model/fieldtypes/Varchar.php b/model/fieldtypes/Varchar.php index 5ea03f0dc..a271216b9 100644 --- a/model/fieldtypes/Varchar.php +++ b/model/fieldtypes/Varchar.php @@ -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] . '.'; } /** diff --git a/tests/model/DBFieldTest.php b/tests/model/DBFieldTest.php index b6f3f7d29..781166509 100644 --- a/tests/model/DBFieldTest.php +++ b/tests/model/DBFieldTest.php @@ -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() { diff --git a/tests/model/MoneyTest.php b/tests/model/MoneyTest.php index 429769c7c..aa2bde1a6 100644 --- a/tests/model/MoneyTest.php +++ b/tests/model/MoneyTest.php @@ -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() {