1 package FS::contact_phone;
2 use base qw( FS::Record );
8 FS::contact_phone - Object methods for contact_phone records
12 use FS::contact_phone;
14 $record = new FS::contact_phone \%hash;
15 $record = new FS::contact_phone { 'column' => 'value' };
17 $error = $record->insert;
19 $error = $new_record->replace($old_record);
21 $error = $record->delete;
23 $error = $record->check;
27 An FS::contact_phone object represents a contatct's phone number.
28 FS::contact_phone inherits from FS::Record. The following fields are currently supported:
65 Creates a new phone number. To add the phone number to the database, see
68 Note that this stores the hash reference, not a distinct copy of the hash it
69 points to. You can ask the object for a copy with the I<hash> method.
73 sub table { 'contact_phone'; }
77 Adds this record to the database. If there is an error, returns the error,
78 otherwise returns false.
82 Delete this record from the database.
84 =item replace OLD_RECORD
86 Replaces the OLD_RECORD with this one in the database. If there is an error,
87 returns the error, otherwise returns false.
91 Checks all fields to make sure this is a valid phone number. If there is
92 an error, returns the error, otherwise returns false. Called by the insert
101 $self->ut_numbern('contactphonenum')
102 || $self->ut_number('contactnum')
103 || $self->ut_number('phonetypenum')
104 || $self->ut_text('countrycode')
105 || $self->ut_text('phonenum')
106 || $self->ut_textn('extension')
108 return $error if $error;
110 #strip non-digits, UI should format numbers per countrycode
111 (my $phonenum = $self->phonenum ) =~ s/\D//g;
112 $self->phonenum($phonenum);
117 sub phonenum_pretty {
120 #until/unless we have the upgrade strip all whitespace
121 (my $phonenum = $self->phonenum ) =~ s/\D//g;
123 if ( $self->countrycode == 1 ) {
125 $phonenum =~ /^(\d{3})(\d{3})(\d{4})(\d*)$/
126 or return $self->phonenum; #wtf?
128 $phonenum = "($1) $2-$3";
129 $phonenum .= " x$4" if $4;
133 warn "don't know how to format phone numbers for country +". $self->countrycode;
134 #also, the UI doesn't have a good way for you to enter them yet or parse a countrycode from the number
135 return $self->phonenum;
142 $self->phone_type->typename;
151 L<FS::contact>, L<FS::Record>