1 package OpenILS::Application::Circ::NonCat;
2 use base 'OpenILS::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 use OpenILS::Utils::CStoreEditor qw/:funcs/;
11 $Data::Dumper::Indent = 0;
13 my $U = "OpenILS::Application::AppUtils";
16 # returns ( $newid, $evt ). If $evt, then there was an error
17 sub create_non_cat_circ {
18 my( $staffid, $patronid, $circ_lib, $noncat_type, $circ_time, $editor ) = @_;
20 my( $id, $nct, $evt );
22 my $circ = Fieldmapper::action::non_cataloged_circulation->new;
24 $logger->activity("Creating non-cataloged circulation for ".
25 "staff $staffid, patron $patronid, location $circ_lib, and non-cat type $noncat_type");
27 $circ->patron($patronid);
28 $circ->staff($staffid);
29 $circ->circ_lib($circ_lib);
30 $circ->item_type($noncat_type);
31 $circ->circ_time($circ_time);
34 $evt = $editor->event unless
35 $circ = $editor->create_action_non_cataloged_circulation( $circ )
40 'open-ils.storage.direct.action.non_cataloged_circulation.create', $circ );
41 $evt = $U->DB_UPDATE_FAILED($circ) unless $id;
45 return( $circ, $evt );
49 __PACKAGE__->register_method(
50 method => "create_noncat_type",
51 api_name => "open-ils.circ.non_cat_type.create",
53 Creates a new non cataloged item type
54 @param authtoken The login session key
55 @param name The name of the new type
56 @param orgId The location where the type will live
57 @return The type object on success and the corresponding
61 sub create_noncat_type {
62 my( $self, $client, $authtoken, $name, $orgId, $interval, $inhouse ) = @_;
64 my $e = new_editor(authtoken=>$authtoken, xact=>1);
65 return $e->die_event unless $e->checkauth;
66 return $e->die_event unless $e->allowed('CREATE_NON_CAT_TYPE', $orgId);
68 # grab all of "my" non-cat types and see if one with
69 # the requested name already exists
70 my $types = retrieve_noncat_types_all($self, $client, $orgId);
72 if( $_->name eq $name ) {
74 return OpenILS::Event->new('NON_CAT_TYPE_EXISTS', payload => $name);
78 my $type = Fieldmapper::config::non_cataloged_type->new;
80 $type->owning_lib($orgId);
81 $type->circ_duration($interval);
82 $type->in_house( ($inhouse) ? 't' : 'f' );
84 $e->create_config_non_cataloged_type($type) or return $e->die_event;
91 __PACKAGE__->register_method(
92 method => "update_noncat_type",
93 api_name => "open-ils.circ.non_cat_type.update",
95 Updates a non-cataloged type object
96 @param authtoken The login session key
97 @param type The updated type object
98 @return The result of the DB update call unless a preceeding event occurs,
99 in which case the event will be returned
102 sub update_noncat_type {
103 my( $self, $client, $authtoken, $type ) = @_;
104 my $e = new_editor(xact=>1, authtoken=>$authtoken);
105 return $e->die_event unless $e->checkauth;
107 my $otype = $e->retrieve_config_non_cataloged_type($type->id)
108 or return $e->die_event;
110 return $e->die_event unless
111 $e->allowed('UPDATE_NON_CAT_TYPE', $otype->owning_lib);
113 $type->owning_lib($otype->owning_lib); # do not allow them to "move" the object
115 $e->update_config_non_cataloged_type($type) or return $e->die_event;
120 __PACKAGE__->register_method(
121 method => "retrieve_noncat_types_all",
122 api_name => "open-ils.circ.non_cat_types.retrieve.all",
124 Retrieves the non-cat types at the requested location as well
125 as those above and below the requested location in the org tree
126 @param orgId The base location at which to retrieve the type objects
127 @param depth Optional parameter to limit the depth of the tree
128 @return An array of non cat type objects or an event if an error occurs
131 sub retrieve_noncat_types_all {
132 my( $self, $client, $orgId, $depth ) = @_;
133 my $meth = 'open-ils.storage.ranged.config.non_cataloged_type.retrieve.atomic';
134 my $svc = 'open-ils.storage';
135 return $U->simplereq($svc, $meth, $orgId, $depth) if defined($depth);
136 return $U->simplereq($svc, $meth, $orgId);
141 __PACKAGE__->register_method(
142 method => 'fetch_noncat',
143 api_name => 'open-ils.circ.non_cataloged_circulation.retrieve',
149 my( $self, $conn, $auth, $circid ) = @_;
150 my $e = OpenILS::Utils::Editor->new( authtoken => $auth );
151 return $e->event unless $e->checkauth;
152 my $c = $e->retrieve_action_non_cataloged_circulation($circid)
154 if( $c->patron ne $e->requestor->id ) {
155 return $e->event unless $e->allowed('VIEW_CIRCULATIONS'); # XXX rely on editor perm
162 __PACKAGE__->register_method(
163 method => 'fetch_open_noncats',
165 api_name => 'open-ils.circ.open_non_cataloged_circulation.user',
167 Returns an id-list of non-cataloged circulations that are considered
168 open as of now. a circ is open if circ time + circ duration
169 (based on type) is > than now.
171 @param userid user to retrieve non-cat circs for
172 defaults to the session user
176 sub fetch_open_noncats {
177 my( $self, $conn, $auth, $userid ) = @_;
178 my $e = OpenILS::Utils::Editor->new( authtoken => $auth );
179 return $e->event unless $e->checkauth;
180 $userid ||= $e->requestor->id;
181 if( $e->requestor->id ne $userid ) {
182 return $e->event unless $e->allowed('VIEW_CIRCULATIONS'); # XXX rely on editor perm
185 'open-ils.storage.action.open_non_cataloged_circulation.user', $userid );
189 __PACKAGE__->register_method(
190 method => 'delete_noncat',
191 api_name => 'open-ils.circ.non_cataloged_type.delete',
194 my( $self, $conn, $auth, $typeid ) = @_;
195 my $e = new_editor(xact=>1, authtoken => $auth);
196 return $e->die_event unless $e->checkauth;
198 my $nc = $e->retrieve_config_non_cataloged_type($typeid)
199 or return $e->die_event;
201 $e->allowed('DELETE_NON_CAT_TYPE', $nc->owning_lib) # XXX rely on editor perm
202 or return $e->die_event;
204 # XXX Add checks to see if this type is in use by a transaction
206 $e->delete_config_non_cataloged_type($nc) or return $e->die_event;