From 8c18199d1a3e303aea588ff1809a1d5b5d285acf Mon Sep 17 00:00:00 2001 From: haydenyoung Date: Wed, 9 Jan 2019 21:47:30 +0800 Subject: [PATCH] Restructure derivative assets (thumbnails/previews) to be stored as children of the parent original asset. Allow for category to be loaded without associated items. --- build.properties.example | 2 +- manifest.xml | 6 +- plugins/jcar/dspace/dspace.php | 128 ++++++++++++------ plugins/jcar/dspace/dspace.xml | 14 +- .../language/en-GB/en-GB.plg_jcar_dspace.ini | 3 - 5 files changed, 91 insertions(+), 62 deletions(-) diff --git a/build.properties.example b/build.properties.example index d7ea397..1156800 100644 --- a/build.properties.example +++ b/build.properties.example @@ -2,4 +2,4 @@ id=dspace src=. path.joomla=/var/www/html/ package.extensions= -package.version=1.0.2 +package.version=1.1.0 diff --git a/manifest.xml b/manifest.xml index 493c260..08fe532 100644 --- a/manifest.xml +++ b/manifest.xml @@ -6,11 +6,11 @@ plg_jcar_dspace plugin jcar - 1.0.2 + 1.1.0 site - https://github.com/knowledgearcdotorg/jcar-dspace-plugin/releases/tag/1.0.2 + https://github.com/knowledgearcdotorg/jcar-dspace-plugin/releases/tag/1.1.0 - https://github.com/knowledgearcdotorg/jcar-dspace-plugin/releases/download/1.0.2/plg_jcar_dspace.zip + https://github.com/knowledgearcdotorg/jcar-dspace-plugin/releases/download/1.1.0/plg_jcar_dspace.zip stable diff --git a/plugins/jcar/dspace/dspace.php b/plugins/jcar/dspace/dspace.php index 864cc05..f32c566 100644 --- a/plugins/jcar/dspace/dspace.php +++ b/plugins/jcar/dspace/dspace.php @@ -74,11 +74,16 @@ public function onJCarCategoriesRetrieve() * category and paging information to allow for browsing across the entire * recordset. * - * @return A DSpace collection's information, the items within the + * @param int $id The id of an item to retrieve from the + * DSpace archive. + * @param bool $loadItems True if items should be loaded, false + * otherwises. Defaults to true. + * + * @return stdClass A DSpace collection's information, the items within the * category and paging information to allow for browsing across the entire * recordset. */ - public function onJCarCategoryRetrieve($id) + public function onJCarCategoryRetrieve($id, $loadItems = true) { $category = null; @@ -104,8 +109,11 @@ public function onJCarCategoryRetrieve($id) $data = json_decode($response->body); $category = $this->parseCollection($data); - $category->items = $this->getItems($id); - $category->pagination = $this->getPagination(); + + if ($loadItems) { + $category->items = $this->getItems($id); + $category->pagination = $this->getPagination($id); + } } else { JLog::add(print_r($response, true), JLog::DEBUG, 'jcardspace'); @@ -284,7 +292,7 @@ public function getCommunity($id) $id = JCarHelper::parseId($id); - $endpoint = '/communities/'.(int)$id.'.json?collections=true'; + $endpoint = '/communities/'.(int)$id.'.json?collections=true&children=true'; $url = $this->params->get('rest_url').$endpoint; JLog::add($url, JLog::DEBUG, 'jcardspace'); @@ -321,10 +329,10 @@ private function parseCommunity($community) $community->copyright = $community->copyrightText; for ($i = 0; $i < count($community->subCommunities); $i++) { - $subCommunity = ArrayHelper($community->subCommunities, $i); + $subCommunity = ArrayHelper::getValue($community->subCommunities, $i); $subCommunity = $this->parseCommunity($subCommunity); - $community->subCommunities[$i] = subCommunity; + $community->subCommunities[$i] = $subCommunity; } for ($i = 0; $i < count($community->collections); $i++) { @@ -341,9 +349,9 @@ private function parseCommunity($community) * Parses a DSpace collection, adding additional content to the collection * object. * - * @param stdClass $collection The collection to parse. + * @param stdClass $collection The collection to parse. * - * @return stdClass A DSpace collection with additional content. + * @return stdClass A DSpace collection with additional content. * * @throws Exception Thrown if the API endpoint does not return the html * code 200. @@ -380,9 +388,9 @@ private function parseCollection($collection) * Gets a list of items based on a collection from the REST API-enabled * DSpace archive. * - * @param int $cid The id of a collection. + * @param int $cid The id of a collection. * - * @return mixed An item from the REST API-enabled DSpace archive, or + * @return mixed An item from the REST API-enabled DSpace archive, or * null if nothing could be found. * * @throws Exception Thrown if the API endpoint does not return the html @@ -390,7 +398,7 @@ private function parseCollection($collection) */ private function getItems($cid) { - $pagination = $this->getPagination(); + $pagination = $this->getPagination($cid); $items = array(); @@ -453,12 +461,12 @@ private function getItemsCount($cid) return 0; } - private function getPagination() + private function getPagination($id) { $app = JFactory::getApplication(); // @TODO these should be passed as method params. - $total = $this->getItemsCount($app->input->getInt('id')); + $total = $this->getItemsCount($id); $start = $app->input->getInt('limitstart', 0); $limit = $app->input->getInt('limit', 20); @@ -476,15 +484,13 @@ private function getPagination() */ private function getBundles($item) { + $hierarchicalBitstreams = []; + $url = $this->params->get('rest_url'); $url .= '/items/'.$item.'/bundles.json'; $url = new JUri($url); - if ($showBundles = $this->params->get('show_bundles', null)) { - $url->setVar('type', $showBundles); - } - JLog::add($url, JLog::DEBUG, 'jcardspace'); $http = JHttpFactory::getHttp(); @@ -495,39 +501,48 @@ private function getBundles($item) for ($i = 0; $i < count($bundles); $i++) { $bundle = ArrayHelper::getValue($bundles, $i); - $bitstreams = $bundle->bitstreams; - - for ($j = 0; $j < count($bitstreams); $j++) { - $bitstream = ArrayHelper::getValue($bitstreams, $j); - - if ($this->isBitstreamAccessible($bitstream)) { - if ((bool)$this->params->get('stream')) { - $url = new JUri('index.php'); - - $url->setQuery( - array( - 'option'=>'com_jcar', - 'view'=>'asset', - 'format'=>'raw', - 'id'=>$this->_name.':'.$bitstream->id, - 'name'=>$bitstream->name, - 'Itemid'=>JFactory::getApplication()->input->getInt('Itemid'))); + + if ($bundle->name != 'THUMBNAIL' && $bundle->name != 'TEXT') { + $bitstreams = $bundle->bitstreams; + + for ($j = 0; $j < count($bitstreams); $j++) { + $bitstream = ArrayHelper::getValue($bitstreams, $j); + + if ($this->isBitstreamAccessible($bitstream)) { + if ((bool)$this->params->get('stream')) { + $url = new JUri('index.php'); + + $url->setQuery( + array( + 'option'=>'com_jcar', + 'view'=>'asset', + 'format'=>'raw', + 'id'=>$this->_name.':'.$bitstream->id, + 'name'=>$bitstream->name, + 'Itemid'=>JFactory::getApplication()->input->getInt('Itemid'))); + } else { + $url = new JUri( + $this->params->get('rest_url'). + '/bitstreams/'. + $bitstream->id. + '/download'); + } + + $bitstream->url = (string)$url; + + if ($bundles[$i]->name == 'ORIGINAL') { + $bitstream->derivatives = $this->getDerivatives($bundles, $bundles[$i]); + } } else { - $url = new JUri( - $this->params->get('rest_url'). - '/bitstreams/'. - $bitstream->id. - '/download'); + $bitstream->url = null; } - $bundles[$i]->bitstreams[$j]->url = (string)$url; - } else { - $bundles[$i]->bitstreams[$j]->url = null; + $hierarchicalBitstreams[$bundle->name][] = $bitstream; } } } - return $bundles; + return $hierarchicalBitstreams; } else { JLog::add(print_r($response, true), JLog::DEBUG, 'jcardspace'); @@ -537,6 +552,31 @@ private function getBundles($item) } } + private function getDerivatives($bundles, $original) + { + $derivatives = []; + + foreach ($bundles as $bundle) { + if ($bundle->name == 'THUMBNAIL' || $bundle->name == 'TEXT') { + $fileInfo = pathinfo($bundle->bitstreams[0]->name); + + if (strcmp($original->bitstreams[0]->name, $fileInfo['filename']) === 0) { + $url = new JUri( + $this->params->get('rest_url'). + '/bitstreams/'. + $bundle->bitstreams[0]->id. + '/download'); + + $bundle->bitstreams[0]->url = (string)$url; + + $derivatives[$bundle->name] = $bundle->bitstreams[0]; + } + } + } + + return $derivatives; + } + private function isBitstreamAccessible($bitstream) { $url = new JUri( diff --git a/plugins/jcar/dspace/dspace.xml b/plugins/jcar/dspace/dspace.xml index ee0b29f..7e97588 100644 --- a/plugins/jcar/dspace/dspace.xml +++ b/plugins/jcar/dspace/dspace.xml @@ -2,12 +2,12 @@ plg_jcar_dspace KnowledgeArc - 2016-11-29 - Copyright (C) 2015-2016 KnowledgeArc Ltd. All rights reserved. + 2019-01-09 + Copyright (C) 2015-2019 KnowledgeArc Ltd. All rights reserved. GNU General Public License version 2 or later; see LICENSE.txt development@knowledgearc.com www.knowledgearc.org - 1.0.2 + 1.2.0-dev PLG_JCAR_DSPACE_XML_DESCRIPTION @@ -43,14 +43,6 @@
- -