ContentCafe summary of avaible item content
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sun, 1 May 2011 15:29:39 +0000 (15:29 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sun, 1 May 2011 15:29:39 +0000 (15:29 +0000)
Added "available_json" support for Content Cafe.  Returns and array of
available content for a given item, where the content type is mapped to
one of the Evergreen standard added content types, e.g. "summary",
"anotes", "reviews", ...

git-svn-id: svn://svn.open-ils.org/ILS/trunk@20367 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/lib/OpenILS/WWW/AddedContent/ContentCafe.pm

index c6e7f4f..9ecaebe 100644 (file)
@@ -206,6 +206,27 @@ sub summary_json {
         $self->fetch_content('AnnotationDetail', $key));
 }
 
+sub available_json {
+    my($self, $key) = @_;
+    my $xml = $self->fetch_content('AvailableContent', $key);
+    my $doc = XML::LibXML->new->parse_string($xml);
+
+    my @avail;
+    for my $node ($doc->findnodes('//*[text()="true"]')) {
+        push(@avail, 'summary') if $node->nodeName eq 'Annotation';
+        push(@avail, 'jacket') if $node->nodeName eq 'Jacket';
+        push(@avail, 'toc') if $node->nodeName eq 'TOC';
+        push(@avail, 'anotes') if $node->nodeName eq 'Biography';
+        push(@avail, 'excerpt') if $node->nodeName eq 'Excerpt';
+        push(@avail, 'reviews') if $node->nodeName eq 'Review';
+    }
+
+    return { 
+        content_type => 'text/plain', 
+        content => OpenSRF::Utils::JSON->perl2JSON(\@avail)
+    };
+}
+
 
 # --------------------------------------------------------------------------