]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/lib/OpenILS/Application/Actor/ClosedDates.pm
Merge branch 'master' of git.evergreen-ils.org:Evergreen-DocBook into doc_consolidati...
[Evergreen.git] / Open-ILS / src / perlmods / lib / OpenILS / Application / Actor / ClosedDates.pm
1 package OpenILS::Application::Actor::ClosedDates;
2 use base 'OpenILS::Application';
3 use strict; use warnings;
4 use OpenSRF::EX qw(:try);
5 use OpenILS::Utils::Editor q/:funcs/;
6
7 sub initialize { return 1; }
8
9 __PACKAGE__->register_method( 
10         method => 'fetch_dates',
11         api_name        => 'open-ils.actor.org_unit.closed.retrieve.all',
12         signature       => q/
13                 Retrieves a list of closed date object IDs
14         /
15 );
16
17 sub fetch_dates {
18         my( $self, $conn, $auth, $args ) = @_;
19
20         my $e = new_editor(authtoken=>$auth);
21         return $e->event unless $e->checkauth;
22
23         my $org = $$args{orgid} || $e->requestor->ws_ou;
24         my @date = localtime;
25         my $start = $$args{start_date} ||  #default to today 
26                 ($date[5] + 1900) .'-'. ($date[4] + 1) .'-'. $date[3];
27         my $end = $$args{end_date} || '3000-01-01'; # Y3K, here I come..
28
29         my $dates = $e->search_actor_org_unit_closed_date( 
30                 { 
31                         close_start => { ">=" => $start }, 
32                         close_end       => { "<=" => $end },
33                         org_unit                => $org,
34                 }, { idlist             => $$args{idlist} } ) or return $e->event;
35
36         if(!$$args{idlist} and @$dates) {
37                 $dates = [ sort { $a->close_start cmp $b->close_start } @$dates ];
38         }
39
40         return $dates;
41 }
42
43 __PACKAGE__->register_method( 
44         method => 'fetch_date',
45         api_name        => 'open-ils.actor.org_unit.closed.retrieve',
46         signature       => q/
47                 Retrieves a single date object
48         /
49 );
50
51 sub fetch_date {
52         my( $self, $conn, $auth, $id ) = @_;
53         my $e = new_editor(authtoken=>$auth);
54         return $e->event unless $e->checkauth;
55         my $date = $e->retrieve_actor_org_unit_closed_date($id) or return $e->event;
56         return $date;
57 }
58
59
60 __PACKAGE__->register_method( 
61         method => 'delete_date',
62         api_name        => 'open-ils.actor.org_unit.closed.delete',
63         signature       => q/
64                 Removes a single date object
65         /
66 );
67
68 sub delete_date {
69         my( $self, $conn, $auth, $id ) = @_;
70         my $e = new_editor(authtoken=>$auth);
71         return $e->event unless $e->checkauth;
72         my $date = $e->retrieve_actor_org_unit_closed_date($id) or return $e->event;
73         return $e->event unless $e->allowed( # rely on the editor perm eventually
74                 'actor.org_unit.closed_date.delete', $date->org_unit);
75         $e->delete_actor_org_unit_closed_date($date) or return $e->event;
76         return 1;
77 }
78
79
80
81
82 __PACKAGE__->register_method( 
83         method => 'create_date',
84         api_name        => 'open-ils.actor.org_unit.closed.create',
85         signature       => q/
86                 Creates a new org closed data
87         /
88 );
89
90 sub create_date {
91         my( $self, $conn, $auth, $date ) = @_;
92
93         my $e = new_editor(authtoken=>$auth, xact =>1);
94         return $e->event unless $e->checkauth;
95         
96         return $e->event unless $e->allowed( # rely on the editor perm eventually
97                 'actor.org_unit.closed_date.create', $date->org_unit);
98
99         $e->create_actor_org_unit_closed_date($date) or return $e->event;
100
101         my $newobj = $e->retrieve_actor_org_unit_closed_date($date->id)
102                 or return $e->event;
103
104         $e->commit;
105         return $newobj;
106 }
107
108
109 __PACKAGE__->register_method(
110         method => 'edit_date',
111         api_name        => 'open-ils.actor.org_unit.closed.update',
112         signature       => q/
113                 Updates a closed date object
114         /
115 );
116
117 sub edit_date {
118         my( $self, $conn, $auth, $date ) = @_;
119         my $e = new_editor(authtoken=>$auth, xact =>1);
120         return $e->event unless $e->checkauth;
121         
122         # First make sure they have the right to update the selected date object
123         my $odate = $e->retrieve_actor_org_unit_closed_date($date->id) 
124                 or return $e->event;
125
126         return $e->event unless $e->allowed( # rely on the editor perm eventually
127                 'actor.org_unit.closed_date.update', $odate->org_unit);
128
129         $e->update_actor_org_unit_closed_date($date) or return $e->event;
130
131         return 1;
132 }
133
134
135 __PACKAGE__->register_method(
136         method  => 'closed_dates_overlap',
137         api_name        => 'open-ils.actor.org_unit.closed_date.overlap',
138         signature       => q/
139                 Returns an object with 'start' and 'end' fields 
140                 start is the first day the org is open going backwards from 
141                 'date'.  end is the next day the org is open going
142                 forward from 'date'.
143                 @param orgid The org unit in question
144                 @param date The date to search
145         /
146 );
147 sub closed_dates_overlap {
148         my( $self, $conn, $auth, $orgid, $date ) = @_;
149         my $e = new_editor(authtoken=>$auth);
150         return $e->event unless $e->checkauth;
151         return $e->request(
152                 'open-ils.storage.actor.org_unit.closed_date.overlap', $orgid, $date );
153 }
154
155
156
157
158 1;