Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

API CHANGE: DBField::hasValue() conflicts with ViewableData::hasValue…

…(), use DBField::exists() instead.
  • Loading branch information...
commit bdb312c6654f7bcc95137e3a8fb8a34c6524180d 1 parent 501c8f3
@ajoneil ajoneil authored
View
4 model/DataObject.php
@@ -596,7 +596,7 @@ public function isEmpty(){
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 @@ public function provideI18nEntities() {
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);
}
View
2  model/fieldtypes/CompositeDBField.php
@@ -177,6 +177,6 @@ function isChanged();
*
* @return boolean
*/
- function hasValue();
+ function exists();
}
View
12 model/fieldtypes/DBField.php
@@ -120,6 +120,7 @@ function setValue($value, $record = null) {
$this->value = $value;
}
+
/**
* Determines if the field has a value which
* is not considered to be 'null' in
@@ -127,15 +128,8 @@ function setValue($value, $record = null) {
*
* @return boolean
*/
- function hasValue() {
- return ($this->value);
- }
-
- /**
- * @return bool
- */
public function exists() {
- return $this->hasValue();
+ return ($this->value);
}
/**
@@ -167,7 +161,7 @@ function prepValueForDB($value) {
* @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();
}
/**
View
4 model/fieldtypes/HTMLText.php
@@ -128,8 +128,8 @@ public function forTemplate() {
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) {
View
4 model/fieldtypes/HTMLVarchar.php
@@ -14,8 +14,8 @@ public function forTemplate() {
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) {
View
2  model/fieldtypes/Money.php
@@ -190,7 +190,7 @@ function setAmount($amount, $markChanged = true) {
/**
* @return boolean
*/
- function hasValue() {
+ function exists() {
return ($this->getCurrency() && is_numeric($this->getAmount()));
}
View
4 model/fieldtypes/StringField.php
@@ -64,9 +64,9 @@ function getNullifyEmpty() {
/**
* (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 === '');
}
View
2  model/fieldtypes/Varchar.php
@@ -56,7 +56,7 @@ function requireField() {
* 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] . '.';
}
/**
View
26 tests/model/DBFieldTest.php
@@ -157,42 +157,42 @@ function testPrepValueForDB() {
$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() {
View
8 tests/model/MoneyTest.php
@@ -207,23 +207,23 @@ function testSetValueAsMoney() {
);
}
- 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() {
Please sign in to comment.
Something went wrong with that request. Please try again.