/
MultiBackend.php
1340 lines (1277 loc) · 44.3 KB
/
MultiBackend.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Multiple Backend Driver.
*
* PHP version 8
*
* Copyright (C) The National Library of Finland 2012-2021.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category VuFind
* @package ILSdrivers
* @author Ere Maijala <ere.maijala@helsinki.fi>
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development:plugins:ils_drivers Wiki
*/
namespace VuFind\ILS\Driver;
use VuFind\Exception\ILS as ILSException;
use function call_user_func_array;
use function func_get_args;
use function in_array;
use function is_array;
use function is_callable;
use function is_int;
use function is_string;
use function strlen;
/**
* Multiple Backend Driver.
*
* This driver allows to use multiple backends determined by a record id or
* user id prefix (e.g. source.12345).
*
* @category VuFind
* @package ILSdrivers
* @author Ere Maijala <ere.maijala@helsinki.fi>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development:plugins:ils_drivers Wiki
*/
class MultiBackend extends AbstractMultiDriver
{
use \VuFind\Log\LoggerAwareTrait {
logError as error;
}
/**
* ID fields in holds
*/
public const HOLD_ID_FIELDS = ['id', 'item_id', 'cat_username'];
/**
* The default driver to use
*
* @var string
*/
protected $defaultDriver;
/**
* ILS authenticator
*
* @var \VuFind\Auth\ILSAuthenticator
*/
protected $ilsAuth;
/**
* An array of methods that should determine source from a specific parameter
* field
*
* @var array
*/
protected $sourceCheckFields = [
'cancelHolds' => 'cat_username',
'cancelILLRequests' => 'cat_username',
'cancelStorageRetrievalRequests' => 'cat_username',
'changePassword' => 'cat_username',
'getCancelHoldDetails' => 'cat_username',
'getCancelILLRequestDetails' => 'cat_username',
'getCancelStorageRetrievalRequestDetails' => 'cat_username',
'getMyFines' => 'cat_username',
'getMyProfile' => 'cat_username',
'getMyTransactionHistory' => 'cat_username',
'getMyTransactions' => 'cat_username',
'renewMyItems' => 'cat_username',
];
/**
* Methods that don't have parameters that allow the correct source to be
* determined. These methods are only supported for the default driver.
*/
protected $methodsWithNoSourceSpecificParameters = [
'findReserves',
'getCourses',
'getDepartments',
'getFunds',
'getInstructors',
'getNewItems',
'getOfflineMode',
'getSuppressedAuthorityRecords',
'getSuppressedRecords',
'loginIsHidden',
];
/**
* Constructor
*
* @param \VuFind\Config\PluginManager $configLoader Configuration loader
* @param \VuFind\Auth\ILSAuthenticator $ilsAuth ILS authenticator
* @param PluginManager $dm ILS driver manager
*/
public function __construct(
\VuFind\Config\PluginManager $configLoader,
\VuFind\Auth\ILSAuthenticator $ilsAuth,
PluginManager $dm
) {
parent::__construct($configLoader, $dm);
$this->ilsAuth = $ilsAuth;
}
/**
* Initialize the driver.
*
* Validate configuration and perform all resource-intensive tasks needed to
* make the driver active.
*
* @throws ILSException
* @return void
*/
public function init()
{
parent::init();
$this->defaultDriver = $this->config['General']['default_driver'] ?? null;
}
/**
* Get Status
*
* This is responsible for retrieving the status information of a certain
* record.
*
* @param string $id The record id to retrieve the holdings for
*
* @throws ILSException
* @return mixed On success, an associative array with the following keys:
* id, availability (boolean), status, location, reserve, callnumber.
*/
public function getStatus($id)
{
$source = $this->getSource($id);
if ($driver = $this->getDriver($source)) {
$status = $driver->getStatus($this->getLocalId($id));
return $this->addIdPrefixes($status, $source);
}
// Return an empty array if driver is not available; id can point to an ILS
// that's not currently configured.
return [];
}
/**
* Get Statuses
*
* This is responsible for retrieving the status information for a
* collection of records.
*
* @param array $ids The array of record ids to retrieve the status for
*
* @throws ILSException
* @return array An array of getStatus() return values on success.
*/
public function getStatuses($ids)
{
// Group records by source and request statuses from the drivers
$grouped = [];
foreach ($ids as $id) {
$source = $this->getSource($id);
if (!isset($grouped[$source])) {
$driver = $this->getDriver($source);
$grouped[$source] = [
'driver' => $driver,
'ids' => [],
];
}
$grouped[$source]['ids'][] = $id;
}
// Process each group
$results = [];
foreach ($grouped as $source => $current) {
// Get statuses only if a driver is configured for this source
if ($current['driver']) {
$localIds = array_map(
function ($id) {
return $this->getLocalId($id);
},
$current['ids']
);
try {
$statuses = $current['driver']->getStatuses($localIds);
} catch (ILSException $e) {
$statuses = array_map(
function ($id) {
return [
['id' => $id, 'error' => 'An error has occurred'],
];
},
$localIds
);
}
$statuses = array_map(
function ($status) use ($source) {
return $this->addIdPrefixes($status, $source);
},
$statuses
);
$results = array_merge($results, $statuses);
}
}
return $results;
}
/**
* Get Holding
*
* This is responsible for retrieving the holding information of a certain
* record.
*
* @param string $id The record id to retrieve the holdings for
* @param array $patron Patron data
* @param array $options Extra options (not currently used)
*
* @return array On success, an associative array with the following
* keys: id, availability (boolean), status, location, reserve, callnumber,
* duedate, number, barcode.
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function getHolding($id, array $patron = null, array $options = [])
{
$source = $this->getSource($id);
if ($driver = $this->getDriver($source)) {
// If the patron belongs to another source, just pass on an empty array
// to indicate that the patron has logged in but is not available for the
// current catalog.
if (
$patron
&& !$this->driverSupportsSource($source, $patron['cat_username'])
) {
$patron = [];
}
$holdings = $driver->getHolding(
$this->getLocalId($id),
$this->stripIdPrefixes($patron, $source),
$options
);
return $this->addIdPrefixes($holdings, $source);
}
// Return an empty array if driver is not available; id can point to an ILS
// that's not currently configured.
return [];
}
/**
* Get Purchase History
*
* This is responsible for retrieving the acquisitions history data for the
* specific record (usually recently received issues of a serial).
*
* @param string $id The record id to retrieve the info for
*
* @throws ILSException
* @return array An array with the acquisitions data on success.
*/
public function getPurchaseHistory($id)
{
$source = $this->getSource($id);
if ($driver = $this->getDriver($source)) {
return $driver->getPurchaseHistory($this->getLocalId($id));
}
// Return an empty array if driver is not available; id can point to an ILS
// that's not currently configured.
return [];
}
/**
* Get available login targets (drivers enabled for login)
*
* @return string[] Source ID's
*/
public function getLoginDrivers()
{
return $this->config['Login']['drivers'] ?? [];
}
/**
* Get default login driver
*
* @return string Default login driver or empty string
*/
public function getDefaultLoginDriver()
{
if (isset($this->config['Login']['default_driver'])) {
return $this->config['Login']['default_driver'];
}
$drivers = $this->getLoginDrivers();
if ($drivers) {
return $drivers[0];
}
return '';
}
/**
* Get New Items
*
* Retrieve the IDs of items recently added to the catalog.
*
* @param int $page Page number of results to retrieve (counting starts at 1)
* @param int $limit The size of each page of results to retrieve
* @param int $daysOld The maximum age of records to retrieve in days (max. 30)
* @param int $fundId optional fund ID to use for limiting results (use a value
* returned by getFunds, or exclude for no limit); note that "fund" may be a
* misnomer - if funds are not an appropriate way to limit your new item
* results, you can return a different set of values from getFunds. The
* important thing is that this parameter supports an ID returned by getFunds,
* whatever that may mean.
*
* @return array Associative array with 'count' and 'results' keys
*/
public function getNewItems($page, $limit, $daysOld, $fundId = null)
{
if ($driver = $this->getDriver($this->defaultDriver)) {
$result = $driver->getNewItems($page, $limit, $daysOld, $fundId);
if (isset($result['results'])) {
$result['results']
= $this->addIdPrefixes($result['results'], $this->defaultDriver);
}
return $result;
}
throw new ILSException('No suitable backend driver found');
}
/**
* Get Departments
*
* Obtain a list of departments for use in limiting the reserves list.
*
* @return array An associative array with key = dept. ID, value = dept. name.
*/
public function getDepartments()
{
if ($driver = $this->getDriver($this->defaultDriver)) {
return $driver->getDepartments();
}
throw new ILSException('No suitable backend driver found');
}
/**
* Get Instructors
*
* Obtain a list of instructors for use in limiting the reserves list.
*
* @return array An associative array with key = ID, value = name.
*/
public function getInstructors()
{
if ($driver = $this->getDriver($this->defaultDriver)) {
return $driver->getInstructors();
}
throw new ILSException('No suitable backend driver found');
}
/**
* Get Courses
*
* Obtain a list of courses for use in limiting the reserves list.
*
* @return array An associative array with key = ID, value = name.
*/
public function getCourses()
{
if ($driver = $this->getDriver($this->defaultDriver)) {
return $driver->getCourses();
}
throw new ILSException('No suitable backend driver found');
}
/**
* Find Reserves
*
* Obtain information on course reserves.
*
* @param string $course ID from getCourses (empty string to match all)
* @param string $inst ID from getInstructors (empty string to match all)
* @param string $dept ID from getDepartments (empty string to match all)
*
* @return mixed An array of associative arrays representing reserve items
*/
public function findReserves($course, $inst, $dept)
{
if ($driver = $this->getDriver($this->defaultDriver)) {
return $this->addIdPrefixes(
$driver->findReserves($course, $inst, $dept),
$this->defaultDriver,
['BIB_ID']
);
}
throw new ILSException('No suitable backend driver found');
}
/**
* Get Patron Profile
*
* This is responsible for retrieving the profile for a specific patron.
*
* @param array $patron The patron array
*
* @return mixed Array of the patron's profile data
*/
public function getMyProfile($patron)
{
$source = $this->getSource($patron['cat_username']);
if ($driver = $this->getDriver($source)) {
return $this->addIdPrefixes(
$driver->getMyProfile($this->stripIdPrefixes($patron, $source)),
$source
);
}
// Return an empty array if driver is not available; cat_username can point
// to an ILS that's not currently configured.
return [];
}
/**
* Get Patron Holds
*
* This is responsible for retrieving all holds by a specific patron.
*
* @param array $patron The patron array from patronLogin
*
* @return mixed Array of the patron's holds
*/
public function getMyHolds($patron)
{
$source = $this->getSource($patron['cat_username']);
$holds = $this->callMethodIfSupported(
$source,
__FUNCTION__,
func_get_args(),
true,
false
);
return $this->addIdPrefixes($holds, $source, self::HOLD_ID_FIELDS);
}
/**
* Get Patron Call Slips
*
* This is responsible for retrieving all call slips by a specific patron.
*
* @param array $patron The patron array from patronLogin
*
* @return mixed Array of the patron's holds
*/
public function getMyStorageRetrievalRequests($patron)
{
$source = $this->getSource($patron['cat_username']);
if ($driver = $this->getDriver($source)) {
$params = [
$this->stripIdPrefixes($patron, $source),
];
if (!$this->driverSupportsMethod($driver, __FUNCTION__, $params)) {
// Return empty array if not supported by the driver
return [];
}
$requests = $driver->getMyStorageRetrievalRequests(...$params);
return $this->addIdPrefixes($requests, $source);
}
throw new ILSException('No suitable backend driver found');
}
/**
* Check whether a hold or recall request is valid
*
* This is responsible for determining if an item is requestable
*
* @param string $id The Bib ID
* @param array $data An Array of item data
* @param array $patron An array of patron data
*
* @return mixed An array of data on the request including
* whether or not it is valid and a status message. Alternatively a boolean
* true if request is valid, false if not.
*/
public function checkRequestIsValid($id, $data, $patron)
{
if (!isset($patron['cat_username'])) {
return false;
}
$source = $this->getSource($patron['cat_username']);
if ($driver = $this->getDriver($source)) {
if (!$this->driverSupportsSource($source, $id)) {
return false;
}
return $driver->checkRequestIsValid(
$this->stripIdPrefixes($id, $source),
$this->stripIdPrefixes($data, $source),
$this->stripIdPrefixes($patron, $source)
);
}
return false;
}
/**
* Check whether a storage retrieval request is valid
*
* This is responsible for determining if an item is requestable
*
* @param string $id The Bib ID
* @param array $data An Array of item data
* @param array $patron An array of patron data
*
* @return mixed An array of data on the request including
* whether or not it is valid and a status message. Alternatively a boolean
* true if request is valid, false if not.
*/
public function checkStorageRetrievalRequestIsValid($id, $data, $patron)
{
$source = $this->getSource($patron['cat_username']);
if ($driver = $this->getDriver($source)) {
if (
!$this->driverSupportsSource($source, $id)
|| !is_callable([$driver, 'checkStorageRetrievalRequestIsValid'])
) {
return false;
}
return $driver->checkStorageRetrievalRequestIsValid(
$this->stripIdPrefixes($id, $source),
$this->stripIdPrefixes($data, $source),
$this->stripIdPrefixes($patron, $source)
);
}
return false;
}
/**
* Get Pick Up Locations
*
* This is responsible get a list of valid library locations for holds / recall
* retrieval
*
* @param array $patron Patron information returned by the patronLogin
* method.
* @param array $holdDetails Optional array, only passed in when getting a list
* in the context of placing or editing a hold. When placing a hold, it contains
* most of the same values passed to placeHold, minus the patron data. When
* editing a hold it contains all the hold information returned by getMyHolds.
* May be used to limit the pickup options or may be ignored. The driver must
* not add new options to the return array based on this data or other areas of
* VuFind may behave incorrectly.
*
* @return array An array of associative arrays with locationID and
* locationDisplay keys
*/
public function getPickUpLocations($patron = false, $holdDetails = null)
{
$source = $this->getSource(
$patron['cat_username'] ?? $holdDetails['id'] ?? $holdDetails['item_id']
?? ''
);
if ($driver = $this->getDriver($source)) {
if ($id = ($holdDetails['id'] ?? $holdDetails['item_id'] ?? '')) {
if (!$this->driverSupportsSource($source, $id)) {
// Return empty array since the sources don't match
return [];
}
}
$locations = $driver->getPickUpLocations(
$this->stripIdPrefixes($patron, $source),
$this->stripIdPrefixes(
$holdDetails,
$source,
self::HOLD_ID_FIELDS
)
);
return $this->addIdPrefixes($locations, $source);
}
throw new ILSException('No suitable backend driver found');
}
/**
* Get Default Pick Up Location
*
* Returns the default pick up location
*
* @param array $patron Patron information returned by the patronLogin
* method.
* @param array $holdDetails Optional array, only passed in when getting a list
* in the context of placing a hold; contains most of the same values passed to
* placeHold, minus the patron data. May be used to limit the pickup options
* or may be ignored.
*
* @return string A location ID
*/
public function getDefaultPickUpLocation($patron = false, $holdDetails = null)
{
$source = $this->getSource($patron['cat_username']);
if ($driver = $this->getDriver($source)) {
if ($holdDetails) {
if (!$this->driverSupportsSource($source, $holdDetails['id'])) {
// Return false since the sources don't match
return false;
}
}
$locations = $driver->getDefaultPickUpLocation(
$this->stripIdPrefixes($patron, $source),
$this->stripIdPrefixes($holdDetails, $source)
);
return $this->addIdPrefixes($locations, $source);
}
throw new ILSException('No suitable backend driver found');
}
/**
* Get request groups
*
* @param int $id BIB ID
* @param array $patron Patron information returned by the patronLogin
* method.
* @param array $holdDetails Optional array, only passed in when getting a list
* in the context of placing a hold; contains most of the same values passed to
* placeHold, minus the patron data. May be used to limit the request group
* options or may be ignored.
*
* @return array An array of associative arrays with requestGroupId and
* name keys
*/
public function getRequestGroups($id, $patron, $holdDetails = null)
{
// Get source from patron as that will work also with the Demo driver:
$source = $this->getSource($patron['cat_username']);
if ($driver = $this->getDriver($source)) {
$params = [
$this->stripIdPrefixes($id, $source),
$this->stripIdPrefixes($patron, $source),
$this->stripIdPrefixes($holdDetails, $source),
];
if (
!$this->driverSupportsSource($source, $id)
|| !$this->driverSupportsMethod($driver, __FUNCTION__, $params)
) {
// Return empty array since the sources don't match or the method
// isn't supported by the driver
return [];
}
$groups = $driver->getRequestGroups(...$params);
return $groups;
}
throw new ILSException('No suitable backend driver found');
}
/**
* Get Default Request Group
*
* Returns the default request group
*
* @param array $patron Patron information returned by the patronLogin
* method.
* @param array $holdDetails Optional array, only passed in when getting a list
* in the context of placing a hold; contains most of the same values passed to
* placeHold, minus the patron data. May be used to limit the request group
* options or may be ignored.
*
* @return string A location ID
*/
public function getDefaultRequestGroup($patron, $holdDetails = null)
{
$source = $this->getSource($patron['cat_username']);
if ($driver = $this->getDriver($source)) {
$params = [
$this->stripIdPrefixes($patron, $source),
$this->stripIdPrefixes($holdDetails, $source),
];
if (!empty($holdDetails)) {
if (
!$this->driverSupportsSource($source, $holdDetails['id'])
|| !$this->driverSupportsMethod($driver, __FUNCTION__, $params)
) {
// Return false since the sources don't match or the method
// isn't supported by the driver
return false;
}
}
$locations = $driver->getDefaultRequestGroup(...$params);
return $this->addIdPrefixes($locations, $source);
}
throw new ILSException('No suitable backend driver found');
}
/**
* Place Hold
*
* Attempts to place a hold or recall on a particular item and returns
* an array with result details
*
* @param array $holdDetails An array of item and patron data
*
* @return mixed An array of data on the request including
* whether or not it was successful and a system message (if available)
*/
public function placeHold($holdDetails)
{
$source = $this->getSource($holdDetails['patron']['cat_username']);
if ($driver = $this->getDriver($source)) {
if (!$this->driverSupportsSource($source, $holdDetails['id'])) {
return [
'success' => false,
'sysMessage' => 'ILSMessages::hold_wrong_user_institution',
];
}
$holdDetails = $this->stripIdPrefixes($holdDetails, $source);
return $driver->placeHold($holdDetails);
}
throw new ILSException('No suitable backend driver found');
}
/**
* Get Cancel Hold Details
*
* In order to cancel a hold, the ILS requires some information on the hold.
* This function returns the required information, which is then submitted
* as form data in Hold.php. This value is then extracted by the CancelHolds
* function.
*
* @param array $hold A single hold array from getMyHolds
* @param array $patron Patron information from patronLogin
*
* @return string Data for use in a form field
*/
public function getCancelHoldDetails($hold, $patron = [])
{
$source = $this->getSource(
$patron['cat_username'] ?? $hold['id'] ?? $hold['item_id'] ?? ''
);
$params = [
$this->stripIdPrefixes(
$hold,
$source,
self::HOLD_ID_FIELDS
),
$this->stripIdPrefixes($patron, $source),
];
return $this->callMethodIfSupported($source, __FUNCTION__, $params, false);
}
/**
* Place Storage Retrieval Request
*
* Attempts to place a storage retrieval request on a particular item and returns
* an array with result details
*
* @param array $details An array of item and patron data
*
* @return mixed An array of data on the request including
* whether or not it was successful and a system message (if available)
*/
public function placeStorageRetrievalRequest($details)
{
$source = $this->getSource($details['patron']['cat_username']);
$driver = $this->getDriver($source);
if (
$driver
&& is_callable([$driver, 'placeStorageRetrievalRequest'])
) {
if (!$this->driverSupportsSource($source, $details['id'])) {
return [
'success' => false,
'sysMessage' => 'ILSMessages::storage_wrong_user_institution',
];
}
return $driver->placeStorageRetrievalRequest(
$this->stripIdPrefixes($details, $source)
);
}
throw new ILSException('No suitable backend driver found');
}
/**
* Check whether an ILL request is valid
*
* This is responsible for determining if an item is requestable
*
* @param string $id The Bib ID
* @param array $data An Array of item data
* @param array $patron An array of patron data
*
* @return mixed An array of data on the request including
* whether or not it is valid and a status message. Alternatively a boolean
* true if request is valid, false if not.
*/
public function checkILLRequestIsValid($id, $data, $patron)
{
$source = $this->getSource($id);
// Patron is not stripped so that the correct library can be determined
$params = [
$this->stripIdPrefixes($id, $source),
$this->stripIdPrefixes($data, $source),
$patron,
];
return $this->callMethodIfSupported(
$source,
__FUNCTION__,
$params,
false,
false
);
}
/**
* Get ILL Pickup Libraries
*
* This is responsible for getting information on the possible pickup libraries
*
* @param string $id Record ID
* @param array $patron Patron
*
* @return bool|array False if request not allowed, or an array of associative
* arrays with libraries.
*/
public function getILLPickupLibraries($id, $patron)
{
$source = $this->getSource($id);
// Patron is not stripped so that the correct library can be determined
$params = [
$this->stripIdPrefixes($id, $source, ['id']),
$patron,
];
return $this->callMethodIfSupported(
$source,
__FUNCTION__,
$params,
false,
false
);
}
/**
* Get ILL Pickup Locations
*
* This is responsible for getting a list of possible pickup locations for a
* library
*
* @param string $id Record ID
* @param string $pickupLib Pickup library ID
* @param array $patron Patron
*
* @return bool|array False if request not allowed, or an array of
* locations.
*/
public function getILLPickupLocations($id, $pickupLib, $patron)
{
$source = $this->getSource($id);
// Patron is not stripped so that the correct library can be determined
$params = [
$this->stripIdPrefixes($id, $source, ['id']),
$pickupLib,
$patron,
];
return $this->callMethodIfSupported(
$source,
__FUNCTION__,
$params,
false,
false
);
}
/**
* Place ILL Request
*
* Attempts to place an ILL request on a particular item and returns
* an array with result details (or throws an exception on failure of support
* classes)
*
* @param array $details An array of item and patron data
*
* @return mixed An array of data on the request including
* whether or not it was successful and a system message (if available)
*/
public function placeILLRequest($details)
{
$source = $this->getSource($details['id']);
// Patron is not stripped so that the correct library can be determined
$params = [$this->stripIdPrefixes($details, $source, ['id'], ['patron'])];
return $this->callMethodIfSupported(
$source,
__FUNCTION__,
$params,
false,
false
);
}
/**
* Get Patron ILL Requests
*
* This is responsible for retrieving all ILL Requests by a specific patron.
*
* @param array $patron The patron array from patronLogin
*
* @return mixed Array of the patron's ILL requests
*/
public function getMyILLRequests($patron)
{
$source = $this->getSource($patron['cat_username']);
if ($driver = $this->getDriver($source)) {
$params = [
$this->stripIdPrefixes($patron, $source),
];
if (!$this->driverSupportsMethod($driver, __FUNCTION__, $params)) {
// Return empty array if not supported by the driver
return [];
}
$requests = $driver->getMyILLRequests(...$params);
return $this->addIdPrefixes(
$requests,
$source,
['id', 'item_id', 'cat_username']
);
}
throw new ILSException('No suitable backend driver found');
}
/**
* Check whether the patron is blocked from placing requests (holds/ILL/SRR).
*
* @param array $patron Patron data from patronLogin().
*
* @return mixed A boolean false if no blocks are in place and an array
* of block reasons if blocks are in place
*/
public function getRequestBlocks($patron)
{
$source = $this->getSource($patron['cat_username']);
if ($driver = $this->getDriver($source)) {
$params = [
$this->stripIdPrefixes($patron, $source),
];
if (!$this->driverSupportsMethod($driver, __FUNCTION__, $params)) {
return false;
}
return $driver->getRequestBlocks(...$params);
}
throw new ILSException('No suitable backend driver found');
}
/**
* Check whether the patron has any blocks on their account.
*
* @param array $patron Patron data from patronLogin().
*
* @return mixed A boolean false if no blocks are in place and an array
* of block reasons if blocks are in place
*/
public function getAccountBlocks($patron)
{
$source = $this->getSource($patron['cat_username']);
if ($driver = $this->getDriver($source)) {
$params = [
$this->stripIdPrefixes($patron, $source),
];
if (!$this->driverSupportsMethod($driver, __FUNCTION__, $params)) {
return false;
}
return $driver->getAccountBlocks(...$params);
}
throw new ILSException('No suitable backend driver found');
}
/**
* Function which specifies renew, hold and cancel settings.
*
* @param string $function The name of the feature to be checked
* @param array $params Optional feature-specific parameters (array)
*
* @return array An array with key-value pairs.
*/