Freeside:4:Documentation:Developer/FS/part event/Condition

From Freeside
Jump to: navigation, search

NAME

FS::part_event::Condition - Base class for event conditions

SYNOPSIS

package FS::part_event::Condition::mycondition;

use base FS::part_event::Condition;

DESCRIPTION

FS::part_event::Condition is a base class for event conditions classes.

METHODS

These methods are implemented in each condition class.

description
Condition classes must define a description method. This method should return a scalar description of the condition.
eventtable_hashref
Condition classes must define an eventtable_hashref method if they can only be tested against some kinds of tables. This method should return a hash reference of eventtables (values set true indicate the condition can be tested):

 sub eventtable_hashref {
   { 'cust_main'      => 1,
     'cust_bill'      => 1,
     'cust_pkg'       => 0,
     'cust_pay_batch' => 0,
     'cust_statement' => 0,
   };
 }

option_fields
Condition classes may define an option_fields method to indicate that they accept one or more options.
This method should return a list of option names and option descriptions. Each option description can be a scalar description, for simple options, or a hashref with the following values:
label - Description
; type - Currently text, money, checkbox, checkbox-multiple, select, select-agent, select-pkg_class, select-part_referral, select-table, fixed, hidden, (others can be implemented as httemplate/elements/tr-TYPE.html mason components). Defaults to text.:; options - For checkbox-multiple and select, a list reference of available option values.:; option_labels - For checkbox-multiple (and select?), a hash reference of availble option values and labels.:; value - for checkbox, fixed, hidden (also a default for text, money, more?):; table - for select-table:; name_col - for select-table:; NOTE: See httemplate/elements/select-table.html for a full list of the optinal options for the select-table type
NOTE: A database connection is not yet available when this subroutine is executed.
Example:

 sub option_fields {
   (
     'field'         => 'description',

     'another_field' => { 'label'=>'Amount', 'type'=>'money', },

     'third_field'   => { 'label'         => 'Types',
                          'type'          => 'checkbox-multiple',
                          'options'       => [ 'h', 's' ],
                          'option_labels' => { 'h' => 'Happy',
                                               's' => 'Sad',
                                             },
   );
 }

condition CUSTOMER_EVENT_OBJECT
Condition classes must define a condition method. This method is evaluated to determine if the condition has been met. The object which triggered the event (an FS::cust_main, FS::cust_bill or FS::cust_pkg object) is passed as the first argument. Additional arguments are list of key-value pairs.
To retreive option values, call the option method on the desired option, i.e.:

 my( $self, $cust_object, %opts ) = @_;
 $value_of_field = $self->option('field');

Available additional arguments:

 $time = $opt{'time'}; #use this instead of time or $^T

 $cust_event = $opt{'cust_event'}; #to retreive the cust_event object being tested

Return a true value if the condition has been met, and a false value if it has not.
condition_sql EVENTTABLE
Condition classes may optionally define a condition_sql method. This class method should return an SQL fragment that tests for this condition. The fragment is evaluated and a true value of this expression indicates that the condition has been met. The event table (cust_main, cust_bill or cust_pkg) is passed as an argument.
This method is used for optimizing event queries. You may want to add indices for any columns referenced. It is acceptable to return an SQL fragment which partially tests the condition; doing so will still reduce the number of records which must be returned and tested with the condition method.
disabled
Condition classes may optionally define a disabled method. Returning a true value disbles the condition entirely.
implicit_flag
This is used internally by the once and balance conditions. You probably do not want to define this method for new custom conditions, unless you're sure you want every new action to start with your condition.
Condition classes may define an implicit_flag method that returns true to indicate that all new events should start with this condition. (Currently, condition classes which do so should be applicable to all kinds of eventtables.) The numeric value of the flag also defines the ordering of implicit conditions.
remove_warning
Again, used internally by the once and balance conditions; probably not a good idea for new custom conditions.
Condition classes may define a remove_warning method containing a string warning message to enable a confirmation dialog triggered when the condition is removed from an event.
order_sql
This is used internally by the balance_age and cust_bill_age conditions to declare ordering; probably not of general use for new custom conditions.
order_sql_weight
In conjunction with order_sql, this defines which order the ordering fragments supplied by different order_sql should be used.

BASE METHODS

These methods are defined in the base class for use in condition classes.

cust_main CUST_OBJECT
Return the customer object (see FS::cust_main) associated with the provided object (the object itself if it is already a customer object).
cust_pkg OBJECT
Return the package object (FS::cust_pkg) associated with the provided object. The object must be either a service (FS::svc_Common) or a package.
option_label OPTIONNAME
Returns the label for the specified option name.
option_type OPTION
Returns the type of the option, as a string: 'text', 'money', 'date', or 'freq'.
option_age_from OPTION FROM_TIMESTAMP
Retreives a condition option, parses it from a frequency (such as "1d", "1w" or "12m"), and subtracts that interval from the supplied timestamp. It is primarily intended for use in condition.
condition_sql_option OPTION
This is a class method that returns an SQL fragment for retreiving a condition option. It is primarily intended for use in condition_sql.
condition_sql_option_age_from OPTION FROM_TIMESTAMP
This is a class method that returns an SQL fragment that will retreive a condition option, parse it from a frequency (such as "1d", "1w" or "12m"), and subtract that interval from the supplied timestamp. It is primarily intended for use in condition_sql.
condition_sql_option_age OPTION
This is a class method that returns an SQL fragment for retreiving a condition option, and additionaly parsing it from a frequency (such as "1d", "1w" or "12m") into an approximate number of seconds.
Note that since months vary in length, the results of this method should not be used in computations (use condition_sql_option_age_from for that). They are useful for for ordering and comparison to other ages.
This method is primarily intended for use in order_sql.
age2seconds_sql
Class method returns an SQL fragment for parsing an arbitrary frequeny (such as "1d", "1w", "12m", "2y" or "12h") into an approximate number of seconds.
Approximate meaning: months are considered to be 30 days, years to be 365.25 days. Otherwise the numbers of seconds returned is exact.
condition_sql_option_integer OPTION [ DRIVER_NAME ]
As condition_sql_option, but cast the option value to an integer so that comparison to other integers is type-correct.

NEW CONDITION CLASSES

A module should be added in FS/FS/part_event/Condition/ which implements the methods desribed above in "METHODS". An example may be found in the eg/part_event-Condition-template.pm file.

POD ERRORS

Hey! The above document had some coding errors, which are explained below:

Around line 273:
'=item' outside of any '=over'
Around line 536:
You forgot a '=back' before '=head1'