Twitter Feed

Xataface Maillist

Sign up to receive the Xataface news letter with weekly updates and development tips.

 
Found 1 of 138 records in table Wiki
Now Showing 1 of 1

Current Record: field__fieldname

Defining Calculated Fields

[Permalink]

Return to Delegate class methods

Xataface allows you to define calculated fields using the delegate class. These fields won't be visible in the UI by default, but they will be accessible to some modules (e.g. the HTML Reports Module) and they are always accessible to you via the API.

E.g. If you define a calculated field named year, you would be able to access this value using the regular Dataface_Record syntax:

$record->val('year');

You could also define any number of filter methods and permissions on this field just as you can on regular fields.

e.g.

function year__permissions($record){
    // Return special permissions on the year field.
}

or

function year__display($record){
    // Override how the year is displayed in the UI.
    return $record->val('year').' A.D.';
}

How to Define a Calculated Field

In the delegate class you simply create a method with the following naming convention:

function field__fieldname(Dataface_Record $record);

where the return value is the value that the given record should have for the field filedname.

E.g.

function field__year($record){
    $time = trtotime($record->strval('date'));
    if ( $time ){
        return date('Y', $time));
    } else {
        return '';
    }
}
blog comments powered by Disqus
Powered by Xataface
(c) 2005-2018 All rights reserved