Version: current

# Class Money

Implements the "Money" pattern.

  Object
  ViewableData implements IteratorAggregate
  DBField
  Money implements CompositeDBField

Package: sapphire\model
Copyright: Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
License: New BSD License
See: http://www.martinfowler.com/eaaCatalog/money.html
Located at sapphire/core/model/fieldtypes/Money.php

## Methods summary

`public` | # `__construct( mixed $name = null )` #### Overrides `DBField::__construct`
`public array` | # `compositeDatabaseFields( )` Return array in the format of `Money::$composite_db`. Used by DataObject->hasOwnDatabaseField(). Return array in the format of `Money::$composite_db`. Used by DataObject->hasOwnDatabaseField(). #### Returns `array` array #### Implementation of `CompositeDBField::compositeDatabaseFields()`
`public` | # `requireField( )` Add the field to the underlying database. Add the field to the underlying database.
`public` | # `writeToManipulation( array & $manipulation )` Prepare the current field for usage in a database-manipulation (works on a manipulation reference). Prepare the current field for usage in a database-manipulation (works on a manipulation reference). Make value safe for insertion into a SQL SET statement by applying addslashes() - can also be used to apply special SQL-commands to the raw value (e.g. for GIS functionality). `DBField::prepValueForDB()` #### Parameters $manipulation array $manipulation #### Overrides `DBField::writeToManipulation` #### Implementation of `CompositeDBField::writeToManipulation()`
`public` | # `addToQuery( `SS_Query` & $query )` Add custom query parameters for this field, mostly SELECT statements for multi-value fields. Add custom query parameters for this field, mostly SELECT statements for multi-value fields. By default, the ORM layer does a SELECT <tablename>.* which gets you the default representations of all columns. #### Parameters $query SS_Query $query #### Overrides `DBField::addToQuery` #### Implementation of `CompositeDBField::addToQuery()`
`public` | # `setValue( mixed $value, array $record = null, boolean $markChanged = true )` Set the value on the field. Optionally takes the whole record as an argument, to pick other values. Set the value on the field. Optionally takes the whole record as an argument, to pick other values. #### Parameters $value mixed $value $record array $record $markChanged boolean $markChanged Indicate wether this field should be marked changed. Set to FALSE if you are initializing this field after construction, rather than setting a new value. #### Overrides `DBField::setValue` #### Implementation of `CompositeDBField::setValue()`
`public string` | # `Nice( mixed $options = array() )` #### Returns `string` string
`public string` | # `NiceWithShortname( mixed $options = array() )` #### Returns `string` string
`public string` | # `NiceWithName( mixed $options = array() )` #### Returns `string` string
`public string` | # `getCurrency( )` #### Returns `string` string
`public` | # `setCurrency( string $currency, mixed $markChanged = true )` #### Parameters $currency string $markChanged
`public float` | # `getAmount( )` #### Returns `float` float
`public` | # `setAmount( float $amount, mixed $markChanged = true )` #### Parameters $amount float $amount $markChanged
`public boolean` | # `hasValue( )` #### Returns `boolean` boolean #### Overrides `DBField::hasValue` #### Implementation of `CompositeDBField::hasValue()`
`public boolean` | # `hasAmount( )` #### Returns `boolean` boolean
`public boolean` | # `isChanged( )` Determines if the field has been changed since its initialization. Most likely relies on an internal flag thats changed when calling `Money::setValue()` or any other custom setters on the object. Determines if the field has been changed since its initialization. Most likely relies on an internal flag thats changed when calling `Money::setValue()` or any other custom setters on the object. #### Returns `boolean` boolean #### Implementation of `CompositeDBField::isChanged()`
`public` | # `setLocale( string $locale )` #### Parameters $locale string $locale
`public string` | # `getLocale( )` #### Returns `string` string
`public string` | # `getSymbol( mixed $currency = null, mixed $locale = null )` #### Returns `string` string
`public string` | # `getShortName( mixed $currency = null, mixed $locale = null )` #### Returns `string` string
`public string` | # `getName( mixed $currency = null, mixed $locale = null )` #### Returns `string` string #### Overrides `DBField::getName`
`public` | # `setAllowedCurrencies( array $arr )` #### Parameters $arr array $arr
`public array` | # `getAllowedCurrencies( )` #### Returns `array` array
`public `FormField`` | # `scaffoldFormField( string $title = null )` Returns a CompositeField instance used as a default for form scaffolding. Returns a CompositeField instance used as a default for form scaffolding. Used by `SearchContext`, `ModelAdmin`, `DataObject::scaffoldFormFields()` #### Parameters $title string $title Optional. Localized title of the generated instance #### Returns ``FormField`` FormField #### Overrides `DBField::scaffoldFormField`
`public string` | # `__toString( )` For backwards compatibility reasons (mainly with ecommerce module), this returns the amount value of the field, rather than a `Money::Nice()` formatting. For backwards compatibility reasons (mainly with ecommerce module), this returns the amount value of the field, rather than a `Money::Nice()` formatting. #### Returns `string` the class name #### Overrides `Object::__toString`

