X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Faccess_user.pm;h=366ae7ee8cb7a621ea94a4e63661037ff85f378a;hb=f8586b58f8913b133809556958b49a083454a962;hp=4a234ed003b2308e6770860feb344eaf6b59ba96;hpb=83ae7beac0d7dd6130c47327908afc33f31e725a;p=freeside.git diff --git a/FS/FS/access_user.pm b/FS/FS/access_user.pm index 4a234ed00..366ae7ee8 100644 --- a/FS/FS/access_user.pm +++ b/FS/FS/access_user.pm @@ -756,10 +756,88 @@ sub sched_item { sub locale { my $self = shift; return $self->{_locale} if exists($self->{_locale}); -warn "access_user->locale called\n"; $self->{_locale} = $self->option('locale'); } +=item get_page_pref PATH, NAME, TABLENUM + +Returns the user's page preference named NAME for the page at PATH. If the +page is a view or edit page or otherwise shows a single record at a time, +it should use TABLENUM to tell which record the preference is for. + +=cut + +sub get_page_pref { + my $self = shift; + my ($path, $prefname, $tablenum) = @_; + $tablenum ||= ''; + + my $access_user_page_pref = qsearchs('access_user_page_pref', { + path => $path, + usernum => $self->usernum, + tablenum => $tablenum, + prefname => $prefname, + }); + $access_user_page_pref ? $access_user_page_pref->prefvalue : ''; +} + +=item set_page_pref PATH, NAME, TABLENUM, VALUE + +Sets the user's page preference named NAME for the page at PATH. Use TABLENUM +as for get_page_pref. + +=cut + +sub set_page_pref { + my $self = shift; + my ($path, $prefname, $tablenum, $prefvalue) = @_; + $tablenum ||= ''; + + my $error; + my $access_user_page_pref = qsearchs('access_user_page_pref', { + path => $path, + usernum => $self->usernum, + tablenum => $tablenum, + prefname => $prefname, + }); + if ( $access_user_page_pref ) { + if ( $prefvalue eq $access_user_page_pref->get('prefvalue') ) { + return ''; + } + if ( length($prefvalue) > 0 ) { + $access_user_page_pref->set('prefvalue', $prefvalue); + $error = $access_user_page_pref->replace; + $error .= " (updating $prefname)" if $error; + } else { + $error = $access_user_page_pref->delete; + $error .= " (removing $prefname)" if $error; + } + } else { + if ( length($prefvalue) > 0 ) { + $access_user_page_pref = FS::access_user_page_pref->new({ + path => $path, + usernum => $self->usernum, + tablenum => $tablenum, + prefname => $prefname, + prefvalue => $prefvalue, + }); + $error = $access_user_page_pref->insert; + $error .= " (creating $prefname)" if $error; + } else { + return ''; + } + } + + return $error; +} + +#3.x + +sub saved_search { + my $self = shift; + qsearch('saved_search', { 'usernum' => $self->usernum }); +} + =back =head1 BUGS