bab6e5e5638dca4995c819b292a70cc981930eb0
[freeside.git] / FS / FS / pkg_class.pm
1 package FS::pkg_class;
2
3 use strict;
4 use vars qw( @ISA );
5 use FS::Record qw( qsearch );
6 use FS::part_pkg;
7
8 @ISA = qw( FS::Record );
9
10 =head1 NAME
11
12 FS::pkg_class - Object methods for pkg_class records
13
14 =head1 SYNOPSIS
15
16   use FS::pkg_class;
17
18   $record = new FS::pkg_class \%hash;
19   $record = new FS::pkg_class { '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::pkg_class object represents an package class.  Every package definition
32 (see L<FS::part_pkg>) has, optionally, a package class. FS::pkg_class inherits
33 from FS::Record.  The following fields are currently supported:
34
35 =over 4
36
37 =item classnum - primary key (assigned automatically for new package classes)
38
39 =item classname - Text name of this package class
40
41 =item disabled - Disabled flag, empty or 'Y'
42
43 =back
44
45 =head1 METHODS
46
47 =over 4
48
49 =item new HASHREF
50
51 Creates a new package class.  To add the package class to the database, see
52 L<"insert">.
53
54 =cut
55
56 sub table { 'pkg_class'; }
57
58 =item insert
59
60 Adds this package class to the database.  If there is an error, returns the
61 error, otherwise returns false.
62
63 =item delete
64
65 Deletes this package class from the database.  Only package classes with no
66 associated package definitions can be deleted.  If there is an error, returns
67 the error, otherwise returns false.
68
69 =cut
70
71 sub delete {
72   my $self = shift;
73
74   return "Can't delete an pkg_class with part_pkg records!"
75     if qsearch( 'part_pkg', { 'classnum' => $self->classnum } );
76
77   $self->SUPER::delete;
78 }
79
80 =item replace OLD_RECORD
81
82 Replaces 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 package class.  If there is an
88 error, returns the error, otherwise returns false.  Called by the insert and
89 replace methods.
90
91 =cut
92
93 sub check {
94   my $self = shift;
95
96   $self->ut_numbern('classnum')
97   or $self->ut_text('classname')
98   or $self->SUPER::check;
99
100 }
101
102 =back
103
104 =head1 BUGS
105
106 =head1 SEE ALSO
107
108 L<FS::Record>, L<FS::part_pkg>, schema.html from the base documentation.
109
110 =cut
111
112 1;
113