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