From efb3957d591e890be72f46bc9f0c57f703b08e94 Mon Sep 17 00:00:00 2001 From: Dorian Merz <merz@ub.uni-leipzig.de> Date: Mon, 25 Jan 2021 14:01:06 +0100 Subject: [PATCH] refs #18943 [finc] FincLibero refactoring * move some functions from TUF FincLibero to LiberoDingTrait * also refs #17230 --- .../src/finc/ILS/Driver/LiberoDingTrait.php | 214 ++++++++++++++++++ 1 file changed, 214 insertions(+) diff --git a/module/finc/src/finc/ILS/Driver/LiberoDingTrait.php b/module/finc/src/finc/ILS/Driver/LiberoDingTrait.php index 7216649a848..669e122b3fd 100644 --- a/module/finc/src/finc/ILS/Driver/LiberoDingTrait.php +++ b/module/finc/src/finc/ILS/Driver/LiberoDingTrait.php @@ -282,6 +282,60 @@ trait LiberoDingTrait return $this->getLiberoDingResult($result, 'removeMySystemMessages'); } + /** + * Lock account of current user. + * + * @param array $patron Array returned from patronLogin() + * + * @return array + * @throws \Exception + * @throws ILSException + */ + public function setLockMyAccount($patron) + { + $params = $this->getLiberoDingRequestParams(); + $params['memberCode'] = $patron['cat_username']; + $params['password'] = $patron['cat_password']; + try { + $result = $this->httpService->get( + $this->getWebScraperUrl() .'lockMyAccount.jsp', + $params, + null, + $this->getLiberoDingRequestHeaders() + ); + } catch (\Exception $e) { + throw new ILSException($e->getMessage()); + } + if (!$result->isSuccess()) { + // Log error for debugging + $this->debug( + 'HTTP status ' . $result->getStatusCode() . + ' received' + ); + return false; + } + // Log error for debugging + if( true === ($bool = $this->getLiberoDingResultBool($result))) { + // Remove explicitly session vars of PAIA connection + // Compliance security issue + $session = $this->getSession(); + foreach ( + [ + 'patron', + 'access_token', + 'scope', + 'expires_in', + 'borrower_id' + ] as $v + ) { + if ($session->$v) { + unset($session->$v); + } + } + } + return $bool; + } + /** * Change values of users profile. * @@ -365,6 +419,18 @@ trait LiberoDingTrait $this->config['LiberoDing']['restrictedUserGroups'] : []; } + /** + * Return an integer how many entries should be displayed at loan history view. + * Helper method to avoid twice config loading at MyResearchController. + * + * @return int Default 20 to avoid empty standard view. + */ + public function getItemsPerViewLoanHistory() + { + return isset($this->config['LiberoDing']['itemsPerPageLoanHistory']) ? + $this->config['LiberoDing']['itemsPerPageLoanHistory'] : 20; + } + /** * This method queries the LiberoDing-ILS for a patron's current profile * information. @@ -574,4 +640,152 @@ trait LiberoDingTrait } return true; } + + + /** + * Customized getMyLoanHistory + * + * @param array $patron Array returned from patronLogin() + * @param int $lastLine Integer until LiberoDing should process history + * incrementally + * + * @return array $retval + * - ['items'] Array with items of loan history + * - ['total'] Maximum entries at loan history + * @throws \Exception + * @throws ILSException + */ + public function getMyLoanHistory($patron, $lastLine) + { + $params = $this->getLiberoDingRequestParams(); + $params['memberCode'] = $patron['cat_username']; + $params['password'] = $patron['cat_password']; + $params['pageNumber'] = 1; + try { + $result = $this->httpService->get( + $this->getWebScraperUrl() . 'getMyLoanHistory.jsp', + $params, + null, + $this->getLiberoDingRequestHeaders() + ); + } catch (\Exception $e) { + throw new ILSException($e->getMessage()); + } + if (!$result->isSuccess()) { + // log error for debugging + $this->debug( + 'HTTP status ' . $result->getStatusCode() . + ' received' + ); + return false; + } + // get result as array + $details = json_decode($result->getBody(), true); + if (!is_array($details) + || !isset($details["errorcode"]) + || $details["errorcode"] != 0 + ) { + return false; + } + $retval = []; + $retval['total'] = $details['rowCount']; + $retval['items'] = $details['getMyLoanHistory']; + // Check if more entries are required than in first called. + if (count($details['getMyLoanHistory']) < $lastLine) { + // iteration over Libero view pager and security anchor to not iterate + // over more pages than exists + for ($page = 2; $page <= $details['pageCount']; $page++) { + // overwrite param pageNumber + $params['pageNumber'] = $page; + try { + $result = $this->httpService->get( + $this->getWebScraperUrl() . 'getMyLoanHistory.jsp', + $params, + null, + $this->getLiberoDingRequestHeaders() + ); + } catch (\Exception $e) { + throw new ILSException($e->getMessage()); + } + if (!$result->isSuccess()) { + // log error for debugging + $this->debug( + 'HTTP status ' . $result->getStatusCode() . + ' received' + ); + return false; + } + // merge with previous request + $retval['items'] = array_merge( + $retval['items'], + $this->getLiberoDingResult($result, 'getMyLoanHistory') + ); + // If there are requested lines collected break the iteration + if (count($retval['items']) > $lastLine) { + break; + } + } + } + // refs #11535 enable getDriverForILSRecord + foreach ($retval['items'] as &$current) { + $current['id'] = + $this->getAlternativeItemId($current['barcode'], "barcode"); + } + return $retval; + } + + + /** + * Return count of all items at getMyLoanHistory + * + * @param array $patron Array returned from patronLogin() + * + * @return array Array with items of loan history + * - ['total'] Maximum entries at loan history + * @access public + * @throws Exception + * @throws ILSException + */ + public function getMyLoanHistoryItems($patron) + { + $params = $this->getLiberoDingRequestParams(); + $params['memberCode'] = $patron['cat_username']; + $params['password'] = $patron['cat_password']; + $params['pageNumber'] = 1; + try { + $result = $this->httpService->get( + $this->getWebScraperUrl() . 'getMyLoanHistory.jsp', + $params, + null, + $this->_getLiberoDingRequestHeaders() + ); + } catch (\Exception $e) { + throw new ILSException($e->getMessage()); + } + if (!$result->isSuccess()) { + // log error for debugging + $this->debug( + 'HTTP status ' . $result->getStatusCode() . + ' received' + ); + return false; + } + // get result as array + $details = json_decode($result->getBody(), true); + if (!is_array($details) + || !isset($details["errorcode"]) + || $details["errorcode"] != 0 + ) { + return false; + } + + if ($details['rowCount'] > 0) { + return (array_map( + function ($n) { + return sprintf('fake_%03d', $n); + }, range(1, $details['rowCount']) + )); + } + return []; + } } -- GitLab