|
a simple but flexible value calculator. This attribute adds a column that contains a calculated value. Calculations can range from simple "3*4" fixed calculations to calculations based on other attributes. The examples are pretty self-explanatory: Example usages A simple calculation: $this->add(new atkCalculatorAttribute("simple", "10*5")); A calculation using an value from the current record: $this->add(new atkCalculatorAttribute("vat", "[price]*0.19")); A calculation using multiple values, bracketed calculations, and a previous calculation: new atkCalculatorAttribute("total", "([price]*[quantity])+[vat]"); A calculation using values from a relation: new atkCalculatorAttribute("vat", "[vattype.percentage]*[total]"); A word of caution The PHP function eval() is used to perform the calculation, so use this only in a trusted environment, and make sure that the user cannot put arbitrary php code in a value (for example, by only performing calculations on atkNumberAttribute values, which are validated to contain only numeric values). Note that if the calculation contains invalid php code, for example unmatched brackets, a php parse error will be thrown. You can use AF_TOTAL to totalize the values in recordlists. Located in /attributes/class.atkcalculatorattribute.inc [line 60] atkAttribute | --atkCalculatorAttributeAuthor(s):
|
| Inherited Properties | Inherited Methods |
|---|---|
|
Inherited From atkAttribute
|
Inherited From atkAttribute
|
| atkCalculatorAttribute | atkCalculatorAttribute() | Constructor |
| String | display() | Returns a displayable string for this value, to be used in HTML pages. |
| String | load() | The load method performs the calculation. |
| int | loadType() | Make sure the value is loaded *after* the main record is loaded. |
| int | storageType() | Make sure the value is not stored. (always calculated on the fly) |
The calculation to perform.
API Tags:| Access: | private |
|
Constructor
Parameters:| String | $name: | Unique name of this attribute within the node. |
| String | $calculation: | The calculation to perform. Must be a valid php expression. |
| int | $flags: | Flags of the attribute. |
|
Returns a displayable string for this value, to be used in HTML pages.
Parameters:| array | $record: | The record that holds the value for this attribute |
| String | $mode: | The display mode. |
| Return: | HTML String |
| Access: | public |
|
The load method performs the calculation.
Parameters:| atkDb | $db: | |
| array | $record: | |
| &$db: |
| Return: | result of the calculation |
| Access: | private |
|
Make sure the value is loaded *after* the main record is loaded.
| Access: | private |
|
Make sure the value is not stored. (always calculated on the fly)
| Access: | private |