]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/perlmods/lib/OpenILS/WWW/PhoneList/Base.pm
LP2045292 Color contrast for AngularJS patron bills
[working/Evergreen.git] / Open-ILS / src / perlmods / lib / OpenILS / WWW / PhoneList / Base.pm
1 # ---------------------------------------------------------------
2 # Copyright (C) 2011 Merrimack Valley Library Consortium
3 # Jason Stephenson <jstephenson@mvlc.org>
4
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
9
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 # ---------------------------------------------------------------
15 package OpenILS::WWW::PhoneList::Base;
16
17 use strict;
18 use warnings;
19 use Carp;
20 # A base class for generating phone list output.
21
22 use OpenILS::Application::AppUtils;
23
24 my %fields = (
25               columns => [],
26               perms => [],
27               user => undef,
28               authtoken => undef,
29               work_ou => undef,
30              );
31
32 sub new {
33     my $invocant = shift;
34     my $args = shift;
35     my $class = ref($invocant) || $invocant;
36     my $self = {
37                 _permitted => \%fields,
38                 %fields,
39                };
40     bless($self, $class);
41     $self->authtoken($args->{authtoken});
42     $self->user($args->{user});
43     $self->work_ou($args->{work_ou});
44     return $self;
45 }
46
47 sub checkperms {
48     my $self = shift;
49     my $rv = 0;
50     if ($self->perms && $self->user && $self->authtoken && $self->work_ou) {
51         my $r = OpenILS::Application::AppUtils->simplereq('open-ils.actor', 'open-ils.actor.user.perm.check', $self->authtoken, $self->user, $self->work_ou, $self->perms);
52         $rv = 1 unless(@$r);
53     }
54     return $rv;
55 }
56
57 # Return empty array ref.
58 sub next {
59     return [];
60 }
61
62 # Always return false.
63 sub query {
64     return 0;
65 }
66
67 sub AUTOLOAD {
68     my $self = shift;
69     my $class = ref($self) or croak "$self is not an object";
70     my $name = our $AUTOLOAD;
71
72     $name =~ s/.*://;
73
74     unless (exists $self->{_permitted}->{$name}) {
75         croak "Can't access '$name' field of class '$class'";
76     }
77
78     if (@_) {
79         return $self->{$name} = shift;
80     } else {
81         return $self->{$name};
82     }
83 }
84
85 1;