Skip to content
This repository
Browse code

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

…(), use DBField::exists() instead.
  • Loading branch information...
commit bdb312c6654f7bcc95137e3a8fb8a34c6524180d 1 parent 501c8f3
Andrew O'Neil authored April 11, 2012
4  model/DataObject.php
@@ -596,7 +596,7 @@ public function isEmpty(){
596 596
 				if(!array_key_exists($k, $customFields)) continue;
597 597
 				
598 598
 				$dbObj = ($v instanceof DBField) ? $v : $this->dbObject($k);
599  
-				$isEmpty = ($isEmpty && !$dbObj->hasValue());
  599
+				$isEmpty = ($isEmpty && !$dbObj->exists());
600 600
 			}
601 601
 		}
602 602
 		return $isEmpty;
@@ -3346,7 +3346,7 @@ public function provideI18nEntities() {
3346 3346
  	function hasValue($field, $arguments = null, $cache = true) {
3347 3347
  		$obj = $this->dbObject($field);
3348 3348
  		if($obj) {
3349  
- 			return $obj->hasValue();
  3349
+ 			return $obj->exists();
3350 3350
  		} else {
3351 3351
  			return parent::hasValue($field, $arguments, $cache);
3352 3352
  		}
2  model/fieldtypes/CompositeDBField.php
@@ -177,6 +177,6 @@ function isChanged();
177 177
 	 * 
178 178
 	 * @return boolean
179 179
 	 */
180  
-	function hasValue();
  180
+	function exists();
181 181
 	
182 182
 }
12  model/fieldtypes/DBField.php
@@ -120,6 +120,7 @@ function setValue($value, $record = null) {
120 120
 		$this->value = $value;
121 121
 	}
122 122
 	
  123
+	
123 124
 	/**
124 125
 	 * Determines if the field has a value which
125 126
 	 * is not considered to be 'null' in
@@ -127,15 +128,8 @@ function setValue($value, $record = null) {
127 128
 	 * 
128 129
 	 * @return boolean
129 130
 	 */
130  
-	function hasValue() {
131  
-		return ($this->value);
132  
-	}
133  
-	
134  
-	/**
135  
-	 * @return bool
136  
-	 */
137 131
 	public function exists() {
138  
-		return $this->hasValue();
  132
+		return ($this->value);
139 133
 	}
140 134
 	
141 135
 	/**
@@ -167,7 +161,7 @@ function prepValueForDB($value) {
167 161
 	 * @param array $manipulation
168 162
 	 */
169 163
 	function writeToManipulation(&$manipulation) {
170  
-		$manipulation['fields'][$this->name] = $this->hasValue() ? $this->prepValueForDB($this->value) : $this->nullValue();
  164
+		$manipulation['fields'][$this->name] = $this->exists() ? $this->prepValueForDB($this->value) : $this->nullValue();
171 165
 	}
172 166
 	
173 167
 	/**
4  model/fieldtypes/HTMLText.php
@@ -128,8 +128,8 @@ public function forTemplate() {
128 128
 		return ShortcodeParser::get_active()->parse($this->value);
129 129
 	}
130 130
 	
131  
-	public function hasValue() {
132  
-		return parent::hasValue() && $this->value != '<p></p>';
  131
+	public function exists() {
  132
+		return parent::exists() && $this->value != '<p></p>';
133 133
 	}
134 134
 	
135 135
 	public function scaffoldFormField($title = null, $params = null) {
4  model/fieldtypes/HTMLVarchar.php
@@ -14,8 +14,8 @@ public function forTemplate() {
14 14
 		return ShortcodeParser::get_active()->parse($this->value);
15 15
 	}
16 16
 	
17  
-	public function hasValue() {
18  
-		return parent::hasValue() && $this->value != '<p></p>';
  17
+	public function exists() {
  18
+		return parent::exists() && $this->value != '<p></p>';
19 19
 	}
20 20
 	
21 21
 	public function scaffoldFormField($title = null, $params = null) {
2  model/fieldtypes/Money.php
@@ -190,7 +190,7 @@ function setAmount($amount, $markChanged = true) {
190 190
 	/**
191 191
 	 * @return boolean
192 192
 	 */
193  
-	function hasValue() {
  193
+	function exists() {
194 194
 		return ($this->getCurrency() && is_numeric($this->getAmount()));
195 195
 	}
196 196
 	
4  model/fieldtypes/StringField.php
@@ -64,9 +64,9 @@ function getNullifyEmpty() {
64 64
 
65 65
 	/**
66 66
 	 * (non-PHPdoc)
67  
-	 * @see core/model/fieldtypes/DBField#hasValue()
  67
+	 * @see core/model/fieldtypes/DBField#exists()
68 68
 	 */
69  
-	function hasValue() {
  69
+	function exists() {
70 70
 		return ($this->value || $this->value == '0') || ( !$this->nullifyEmpty && $this->value === '');
71 71
 	}
72 72
 
2  model/fieldtypes/Varchar.php
@@ -56,7 +56,7 @@ function requireField() {
56 56
 	 * Return the first letter of the string followed by a .
57 57
 	 */
58 58
 	function Initial() {
59  
-		if($this->hasValue()) return $this->value[0] . '.';
  59
+		if($this->exists()) return $this->value[0] . '.';
60 60
 	}
61 61
 	
62 62
 	/**
26  tests/model/DBFieldTest.php
@@ -157,42 +157,42 @@ function testPrepValueForDB() {
157 157
 		$this->assertEquals("00:00:00", $time->getValue());
158 158
 	}
159 159
 	
160  
-	function testHasValue() {
  160
+	function testExists() {
161 161
 		$varcharField = new Varchar("testfield");
162 162
 		$this->assertTrue($varcharField->getNullifyEmpty());
163 163
 		$varcharField->setValue('abc');
164  
-		$this->assertTrue($varcharField->hasValue());
  164
+		$this->assertTrue($varcharField->exists());
165 165
 		$varcharField->setValue('');
166  
-		$this->assertFalse($varcharField->hasValue());
  166
+		$this->assertFalse($varcharField->exists());
167 167
 		$varcharField->setValue(null);
168  
-		$this->assertFalse($varcharField->hasValue());
  168
+		$this->assertFalse($varcharField->exists());
169 169
 		
170 170
 		$varcharField = new Varchar("testfield", 50, array('nullifyEmpty'=>false));
171 171
 		$this->assertFalse($varcharField->getNullifyEmpty());
172 172
 		$varcharField->setValue('abc');
173  
-		$this->assertTrue($varcharField->hasValue());
  173
+		$this->assertTrue($varcharField->exists());
174 174
 		$varcharField->setValue('');
175  
-		$this->assertTrue($varcharField->hasValue());
  175
+		$this->assertTrue($varcharField->exists());
176 176
 		$varcharField->setValue(null);
177  
-		$this->assertFalse($varcharField->hasValue());
  177
+		$this->assertFalse($varcharField->exists());
178 178
 
179 179
 		$textField = new Text("testfield");
180 180
 		$this->assertTrue($textField->getNullifyEmpty());
181 181
 		$textField->setValue('abc');
182  
-		$this->assertTrue($textField->hasValue());
  182
+		$this->assertTrue($textField->exists());
183 183
 		$textField->setValue('');
184  
-		$this->assertFalse($textField->hasValue());
  184
+		$this->assertFalse($textField->exists());
185 185
 		$textField->setValue(null);
186  
-		$this->assertFalse($textField->hasValue());
  186
+		$this->assertFalse($textField->exists());
187 187
 		
188 188
 		$textField = new Text("testfield", array('nullifyEmpty'=>false));
189 189
 		$this->assertFalse($textField->getNullifyEmpty());
190 190
 		$textField->setValue('abc');
191  
-		$this->assertTrue($textField->hasValue());
  191
+		$this->assertTrue($textField->exists());
192 192
 		$textField->setValue('');
193  
-		$this->assertTrue($textField->hasValue());
  193
+		$this->assertTrue($textField->exists());
194 194
 		$textField->setValue(null);
195  
-		$this->assertFalse($textField->hasValue());
  195
+		$this->assertFalse($textField->exists());
196 196
 	}
197 197
 	
198 198
 	function testStringFieldsWithMultibyteData() {
8  tests/model/MoneyTest.php
@@ -207,23 +207,23 @@ function testSetValueAsMoney() {
207 207
 		);
208 208
 	}
209 209
 	
210  
-	function testHasValue() {
  210
+	function testExists() {
211 211
 		$m1 = new Money();
212  
-		$this->assertFalse($m1->hasValue());
  212
+		$this->assertFalse($m1->exists());
213 213
 		
214 214
 		$m2 = new Money();
215 215
 		$m2->setValue(array(
216 216
 			'Currency' => 'EUR',
217 217
 			'Amount' => 3.44
218 218
 		));
219  
-		$this->assertTrue($m2->hasValue());
  219
+		$this->assertTrue($m2->exists());
220 220
 		
221 221
 		$m3 = new Money();
222 222
 		$m3->setValue(array(
223 223
 			'Currency' => 'EUR',
224 224
 			'Amount' => 0
225 225
 		));
226  
-		$this->assertTrue($m3->hasValue());
  226
+		$this->assertTrue($m3->exists());
227 227
 	}
228 228
 
229 229
 	function testLoadIntoDataObject() {

0 notes on commit bdb312c

Please sign in to comment.
Something went wrong with that request. Please try again.