1 package OpenILS::Application::Circ::NonCat;
2 use base 'OpenSRF::Application';
3 use strict; use warnings;
4 use OpenSRF::EX qw(:try);
6 use OpenSRF::Utils::Logger qw(:logger);
7 use OpenILS::Application::AppUtils;
8 use OpenILS::Utils::Fieldmapper;
9 use OpenILS::Utils::Editor;
10 $Data::Dumper::Indent = 0;
12 my $U = "OpenILS::Application::AppUtils";
15 # returns ( $newid, $evt ). If $evt, then there was an error
16 sub create_non_cat_circ {
17 my( $staffid, $patronid, $circ_lib, $noncat_type, $circ_time ) = @_;
19 my( $id, $nct, $evt );
21 my $circ = Fieldmapper::action::non_cataloged_circulation->new;
23 $logger->activity("Creating non-cataloged circulation for ".
24 "staff $staffid, patron $patronid, location $circ_lib, and non-cat type $noncat_type");
26 $circ->patron($patronid);
27 $circ->staff($staffid);
28 $circ->circ_lib($circ_lib);
29 $circ->item_type($noncat_type);
30 $circ->circ_time($circ_time);
34 'open-ils.storage.direct.action.non_cataloged_circulation.create', $circ );
35 $evt = $U->DB_UPDATE_FAILED($circ) unless $id;
38 return( $circ, $evt );
42 __PACKAGE__->register_method(
43 method => "create_noncat_type",
44 api_name => "open-ils.circ.non_cat_type.create",
46 Creates a new non cataloged item type
47 @param authtoken The login session key
48 @param name The name of the new type
49 @param orgId The location where the type will live
50 @return The type object on success and the corresponding
54 sub create_noncat_type {
55 my( $self, $client, $authtoken, $name, $orgId ) = @_;
56 my( $staff, $evt ) = $U->checkses($authtoken);
59 # grab all of "my" non-cat types and see if one with
60 # the requested name already exists
61 my $types = $self->retrieve_noncat_types_all($client, $orgId);
64 return OpenILS::Event->new('NON_CAT_TYPE_EXISTS') if $_->name eq $name;
68 $evt = $U->check_perms( $staff->id, $orgId, 'CREATE_NON_CAT_TYPE' );
71 my $type = Fieldmapper::config::non_cataloged_type->new;
73 $type->owning_lib($orgId);
75 my $id = $U->simplereq(
77 'open-ils.storage.direct.config.non_cataloged_type.create', $type );
79 return $U->DB_UPDATE_FAILED($type) unless $id;
84 __PACKAGE__->register_method(
85 method => "update_noncat_type",
86 api_name => "open-ils.circ.non_cat_type.update",
88 Updates a non-cataloged type object
89 @param authtoken The login session key
90 @param type The updated type object
91 @return The result of the DB update call unless a preceeding event occurs,
92 in which case the event will be returned
95 sub update_noncat_type {
96 my( $self, $client, $authtoken, $type ) = @_;
97 my( $staff, $evt ) = $U->checkses($authtoken);
101 ($otype, $evt) = $U->fetch_non_cat_type($type->id);
104 $type->owning_lib($otype->owning_lib); # do not allow them to "move" the object
106 $evt = $U->check_perms( $staff->id, $type->owning_lib, 'UPDATE_NON_CAT_TYPE' );
109 return $U->simplereq(
111 'open-ils.storage.direct.config.non_cataloged_type.update', $type );
114 __PACKAGE__->register_method(
115 method => "retrieve_noncat_types_all",
116 api_name => "open-ils.circ.non_cat_types.retrieve.all",
118 Retrieves the non-cat types at the requested location as well
119 as those above and below the requested location in the org tree
120 @param orgId The base location at which to retrieve the type objects
121 @param depth Optional parameter to limit the depth of the tree
122 @return An array of non cat type objects or an event if an error occurs
125 sub retrieve_noncat_types_all {
126 my( $self, $client, $orgId, $depth ) = @_;
127 my $meth = 'open-ils.storage.ranged.config.non_cataloged_type.retrieve.atomic';
128 my $svc = 'open-ils.storage';
129 return $U->simplereq($svc, $meth, $orgId, $depth) if defined($depth);
130 return $U->simplereq($svc, $meth, $orgId);
135 __PACKAGE__->register_method(
136 method => 'fetch_noncat',
137 api_name => 'open-ils.circ.non_cataloged_circulation.retrieve',
143 my( $self, $conn, $auth, $circid ) = @_;
144 my $e = OpenILS::Utils::Editor->new( authtoken => $auth );
145 return $e->event unless $e->checkauth;
146 return $e->event unless $e->allowed('VIEW_CIRCULATIONS'); # XXX rely on editor perm
147 my $c = $e->retrieve_action_non_cataloged_circulation($circid)
154 __PACKAGE__->register_method(
155 method => 'fetch_open_noncats',
156 api_name => 'open-ils.circ.open_non_cataloged_circulation.user',
158 Returns an id-list of non-cataloged circulations that are considered
159 open as of now. a circ is open if circ time + circ duration
160 (based on type) is > than now.
162 @param userid user to retrieve non-cat circs for
163 defaults to the session user
167 sub fetch_open_noncats {
168 my( $self, $conn, $auth, $userid ) = @_;
169 my $e = OpenILS::Utils::Editor->new( authtoken => $auth );
170 return $e->event unless $e->checkauth;
171 return $e->event unless $e->allowed('VIEW_CIRCULATIONS'); # XXX rely on editor perm
172 $userid ||= $e->requestor->id;
174 'open-ils.storage.action.open_non_cataloged_circulation.user', $userid );
178 __PACKAGE__->register_method(
179 method => 'delete_noncat',
180 api_name => 'open-ils.circ.non_cataloged_type.delete',
183 my( $self, $conn, $auth, $typeid ) = @_;
184 my $e = OpenILS::Utils::Editor->new( authtoken => $auth );
185 return $e->event unless $e->checkauth;
187 my $nc = $e->retrieve_config_non_cataloged_type($typeid)
190 $e->allowed('DELETE_NON_CAT_TYPE', $nc->owning_lib) # XXX rely on editor perm
193 $e->delete_config_non_cataloged_type($nc) or return $e->event;