You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ngcp-panel/lib/NGCP/Panel/Utils/Subscriber.pm

114 lines
2.8 KiB

package NGCP::Panel::Utils::Subscriber;
use strict;
use warnings;
use Sipwise::Base;
use DBIx::Class::Exception;
sub get_usr_preference_rs {
my %params = @_;
my $c = $params{c};
my $attribute = $params{attribute};
my $prov_subscriber= $params{prov_subscriber};
my $preference = $c->model('DB')->resultset('voip_preferences')->find({
attribute => $attribute, 'usr_pref' => 1,
})->voip_usr_preferences->search_rs({
subscriber_id => $prov_subscriber->id,
});
return $preference;
}
sub period_as_string {
my $set = shift;
my @wdays = (qw/
invalid Sunday Monday Tuesday Wednesday Thursday Friday Saturday
/);
my @months = (qw/
invalid January February March April May June July August September October November December
/);
my $string = "";
foreach my $type(qw/year month mday wday hour minute/) {
my $s = $set->{$type};
if(defined $s) {
given($type) {
when(/^month$/) {
my ($from, $to) = split /\-/, $s;
$s = $months[$from];
$s .= '-'.$months[$to] if defined($to);
}
when(/^wday$/) {
my ($from, $to) = split /\-/, $s;
$s = $wdays[$from];
$s .= '-'.$wdays[$to] if defined($to);
}
}
}
$string .= "$type { $s } " if defined($s);
}
return $string;
}
sub destination_as_string {
my $destination = shift;
my $dest = $destination->{destination};
if($dest =~ /\@voicebox\.local$/) {
return "VoiceMail";
} elsif($dest =~ /\@fax2mail\.local$/) {
return "Fax2Mail";
} elsif($dest =~ /\@conference\.local$/) {
return "Conference";
} elsif($dest =~ /^sip:callingcard\@app\.local$/) {
return "CallingCard";
} elsif($dest =~ /^sip:callthrough\@app\.local$/) {
return "CallThrough";
} elsif($dest =~ /^sip:localuser\@.+\.local$/) {
return "Local Subscriber";
} else {
my $d = $dest;
$d =~ s/sip:(.+)\@.+$/$1/;
if($d =~ /^\d+$/) {
return $d;
} else {
return $dest;
}
}
}
1;
=head1 NAME
NGCP::Panel::Utils::Subscriber
=head1 DESCRIPTION
A temporary helper to manipulate subscriber data
=head1 METHODS
=head2 get_usr_preference_rs
Parameters:
c The controller
prov_subscriber The provisioning_voip_subscriber row
attribute The name of the usr preference
Returns a result set for the voip_usr_preference of the given subscriber.
=head1 AUTHOR
Andreas Granig,
=head1 LICENSE
This library is free software. You can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
# vim: set tabstop=4 expandtab: