communigate (phase 2): rules. RT#7514
[freeside.git] / FS / FS / cgp_rule_condition.pm
1 package FS::cgp_rule_condition;
2
3 use strict;
4 use base qw( FS::Record );
5 use FS::Record qw( qsearch qsearchs );
6 use FS::cgp_rule;
7
8 =head1 NAME
9
10 FS::cgp_rule_condition - Object methods for cgp_rule_condition records
11
12 =head1 SYNOPSIS
13
14   use FS::cgp_rule_condition;
15
16   $record = new FS::cgp_rule_condition \%hash;
17   $record = new FS::cgp_rule_condition { 'column' => 'value' };
18
19   $error = $record->insert;
20
21   $error = $new_record->replace($old_record);
22
23   $error = $record->delete;
24
25   $error = $record->check;
26
27 =head1 DESCRIPTION
28
29 An FS::cgp_rule_condition object represents a mail filtering condition.
30 FS::cgp_rule_condition inherits from FS::Record.  The following fields are
31 currently supported:
32
33 =over 4
34
35 =item ruleconditionnum
36
37 primary key
38
39 =item condition
40
41 condition
42
43 =item op
44
45 op
46
47 =item params
48
49 params
50
51 =item rulenum
52
53 rulenum
54
55
56 =back
57
58 =head1 METHODS
59
60 =over 4
61
62 =item new HASHREF
63
64 Creates a new condition.  To add the condition to the database, see L<"insert">.
65
66 Note that this stores the hash reference, not a distinct copy of the hash it
67 points to.  You can ask the object for a copy with the I<hash> method.
68
69 =cut
70
71 # the new method can be inherited from FS::Record, if a table method is defined
72
73 sub table { 'cgp_rule_condition'; }
74
75 =item insert
76
77 Adds this record to the database.  If there is an error, returns the error,
78 otherwise returns false.
79
80 =cut
81
82 # the insert method can be inherited from FS::Record
83
84 =item delete
85
86 Delete this record from the database.
87
88 =cut
89
90 # the delete method can be inherited from FS::Record
91
92 =item replace OLD_RECORD
93
94 Replaces the OLD_RECORD with this one in the database.  If there is an error,
95 returns the error, otherwise returns false.
96
97 =cut
98
99 # the replace method can be inherited from FS::Record
100
101 =item check
102
103 Checks all fields to make sure this is a valid condition.  If there is
104 an error, returns the error, otherwise returns false.  Called by the insert
105 and replace methods.
106
107 =cut
108
109 # the check method should currently be supplied - FS::Record contains some
110 # data checking routines
111
112 sub check {
113   my $self = shift;
114
115   my $error = 
116     $self->ut_numbern('ruleconditionnum')
117     || $self->ut_text('condition')
118     || $self->ut_text('op')
119     || $self->ut_text('params')
120     || $self->ut_foreign_key('rulenum', 'cgp_rule', 'rulenum')
121   ;
122   return $error if $error;
123
124   $self->SUPER::check;
125 }
126
127 =back
128
129 =head1 BUGS
130
131 =head1 SEE ALSO
132
133 L<FS::Record>, schema.html from the base documentation.
134
135 =cut
136
137 1;
138