Skip to content
Snippets Groups Projects
Commit 6a836c70 authored by Ere Maijala's avatar Ere Maijala Committed by Demian Katz
Browse files

Use the onCampus parameter properly when retrieving records from Primo.

parent 0677c055
Branches
Tags
No related merge requests found
......@@ -133,9 +133,13 @@ class Backend extends AbstractBackend implements RetrieveBatchInterface
*/
public function retrieve($id, ParamBag $params = null)
{
$onCampus = (null !== $params) ? $params->get('onCampus') : [false];
$onCampus = $onCampus ? $onCampus[0] : false;
try {
$response = $this->connector
->getRecord($id, $this->connector->getInstitutionCode());
->getRecord(
$id, $this->connector->getInstitutionCode(), $onCampus
);
} catch (\Exception $e) {
throw new BackendException(
$e->getMessage(),
......@@ -158,6 +162,9 @@ class Backend extends AbstractBackend implements RetrieveBatchInterface
*/
public function retrieveBatch($ids, ParamBag $params = null)
{
$onCampus = (null !== $params) ? $params->get('onCampus') : [false];
$onCampus = $onCampus ? $onCampus[0] : false;
// Load 100 records at a time; this is a good number to avoid memory
// problems while still covering a lot of ground.
$pageSize = 100;
......@@ -169,7 +176,7 @@ class Backend extends AbstractBackend implements RetrieveBatchInterface
try {
$response = $this->connector->getRecords(
$currentPage, $this->connector->getInstitutionCode()
$currentPage, $this->connector->getInstitutionCode(), $onCampus
);
} catch (\Exception $e) {
throw new BackendException(
......
......@@ -595,11 +595,12 @@ class Connector implements \Zend\Log\LoggerAwareInterface
*
* @param string $recordId The document to retrieve from the Primo API
* @param string $inst_code Institution code (optional)
* @param bool $onCampus Whether the user is on campus
*
* @throws \Exception
* @return string The requested resource
*/
public function getRecord($recordId, $inst_code = null)
public function getRecord($recordId, $inst_code = null, $onCampus = false)
{
// Query String Parameters
if (isset($recordId)) {
......@@ -607,7 +608,7 @@ class Connector implements \Zend\Log\LoggerAwareInterface
$qs[] = 'query=rid,exact,"' . urlencode(addcslashes($recordId, '"'))
. '"';
$qs[] = "institution=$inst_code";
$qs[] = "onCampus=true";
$qs[] = 'onCampus=' . ($onCampus ? 'true' : 'false');
$qs[] = "indx=1";
$qs[] = "bulkSize=1";
$qs[] = "loc=adaptor,primo_central_multiple_fe";
......@@ -626,11 +627,12 @@ class Connector implements \Zend\Log\LoggerAwareInterface
*
* @param array $recordIds The documents to retrieve from the Primo API
* @param string $inst_code Institution code (optional)
* @param bool $onCampus Whether the user is on campus
*
* @throws \Exception
* @return string The requested resource
*/
public function getRecords($recordIds, $inst_code = null)
public function getRecords($recordIds, $inst_code = null, $onCampus = false)
{
// Callback function for formatting IDs:
$formatIds = function ($i) {
......@@ -643,7 +645,7 @@ class Connector implements \Zend\Log\LoggerAwareInterface
$recordIds = array_map($formatIds, $recordIds);
$qs[] = 'query=rid,contains,' . urlencode(implode(' OR ', $recordIds));
$qs[] = "institution=$inst_code";
$qs[] = "onCampus=true";
$qs[] = 'onCampus=' . ($onCampus ? 'true' : 'false');
$qs[] = "indx=1";
$qs[] = "bulkSize=" . count($recordIds);
$qs[] = "loc=adaptor,primo_central_multiple_fe";
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment