saved searches, core stuff, #72101
[freeside.git] / FS / FS / saved_search_option.pm
1 package FS::saved_search_option;
2 use base qw( FS::Record );
3
4 use strict;
5 use FS::Record qw( qsearch qsearchs );
6
7 =head1 NAME
8
9 FS::saved_search_option - Object methods for saved_search_option records
10
11 =head1 SYNOPSIS
12
13   use FS::saved_search_option;
14
15   $record = new FS::saved_search_option \%hash;
16   $record = new FS::saved_search_option { '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::saved_search_option object represents a CGI parameter for a report
29 saved in L<FS::saved_search>.  FS::saved_search_option inherits from
30 FS::Record.  The following fields are currently supported:
31
32 =over 4
33
34 =item optionnum
35
36 primary key
37
38 =item searchnum
39
40 searchnum
41
42 =item optionname
43
44 optionname
45
46 =item optionvalue
47
48 optionvalue
49
50
51 =back
52
53 =head1 METHODS
54
55 =over 4
56
57 =item new HASHREF
58
59 Creates a new parameter.  To add the record to the database, see
60 L<"insert">.
61
62 Note that this stores the hash reference, not a distinct copy of the hash it
63 points to.  You can ask the object for a copy with the I<hash> method.
64
65 =cut
66
67 # the new method can be inherited from FS::Record, if a table method is defined
68
69 sub table { 'saved_search_option'; }
70
71 =item insert
72
73 Adds this record to the database.  If there is an error, returns the error,
74 otherwise returns false.
75
76 =item delete
77
78 Delete this record from the database.
79
80 =item replace OLD_RECORD
81
82 Replaces the OLD_RECORD with this one in the database.  If there is an error,
83 returns the error, otherwise returns false.
84
85 =item check
86
87 Checks all fields to make sure this is a valid example.  If there is
88 an error, returns the error, otherwise returns false.  Called by the insert
89 and replace methods.
90
91 =cut
92
93 # the check method should currently be supplied - FS::Record contains some
94 # data checking routines
95
96 sub check {
97   my $self = shift;
98
99 # unpack these from the format used by CGI
100   my $optionvalue = $self->optionvalue;
101   $optionvalue =~ s/\0/\n/g;
102
103   my $error = 
104     $self->ut_numbern('optionnum')
105     || $self->ut_number('searchnum')
106 #   || $self->ut_foreign_key('searchnum', 'saved_search', 'searchnum')
107     || $self->ut_text('optionname')
108     || $self->ut_textn('optionvalue')
109   ;
110   return $error if $error;
111
112   $self->SUPER::check;
113 }
114
115 =back
116
117 =head1 SEE ALSO
118
119 L<FS::Record>
120
121 =cut
122
123 1;
124