Flourish PHP Unframework

fORMMoney

static class, v1.0.0b11

Provides money functionality for fActiveRecord classes

Changes:
1.0.0b11Fixed the generation of validation messages when a non-monetary value is supplied 5/17/11
1.0.0b10Updated code to work with the new fORM API 8/6/10
1.0.0b9Added the $remove_zero_fraction parameter to prepare methods 6/9/10
1.0.0b8Changed validation messages array to use column name keys 5/26/10
1.0.0b7Fixed the set methods to return the record object in order to be consistent with all other set methods 3/15/10
1.0.0b6Fixed duplicate validation messages and fProgrammerException object being thrown when NULL is set 3/3/10
1.0.0b5Updated code for the new fORMDatabase and fORMSchema APIs 10/28/09
1.0.0b4Updated to use new fORM::registerInspectCallback() method 7/13/09
1.0.0b3Updated code to use new fValidationException::formatField() method 6/4/09
1.0.0b2Fixed bugs with objectifying money columns 11/24/08
1.0.0bThe initial implementation 9/5/08

Static Methods

::configureMoneyColumn() public

Sets a column to be formatted as an fMoney object

Signature

void configureMoneyColumn( mixed $class, string $column, string $currency_column=NULL )

Parameters

mixed $class The class name or instance of the class to set the column format
string $column The column to format as an fMoney object
string $currency_column If specified, this column will store the currency of the fMoney object

::encodeMoneyColumn() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

Encodes a money column by calling fMoney::__toString()

Signature

string encodeMoneyColumn( fActiveRecord $object, array &$values, array &$old_values, array &$related_records, array &$cache, string $method_name, array $parameters )

Parameters

fActiveRecord $object The fActiveRecord instance
array &$values The current values
array &$old_values The old values
array &$related_records Any records related to this record
array &$cache The cache array for the record
string $method_name The method that was called
array $parameters The parameters passed to the method

Returns

The encoded monetary value

::inspect() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

Adds metadata about features added by this class

Signature

void inspect( string $class, string $column, array &$metadata )

Parameters

string $class The class being inspected
string $column The column being inspected
array &$metadata The array of metadata about a column

::makeMoneyObjects() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

Makes fMoney objects for all money columns in the object that also have a currency column

Signature

void makeMoneyObjects( fActiveRecord $object, array &$values, array &$old_values, array &$related_records, array &$cache )

Parameters

fActiveRecord $object The fActiveRecord instance
array &$values The current values
array &$old_values The old values
array &$related_records Any records related to this record
array &$cache The cache array for the record

::objectifyMoney() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

Turns a monetary value into an fMoney object

Signature

mixed objectifyMoney( string $class, string $column, mixed $value )

Parameters

string $class The class this value is for
string $column The column the value is in
mixed $value The value

Returns

The fMoney object or raw value

::objectifyMoneyWithCurrency() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

Turns a monetary value into an fMoney object with a currency specified by another column

Signature

void objectifyMoneyWithCurrency( array &$values, array &$old_values, string $value_column, string $currency_column )

Parameters

array &$values The current values
array &$old_values The old values
string $value_column The column holding the value
string $currency_column The column holding the currency code

::prepareMoneyColumn() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

Prepares a money column by calling fMoney::format()

Signature

string prepareMoneyColumn( fActiveRecord $object, array &$values, array &$old_values, array &$related_records, array &$cache, string $method_name, array $parameters )

Parameters

fActiveRecord $object The fActiveRecord instance
array &$values The current values
array &$old_values The old values
array &$related_records Any records related to this record
array &$cache The cache array for the record
string $method_name The method that was called
array $parameters The parameters passed to the method

Returns

The formatted monetary value

::reflect() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

Adjusts the fActiveRecord::reflect() signatures of columns that have been configured in this class

Signature

void reflect( string $class, array &$signatures, boolean $include_doc_comments )

Parameters

string $class The class to reflect
array &$signatures The associative array of {method name} => {signature}
boolean $include_doc_comments If doc comments should be included with the signature

::reset() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

Resets the configuration of the class

Signature

void reset( )

::setCurrencyColumn() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

Sets the currency column and then tries to objectify the related money column

Signature

fActiveRecord setCurrencyColumn( fActiveRecord $object, array &$values, array &$old_values, array &$related_records, array &$cache, string $method_name, array $parameters )

Parameters

fActiveRecord $object The fActiveRecord instance
array &$values The current values
array &$old_values The old values
array &$related_records Any records related to this record
array &$cache The cache array for the record
string $method_name The method that was called
array $parameters The parameters passed to the method

Returns

The record object, to allow for method chaining

::setMoneyColumn() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

Sets the money column and then tries to objectify it with an related currency column

Signature

fActiveRecord setMoneyColumn( fActiveRecord $object, array &$values, array &$old_values, array &$related_records, array &$cache, string $method_name, array $parameters )

Parameters

fActiveRecord $object The fActiveRecord instance
array &$values The current values
array &$old_values The old values
array &$related_records Any records related to this record
array &$cache The cache array for the record
string $method_name The method that was called
array $parameters The parameters passed to the method

Returns

The record object, to allow for method chaining

::validateMoneyColumns() internal public

Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code

Validates all money columns

Signature

void validateMoneyColumns( fActiveRecord $object, array &$values, array &$old_values, array &$related_records, array &$cache, array &$validation_messages )

Parameters

fActiveRecord $object The fActiveRecord instance
array &$values The current values
array &$old_values The old values
array &$related_records Any records related to this record
array &$cache The cache array for the record
array &$validation_messages An array of ordered validation messages