1 package FS::phone_type;
2 use base qw( FS::Record );
5 use FS::Record qw( qsearch ); # qsearchs );
9 FS::phone_type - Object methods for phone_type records
15 $record = new FS::phone_type \%hash;
16 $record = new FS::phone_type { 'column' => 'value' };
18 $error = $record->insert;
20 $error = $new_record->replace($old_record);
22 $error = $record->delete;
24 $error = $record->check;
28 An FS::phone_type object represents an phone number type (for example: Work,
29 Home, Mobile, Fax). FS::phone_type inherits from FS::Record. The following
30 fields are currently supported:
50 Creates a new type. To add the type to the database, see L<"insert">.
52 Note that this stores the hash reference, not a distinct copy of the hash it
53 points to. You can ask the object for a copy with the I<hash> method.
57 sub table { 'phone_type'; }
61 Adds this record to the database. If there is an error, returns the error,
62 otherwise returns false.
66 Delete this record from the database.
68 =item replace OLD_RECORD
70 Replaces the OLD_RECORD with this one in the database. If there is an error,
71 returns the error, otherwise returns false.
75 Checks all fields to make sure this is a valid type. If there is
76 an error, returns the error, otherwise returns false. Called by the insert
85 $self->ut_numbern('phonetypenum')
86 || $self->ut_number('weight')
87 || $self->ut_text('typename')
89 return $error if $error;
96 returns a list of phone_types.
100 sub get_phone_types {
101 ## not using Home and Fax right now. false laziness with /elements/contact.html
102 my @phone_types = qsearch({table=>'phone_type', order_by=>'ORDER BY weight DESC', extra_sql => " WHERE typename NOT IN ('Home','Fax')"});
106 # Used by FS::Setup to initialize a new database.
107 sub _populate_initial_data {
108 my ($class, %opts) = @_;
112 foreach ("Work", "Home", "Mobile", "Fax") {
113 my $object = $class->new({ 'typename' => $_,
116 my $error = $object->insert;
117 die "error inserting $class into database: $error\n"
127 # Used by FS::Upgrade to migrate to a new database.
131 return $class->_populate_initial_data(@_)
132 unless scalar( qsearch( 'phone_type', {} ) );
144 L<FS::contact_phone>, L<FS::Record>, schema.html from the base documentation.