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/;
7 sub initialize { return 1; }
9 __PACKAGE__->register_method(
10 method => 'fetch_dates',
11 api_name => 'open-ils.actor.org_unit.closed.retrieve.all',
13 Retrieves a list of closed date object IDs
18 my( $self, $conn, $auth, $args ) = @_;
20 my $e = new_editor(authtoken=>$auth);
21 return $e->event unless $e->checkauth;
23 my $org = $$args{orgid} || $e->requestor->ws_ou;
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..
29 my $dates = $e->search_actor_org_unit_closed_date(
31 close_start => { ">=" => $start },
32 close_end => { "<=" => $end },
34 }, { idlist => $$args{idlist} } ) or return $e->event;
36 if(!$$args{idlist} and @$dates) {
37 $dates = [ sort { $a->close_start cmp $b->close_start } @$dates ];
43 __PACKAGE__->register_method(
44 method => 'fetch_date',
45 api_name => 'open-ils.actor.org_unit.closed.retrieve',
47 Retrieves a single date object
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;
60 __PACKAGE__->register_method(
61 method => 'delete_date',
62 api_name => 'open-ils.actor.org_unit.closed.delete',
64 Removes a single date object
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;
82 __PACKAGE__->register_method(
83 method => 'create_date',
84 api_name => 'open-ils.actor.org_unit.closed.create',
86 Creates a new org closed data
91 my( $self, $conn, $auth, $date ) = @_;
93 my $e = new_editor(authtoken=>$auth, xact =>1);
94 return $e->event unless $e->checkauth;
96 return $e->event unless $e->allowed( # rely on the editor perm eventually
97 'actor.org_unit.closed_date.create', $date->org_unit);
99 $e->create_actor_org_unit_closed_date($date) or return $e->event;
101 my $newobj = $e->retrieve_actor_org_unit_closed_date($date->id)
109 __PACKAGE__->register_method(
110 method => 'edit_date',
111 api_name => 'open-ils.actor.org_unit.closed.update',
113 Updates a closed date object
118 my( $self, $conn, $auth, $date ) = @_;
119 my $e = new_editor(authtoken=>$auth, xact =>1);
120 return $e->event unless $e->checkauth;
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)
126 return $e->event unless $e->allowed( # rely on the editor perm eventually
127 'actor.org_unit.closed_date.update', $odate->org_unit);
129 $e->update_actor_org_unit_closed_date($date) or return $e->event;
135 __PACKAGE__->register_method(
136 method => 'closed_dates_overlap',
137 api_name => 'open-ils.actor.org_unit.closed_date.overlap',
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
143 @param orgid The org unit in question
144 @param date The date to search
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;
152 'open-ils.storage.actor.org_unit.closed_date.overlap', $orgid, $date );