return;
}
+__PACKAGE__->register_method(
+ "method" => "fetch_pattern_templates",
+ "api_name" => "open-ils.serial.pattern_template.retrieve.at",
+ "stream" => 1,
+ "signature" => {
+ "desc" => q{Return the set of pattern templates that are
+ visible to the specified library.},
+ "params" => [
+ {"desc" => "Authtoken", "type" => "string"},
+ {"desc" => "OU ID", "type" => "number"},
+ ],
+ return => {
+ desc => "stream of pattern templates",
+ type => "object", class => "spt"
+ }
+ }
+);
+
+sub fetch_pattern_templates {
+ my ($self, $client, $auth, $org_unit) = @_;
+
+ my $e = new_editor("authtoken" => $auth);
+ return $e->die_event unless $e->checkauth;
+
+ my $patterns = $e->json_query({
+ from => [ 'serial.pattern_templates_visible_to' => $org_unit ]
+ });
+$logger->info(Dumper($patterns)); use Data::Dumper;
+
+ $client->respond($e->retrieve_serial_pattern_template($_->{id}))
+ foreach (@$patterns);
+
+ $e->disconnect;
+ return undef;
+}
+
1;
);
CREATE INDEX serial_pattern_template_name_idx ON serial.pattern_template (evergreen.lowercase(name));
+CREATE OR REPLACE FUNCTION serial.pattern_templates_visible_to(org_unit INT) RETURNS SETOF serial.pattern_template AS $func$
+BEGIN
+ RETURN QUERY SELECT *
+ FROM serial.pattern_template spt
+ WHERE (
+ SELECT ARRAY_AGG(id)
+ FROM actor.org_unit_descendants(spt.owning_lib, spt.share_depth)
+ ) @@ org_unit::TEXT::QUERY_INT;
+END;
+$func$ LANGUAGE PLPGSQL;
+
-- COMMIT;