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