1 package FS::class_Common;
4 use base qw( FS::Record );
5 use FS::Record qw( qsearch qsearchs );
9 FS::class_Common - Base class for classification classes
13 use base qw( FS::class_Common );
14 use FS::category_table; #should use this
17 sub _target_table { 'table_name'; }
19 #optional for non-standard names
20 sub _target_column { 'classnum'; } #default is classnum
21 sub _category_table { 'table_name'; } #default is to replace s/class/category/
25 FS::class_Common is a base class for classes which provide a classification for
26 other classes, such as pkg_class or cust_class.
34 Creates a new classification. To add the classfication to the database, see
41 Adds this classification to the database. If there is an error, returns the
42 error, otherwise returns false.
46 Deletes this classification from the database. Only classifications with no
47 associated target objects can be deleted. If there is an error, returns
48 the error, otherwise returns false.
55 return "Can't delete a ". $self->table.
56 " with ". $self->_target_table. " records!"
57 if qsearch( $self->_target_table,
58 { $self->_target_column => $self->classnum }
64 =item replace OLD_RECORD
66 Replaces OLD_RECORD with this one in the database. If there is an error,
67 returns the error, otherwise returns false.
71 Checks all fields to make sure this is a valid package classification. If
72 there is an error, returns the error, otherwise returns false. Called by the
73 insert and replace methods.
80 $self->ut_numbern('classnum')
81 or $self->ut_text('classname')
82 or $self->ut_foreign_keyn( 'categorynum',
83 $self->_category_table,
86 or $self->ut_enum('disabled', [ '', 'Y' ] )
87 or $self->SUPER::check;
93 Returns the category record associated with this class, or false if there is
100 qsearchs($self->_category_table, { 'categorynum' => $self->categorynum } );
105 Returns the category name associated with this class, or false if there
111 my $category = shift->category;
112 $category ? $category->categoryname : '';
118 die "_target_table unspecified for $self";
123 sub _target_column { 'classnum'; }
125 use vars qw( %_category_table );
126 sub _category_table {
128 return $_category_table{ ref $self } ||= do {
129 my $category_table = $self->table;
130 $category_table =~ s/class/category/ # s/_class$/_category/
131 or die "can't determine an automatic category table for $category_table";
140 L<FS::category_Common>, L<FS::pkg_class>, L<FS::cust_class>