### Methods inherited from DBField

`ATT()`, `HTML()`, `HTMLATT()`, `JS()`, `LowerCase()`, `RAW()`, `RAWURLATT()`, `URLATT()`, `UpperCase()`, `XML()`, `create()`, `debug()`, `defaultSearchFilter()`, `exists()`, `forTemplate()`, `getValue()`, `nullValue()`, `prepValueForDB()`, `saveInto()`, `scaffoldSearchField()`, `setName()`, `setTable()`

### Methods inherited from ViewableData

`ATT_val()`, `BaseHref()`, `CSSClasses()`, `ColumnBreak()`, `ColumnCalc()`, `ColumnNumber()`, `ColumnPad()`, `ColumnPos()`, `CurrentMember()`, `CurrentPage()`, `Debug()`, `Even()`, `EvenOdd()`, `First()`, `FirstLast()`, `HasPerm()`, `IsAjax()`, `JS_val()`, `Last()`, `Me()`, `Middle()`, `MiddleString()`, `Modulus()`, `MultipleOf()`, `Odd()`, `Pos()`, `RAW_val()`, `SQL_val()`, `ThemeDir()`, `ThemeName()`, `Top()`, `TotalItems()`, `XML_val()`, `__get()`, `__isset()`, `__set()`, `buildCastingCache()`, `cachedCall()`, `castingClass()`, `castingHelper()`, `castingHelperPair()`, `castingObjectCreator()`, `castingObjectCreatorPair()`, `customise()`, `defineMethods()`, `escapeTypeForField()`, `getField()`, `getIterator()`, `getSecurityID()`, `getXMLValues()`, `hasField()`, `i18nLocale()`, `iteratorProperties()`, `obj()`, `renderWith()`, `setCustomisedObj()`, `setField()`

### Methods inherited from Object

`__call()`, `__wakeup()`, `addMethodsFrom()`, `addStaticVars()`, `addWrapperMethod()`, `add_extension()`, `add_static_var()`, `allMethodNames()`, `cacheToFile()`, `cacheToFileWithArgs()`, `clearCache()`, `combined_static()`, `createMethod()`, `create_from_string()`, `extInstance()`, `extend()`, `getCustomClass()`, `getExtensionInstance()`, `getExtensionInstances()`, `get_extensions()`, `get_static()`, `hasExtension()`, `hasMethod()`, `has_extension()`, `invokeWithExtensions()`, `is_a()`, `loadCache()`, `parentClass()`, `parse_class_spec()`, `remove_extension()`, `sanitiseCachename()`, `saveCache()`, `set_stat()`, `set_static()`, `set_uninherited()`, `stat()`, `strong_create()`, `uninherited()`, `uninherited_static()`, `useCustomClass()`

### Magic methods summary

## Properties summary

`protected string` | $currency | # $getCurrency() $getCurrency()
`protected float` | $amount | # $currencyAmount $currencyAmount
`protected boolean` | $isChanged | # $isChanged $isChanged
`protected string` | $locale | # $locale $locale
`protected Zend_Currency` | $currencyLib | #
`protected array` | $allowedCurrencies | # Limit the currencies Limit the currencies
`public static array` | $composite_db | # #### Param array

### Properties inherited from DBField

`$arrayValue`, `$defaultVal`, `$default_search_filter_class`, `$escape_type`, `$name`, `$tableName`, `$value`

### Properties inherited from ViewableData

`$casting`, `$customisedObject`, `$default_cast`, `$failover`, `$iteratorPos`, `$iteratorTotalItems`

### Properties inherited from Object

`$class`, `$extension_instances`, `$extensions`

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -