1 package FS::contact_phone;
2 use base qw( FS::Record );
5 use FS::Record qw( qsearch qsearchs );
10 FS::contact_phone - Object methods for contact_phone records
14 use FS::contact_phone;
16 $record = new FS::contact_phone \%hash;
17 $record = new FS::contact_phone { 'column' => 'value' };
19 $error = $record->insert;
21 $error = $new_record->replace($old_record);
23 $error = $record->delete;
25 $error = $record->check;
29 An FS::contact_phone object represents a contatct's phone number.
30 FS::contact_phone inherits from FS::Record. The following fields are currently supported:
67 Creates a new phone number. To add the phone number to the database, see
70 Note that this stores the hash reference, not a distinct copy of the hash it
71 points to. You can ask the object for a copy with the I<hash> method.
75 sub table { 'contact_phone'; }
79 Adds this record to the database. If there is an error, returns the error,
80 otherwise returns false.
84 Delete this record from the database.
86 =item replace OLD_RECORD
88 Replaces the OLD_RECORD with this one in the database. If there is an error,
89 returns the error, otherwise returns false.
93 Checks all fields to make sure this is a valid phone number. If there is
94 an error, returns the error, otherwise returns false. Called by the insert
103 $self->ut_numbern('contactphonenum')
104 || $self->ut_number('contactnum')
105 || $self->ut_number('phonetypenum')
106 || $self->ut_text('countrycode')
107 || $self->ut_text('phonenum')
108 || $self->ut_textn('extension')
110 return $error if $error;
112 #strip non-digits, UI should format numbers per countrycode
113 (my $phonenum = $self->phonenum ) =~ s/\D//g;
114 $self->phonenum($phonenum);
119 sub phonenum_pretty {
122 #until/unless we have the upgrade strip all whitespace
123 (my $phonenum = $self->phonenum ) =~ s/\D//g;
125 if ( $self->countrycode == 1 ) {
127 $phonenum =~ /^(\d{3})(\d{3})(\d{4})(\d*)$/
128 or return $self->phonenum; #wtf?
130 $phonenum = "($1) $2-$3";
131 $phonenum .= " x$4" if $4;
135 warn "don't know how to format phone numbers for country +". $self->countrycode;
136 #also, the UI doesn't have a good way for you to enter them yet or parse a countrycode from the number
137 return $self->phonenum;
144 qsearchs( 'contact', { 'contactnum' => $self->contactnum } );
153 L<FS::contact>, L<FS::Record>