Skip to content
Snippets Groups Projects
Commit efb3957d authored by Dorian Merz's avatar Dorian Merz Committed by Robert Lange
Browse files

refs #18943 [finc] FincLibero refactoring

* move some functions from TUF FincLibero to LiberoDingTrait
* also refs #17230
parent c5b93395
No related merge requests found
...@@ -282,6 +282,60 @@ trait LiberoDingTrait ...@@ -282,6 +282,60 @@ trait LiberoDingTrait
return $this->getLiberoDingResult($result, 'removeMySystemMessages'); 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. * Change values of users profile.
* *
...@@ -365,6 +419,18 @@ trait LiberoDingTrait ...@@ -365,6 +419,18 @@ trait LiberoDingTrait
$this->config['LiberoDing']['restrictedUserGroups'] : []; $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 * This method queries the LiberoDing-ILS for a patron's current profile
* information. * information.
...@@ -574,4 +640,152 @@ trait LiberoDingTrait ...@@ -574,4 +640,152 @@ trait LiberoDingTrait
} }
return true; 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 [];
}
} }
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