1 package FS::part_pkg_report_option;
4 use base qw( FS::Record );
5 use FS::Record qw( qsearch qsearchs dbh );
9 FS::part_pkg_report_option - Object methods for part_pkg_report_option records
13 use FS::part_pkg_report_option;
15 $record = new FS::part_pkg_report_option \%hash;
16 $record = new FS::part_pkg_report_option { 'column' => 'value' };
18 $error = $record->insert;
20 $error = $new_record->replace($old_record);
22 $error = $record->delete;
24 $error = $record->check;
28 An FS::part_pkg_report_option object represents a package definition optional
29 reporting classification. FS::part_pkg_report_option inherits from
30 FS::Record. The following fields are currently supported:
40 name - The name associated with the reporting option
44 disabled - set to 'Y' to prevent addition to new packages
55 Creates a new report option. To add the option to the database, see L<"insert">.
57 Note that this stores the hash reference, not a distinct copy of the hash it
58 points to. You can ask the object for a copy with the I<hash> method.
62 sub table { 'part_pkg_report_option'; }
66 Adds this record to the database. If there is an error, returns the error,
67 otherwise returns false.
73 Delete this record from the database.
78 return "Can't delete part_pkg_report_option records!";
81 =item replace OLD_RECORD
83 Replaces the OLD_RECORD with this one in the database. If there is an error,
84 returns the error, otherwise returns false.
90 Checks all fields to make sure this is a valid example. If there is
91 an error, returns the error, otherwise returns false. Called by the insert
96 # the check method should currently be supplied - FS::Record contains some
97 # data checking routines
103 $self->ut_numbern('num')
104 || $self->ut_text('name')
105 || $self->ut_enum('disabled', [ '', 'Y' ])
107 return $error if $error;
118 =item subsets OPTIONNUM, ...
120 Given a list of report_option numbers, determines all combinations of those
121 numbers that exist on actual package definitions. For each such combination,
122 returns an arrayref of report_option numbers, followed by an arrayref of
123 corresponding report class names. This is used for a search optimization.
127 # probably doesn't belong here, but there's not a better place for it
128 # and optimizations are, by nature, hackish
131 my ($self, @nums) = @_;
132 my @optionnames = map { "'report_option_$_'" } @nums;
133 my $where = "WHERE optionname IN(".join(',',@optionnames).")"
136 "SELECT pkgpart, replace(optionname, 'report_option_', '')::int AS num ".
137 "FROM part_pkg_option $where ".
138 "ORDER BY pkgpart, num";
140 "SELECT DISTINCT array_to_string(array_agg(num), ','), ".
141 "array_to_string(array_agg(name), ',') ".
142 "FROM ($subselect) AS x JOIN part_pkg_report_option USING (num) ".
145 my $sth = $dbh->prepare($select)
146 or die $dbh->errstr; # seriously, this should never happen
149 # return a pair of entries for the null set (conventionally we use zero
151 ( [ 0 ], [ '(empty class)' ],
152 # followed by the first two columns: report class numbers and names
153 map { [ split(',',$_->[0]) ],
154 [ split(',',$_->[1]) ] } @{ $sth->fetchall_arrayref }
162 Overlaps somewhat with pkg_class and pkg_category
166 L<FS::Record>, schema.html from the base documentation.