adding svc_mailinglist for communigate "groups" (mailing lists), RT#7514
[freeside.git] / FS / FS / mailinglistmember.pm
1 package FS::mailinglistmember;
2
3 use strict;
4 use base qw( FS::Record );
5 use FS::Record qw( qsearchs ); # qsearch );
6 use FS::mailinglist;
7 use FS::svc_acct;
8 use FS::contact_email;
9
10 =head1 NAME
11
12 FS::mailinglistmember - Object methods for mailinglistmember records
13
14 =head1 SYNOPSIS
15
16   use FS::mailinglistmember;
17
18   $record = new FS::mailinglistmember \%hash;
19   $record = new FS::mailinglistmember { 'column' => 'value' };
20
21   $error = $record->insert;
22
23   $error = $new_record->replace($old_record);
24
25   $error = $record->delete;
26
27   $error = $record->check;
28
29 =head1 DESCRIPTION
30
31 An FS::mailinglistmember object represents a mailing list member.
32 FS::mailinglistmember inherits from FS::Record.  The following fields are
33 currently supported:
34
35 =over 4
36
37 =item membernum
38
39 primary key
40
41 =item listnum
42
43 listnum
44
45 =item svcnum
46
47 svcnum
48
49 =item contactemailnum
50
51 contactemailnum
52
53 =item email
54
55 email
56
57
58 =back
59
60 =head1 METHODS
61
62 =over 4
63
64 =item new HASHREF
65
66 Creates a new mailing list member.  To add the member to the database, see
67  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 { 'mailinglistmember'; }
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 member.  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('membernum')
120     || $self->ut_foreign_key('listnum', 'mailinglist', 'listnum')
121     || $self->ut_foreign_keyn('svcnum', 'svc_acct', 'svcnum')
122     || $self->ut_foreign_keyn('contactemailnum', 'contact_email', 'contactemailnum')
123     || $self->ut_textn('email') #XXX ut_email! from svc_forward, cust_main_invoice
124   ;
125   return $error if $error;
126
127   $self->SUPER::check;
128 }
129
130 =item mailinglist
131
132 =cut
133
134 sub mailinglist {
135   my $self = shift;
136   qsearchs('mailinglist', { 'listnum' => $self->listnum } );
137 }
138
139 =back
140
141 =head1 BUGS
142
143 =head1 SEE ALSO
144
145 L<FS::Record>, schema.html from the base documentation.
146
147 =cut
148
149 1;
150