1 package FS::contact_phone;
2 use base qw( FS::Record );
5 use FS::Record qw( qsearch qsearchs );
11 FS::contact_phone - Object methods for contact_phone records
15 use FS::contact_phone;
17 $record = new FS::contact_phone \%hash;
18 $record = new FS::contact_phone { 'column' => 'value' };
20 $error = $record->insert;
22 $error = $new_record->replace($old_record);
24 $error = $record->delete;
26 $error = $record->check;
30 An FS::contact_phone object represents a contatct's phone number.
31 FS::contact_phone inherits from FS::Record. The following fields are currently supported:
68 Creates a new phone number. To add the phone number to the database, see
71 Note that this stores the hash reference, not a distinct copy of the hash it
72 points to. You can ask the object for a copy with the I<hash> method.
76 sub table { 'contact_phone'; }
80 Adds this record to the database. If there is an error, returns the error,
81 otherwise returns false.
85 Delete this record from the database.
87 =item replace OLD_RECORD
89 Replaces the OLD_RECORD with this one in the database. If there is an error,
90 returns the error, otherwise returns false.
94 Checks all fields to make sure this is a valid phone number. If there is
95 an error, returns the error, otherwise returns false. Called by the insert
104 $self->ut_numbern('contactphonenum')
105 || $self->ut_number('contactnum')
106 || $self->ut_number('phonetypenum')
107 || $self->ut_text('countrycode')
108 || $self->ut_text('phonenum')
109 || $self->ut_textn('extension')
111 return $error if $error;
113 #strip non-digits, UI should format numbers per countrycode
114 (my $phonenum = $self->phonenum ) =~ s/\D//g;
115 $self->phonenum($phonenum);
120 sub phonenum_pretty {
123 #until/unless we have the upgrade strip all whitespace
124 (my $phonenum = $self->phonenum ) =~ s/\D//g;
126 if ( $self->countrycode == 1 ) {
128 $phonenum =~ /^(\d{3})(\d{3})(\d{4})(\d*)$/
129 or return $self->phonenum; #wtf?
131 $phonenum = "($1) $2-$3";
132 $phonenum .= " x$4" if $4;
136 warn "don't know how to format phone numbers for country +". $self->countrycode;
137 #also, the UI doesn't have a good way for you to enter them yet or parse a countrycode from the number
138 return $self->phonenum;
145 qsearchs( 'contact', { 'contactnum' => $self->contactnum } );
150 qsearchs('phone_type', { 'phonetypenum' => $self->phonetypenum } );
155 $self->phone_type->typename;
164 L<FS::contact>, L<FS::Record>