/** * Retrieve a batch of documents. * * @param array $ids Array of document identifiers * @param ParamBag $params Search backend parameters * * @return RecordCollectionInterface */ 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; // Retrieve records a page at a time: $results = false; while (count($ids) > 0) { $currentPage = array_splice($ids, 0, $pageSize, []); try { $response = $this->connector->getRecords($currentPage, $this->connector->getInstitutionCode(), $onCampus); } catch (\Exception $e) { throw new BackendException($e->getMessage(), $e->getCode(), $e); } $next = $this->createRecordCollection($response); if (!$results) { $results = $next; } else { foreach ($next->getRecords() as $record) { $results->add($record); } } } $this->injectSourceIdentifier($results); return $results; }
/** * Retrieves multiple documents specified by the ID. * * @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, $onCampus = false) { $recordIds = array_map(function ($recordId) { list(, $recordId) = explode('.', $recordId, 2); return $recordId; }, $recordIds); return parent::getRecords($recordIds, $inst_code, $onCampus); }