Grima  2018-08
Whispering into Alma's ear
Public Member Functions | Public Attributes | List of all members
Grima Class Reference

grima-lib.php - a library for running API calls in Alma More...

Public Member Functions

 session_init ( $force=false)
 
 session_save ($result)
 
 session_destroy ()
 
 __construct ()
 
 get_config ()
 
 get ($url, $URLparams, $QSparams)
 general function for GET (retrieve) API calls More...
 
 post ($url, $URLparams, $QSparams, $body)
 general function for POST (create) API calls More...
 
 put ($url, $URLparams, $QSparams, $body)
 general function for PUT (update) API calls More...
 
 delete ($url, $URLparams, $QSparams)
 general function for DELETE API calls More...
 
 checkForErrorMessage ($xml)
 checks for errorMessage tag, throws exceptions More...
 
Bib APIs
 getBib ($mms_id, $view='full', $expand='None')
 Retrieve Bib - retrieve a bib record from Alma. More...
 
 postBib ($bib)
 Create Record - adds a new bib record to Alma. More...
 
 putBib ($mms_id, $bib)
 Update Bib Record - updates the copy of the bib in Alma. More...
 
 deleteBib ($mms_id, $override='false')
 Delete Bib Record - deletes the bib record from Alma. More...
 
Holdings List APIs
 getHoldingsList ($mms_id)
 Retrieve Holdings list - download brief descriptions of holdings for the bib. More...
 
Holding APIs
 getHolding ($mms_id, $holding_id)
 Retrieve Holdings Record - retrieve holdings record from Alma. More...
 
 postHolding ($mms_id, $holding)
 Create holding record - add a new holdings record to a bib. More...
 
 putHolding ($mms_id, $holding_id, $holding)
 Update Holdings Record - replace the holdings record in Alma. More...
 
 deleteHolding ($mms_id, $holding_id, $override='false')
 Delete Holdings Record - delete the holdings record from Alma. More...
 
Item List APIs
 getItemList ($mms_id, $holding_id, $limit, $offset)
 Retrieve Items list - retrieve the items list from a holding or bib from Alma. More...
 
Item APIs
 getItem ($mms_id, $holding_id, $item_pid)
 Retrieve Item and print label information. More...
 
 getItemBC ($barcode)
 Retrieve Item and print label information (by barcode)) More...
 
 postItem ($mms_id, $holding_id, $item)
 Create Item - add a new item to a holding in Alma. More...
 
 putItem ($mms_id, $holding_id, $item_pid, $item)
 Update Item information - replace item record in Alma. More...
 
 deleteItem ($mms_id, $holding_id, $item_pid, $override="false", $holdings="retain")
 Withdraw Item - delete an item record from Alma. More...
 
Electronic APIs
 getElectronicPortfolio ($collection_id, $service_id, $portfolio_id)
 Retrieve Portfolio - retrieve a portfolio record from Alma. More...
 
 getElectronicPortfolioFromBib ($mms_id, $portfolio_id)
 Retrieve Portfolio - retrieve a portfolio record from Alma. More...
 
 postElectronicPortfolio ($collection_id, $service_id, $portfolio)
 Create Electronic Portfolio - add a new portfolio to Alma. More...
 
 postElectronicPortfolioOnBib ($mms_id, $portfolio)
 Create Electronic Portfolio - add a new portfolio to Alma Bib. More...
 
 putElectronicPortfolioOnBib ($mms_id, $portfolio_id, $portfolio)
 Update Electronic Portfolio - update portfolio in Alma. More...
 
 deleteElectronicPortfolio ($collection_id, $service_id, $portfolio_id)
 Delete Electronic Portfolio - delete portfolio from Alma. More...
 
 getElectronicPortfoliosForService ($collection_id, $service_id, $limit, $offset)
 Retrieve Portfolios - retrieve a list of portfolios from Alma. More...
 
 getElectronicPortfoliosForBib ($mms_id, $limit, $offset)
 Retrieve Portfolios list (Bib) - retrieve a list of portfolios from Alma. More...
 
 getElectronicCollection ($collection_id)
 Retrieve Electronic Collection - retrieve a collection record from Alma. More...
 
 getElectronicServices ($collection_id)
 Retrieve Electronic Services - retrieve a list of services from a collection in Alma. More...
 
Library APIs
 getLibrary ($libraryCode)
 Retrieve a Library - retrieve a Library from Alma. More...
 
Location APIs
 getLocation ($libraryCode, $locationCode)
 Retrieve Location - retrieve a Library Location from Alma. More...
 
Set APIs
 getSet ($set_id)
 Retrieve a Set - retrieve a Set from Alma. More...
 
 createSetFromImport ($job_instance_id, $population)
 Create a Set from an import job. More...
 
 deleteSet ($set_id)
 Delete a Set - delete a set (not its items) from Alma. More...
 
 getSetMembers ($set_id, $limit=10, $offset=0)
 get the members of a set, IF IT WORKS?!?! More...
 
Analytics APIs
 getAnalytics ($path, $filter, $limit=25, $token=null)
 

Public Attributes

 $server
 
 $apikey
 

Detailed Description

grima-lib.php - a library for running API calls in Alma

(c) 2019 Kathryn Lybarger. CC-BY-SA

Definition at line 14 of file grima-lib.php.

Constructor & Destructor Documentation

◆ __construct()

Grima::__construct ( )

Definition at line 60 of file grima-lib.php.

References get_config().

60  {
61  $this->get_config();
62  }
get_config()
Definition: grima-lib.php:64

Member Function Documentation

◆ checkForErrorMessage()

Grima::checkForErrorMessage (   $xml)

checks for errorMessage tag, throws exceptions

Parameters
DomDocument$xml

Definition at line 298 of file grima-lib.php.

Referenced by createSetFromImport(), deleteBib(), deleteElectronicPortfolio(), deleteHolding(), deleteItem(), deleteSet(), getBib(), getElectronicCollection(), getElectronicPortfolio(), getElectronicPortfolioFromBib(), getElectronicPortfoliosForBib(), getElectronicPortfoliosForService(), getElectronicServices(), getHolding(), getHoldingsList(), getItem(), getItemBC(), getItemList(), getLibrary(), getLocation(), getSet(), getSetMembers(), postBib(), postElectronicPortfolio(), postElectronicPortfolioOnBib(), postHolding(), postItem(), putBib(), and putElectronicPortfolioOnBib().

298  {
299  if ($xml instanceOf DomDocument) {
300  $xpath = new DomXpath($xml);
301  $xpath->registerNamespace("err","http://com/exlibris/urm/general/xmlbeans");
302  $error = $xpath->query('//err:errorMessage');
303  if ($error->length > 0) {
304  throw new Exception("Alma says: " . $error[0]->nodeValue);
305  }
306  }
307  }

◆ createSetFromImport()

Grima::createSetFromImport (   $job_instance_id,
  $population 
)

Create a Set from an import job.

Makes a call to the API: (API docs)

POST /almaws/v1/conf/sets
Parameters
string$job_instance_idID of the import job
string$population...
Returns
DomDocument Set object

Definition at line 1060 of file grima-lib.php.

References checkForErrorMessage(), and post().

1060  {
1061  # create blank set
1062 
1063  $body = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?' . '>
1064 <set>
1065  <name>Grima set from ' . $job_instance_id . '</name>
1066  <description>members of ' . $job_instance_id . '</description>
1067  <type desc="Itemized">ITEMIZED</type>
1068  <content desc="All Titles">BIB_MMS</content>
1069  <private desc="No">false</private>
1070 </set>';
1071 
1072 /*
1073  Content:
1074  BIB_MMS -- all titles
1075  ITEM
1076  PORTFOLIO
1077  IEPA
1078  FILE
1079  AUTHORITY_MMS
1080  IEP
1081  IEE
1082  IED
1083  IEC
1084 */
1085 
1086 /*
1087  Population:
1088 */
1089 
1090  $bodyxml = new DomDocument();
1091  $bodyxml->loadXML($body);
1092 
1093  $ret = $this->post('/almaws/v1/conf/sets', array(), array('job_instance_id' => $job_instance_id, 'population' => $population),$bodyxml);
1094  $this->checkForErrorMessage($ret);
1095  return $ret;
1096 
1097  }
checkForErrorMessage($xml)
checks for errorMessage tag, throws exceptions
Definition: grima-lib.php:298
post($url, $URLparams, $QSparams, $body)
general function for POST (create) API calls
Definition: grima-lib.php:174

◆ delete()

Grima::delete (   $url,
  $URLparams,
  $QSparams 
)

general function for DELETE API calls

Parameters
string$url- URL pattern string with parameters in {}
array$URLparams- URL parameters
array$QSparams- query string parameters

Definition at line 260 of file grima-lib.php.

260  {
261  foreach ($URLparams as $k => $v) {
262  $url = str_replace('{'.$k.'}',urlencode($v),$url);
263  }
264  $url = $this->server . $url . '?apikey=' . urlencode($this->apikey);
265  foreach ($QSparams as $k => $v) {
266  $url .= "&$k=$v";
267  }
268  $ch = curl_init();
269  curl_setopt($ch, CURLOPT_URL, $url);
270  curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
271  curl_setopt($ch, CURLOPT_HEADER, FALSE);
272  curl_setopt($ch, CURLOPT_HTTPHEADER,
273  array ("Accept: application/xml"));
274  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
275  $response = curl_exec($ch);
276  $code = curl_getinfo($ch,CURLINFO_HTTP_CODE);
277  if (curl_errno($ch)) {
278  throw new Exception("Network error: " . curl_error($ch));
279  }
280  curl_close($ch);
281  if ($code != 204) {
282  $xml = new DOMDocument();
283  try {
284  $xml->loadXML($response);
285  } catch (Exception $e) {
286  throw new Exception("Malformed XML from Alma: $e");
287  }
288  return $xml;
289  }
290  }

◆ deleteBib()

Grima::deleteBib (   $mms_id,
  $override = 'false' 
)

Delete Bib Record - deletes the bib record from Alma.

Makes a call to the API: (API docs)

DELETE /almaws/v1/bibs/{mms_id}
Parameters
string$mms_idMMS ID of Alma Bib record to delete
string$overrideOptional. Default=false

Definition at line 399 of file grima-lib.php.

References checkForErrorMessage().

399  {
400  $ret = $this->delete('/almaws/v1/bibs/{mms_id}',
401  array('mms_id' => $mms_id),
402  array('override' => $override)
403  );
404  $this->checkForErrorMessage($ret);
405  }
checkForErrorMessage($xml)
checks for errorMessage tag, throws exceptions
Definition: grima-lib.php:298

◆ deleteElectronicPortfolio()

Grima::deleteElectronicPortfolio (   $collection_id,
  $service_id,
  $portfolio_id 
)

Delete Electronic Portfolio - delete portfolio from Alma.

Makes a call to the API: (API docs)

   DELETE /almaws/v1/electronic/e-collections/{collection_id}/e-services/{service_id}/portfolios/{portfolio_id}
Parameters
string$collection_idID of collection
string$service_idID of service
string$portfolio_idID of portfolio

Definition at line 849 of file grima-lib.php.

References checkForErrorMessage().

849  {
850  $ret = $this->delete('/almaws/v1/electronic/e-collections/{collection_id}/e-services/{service_id}/portfolios/{portfolio_id}',
851  array('collection_id' => $collection_id, 'service_id' => $service_id, 'portfolio_id' => $portfolio_id),
852  array()
853  );
854  $this->checkForErrorMessage($ret);
855  }
checkForErrorMessage($xml)
checks for errorMessage tag, throws exceptions
Definition: grima-lib.php:298

◆ deleteHolding()

Grima::deleteHolding (   $mms_id,
  $holding_id,
  $override = 'false' 
)

Delete Holdings Record - delete the holdings record from Alma.

Makes a call to the API: (API docs)

DELETE /almaws/v1/bibs/{mms_id}/holdings/{holding_id}
Parameters
string$mms_idMMS ID of Alma Bib record
string$holding_idHolding ID of Holding record to delete from Alma
string$overrideOptional. Default=false

Definition at line 531 of file grima-lib.php.

References checkForErrorMessage().

531  {
532  $ret = $this->delete('/almaws/v1/bibs/{mms_id}/holdings/{holding_id}',
533  array(
534  'mms_id' => $mms_id,
535  'holding_id' => $holding_id
536  ),
537  array('override' => $override)
538  );
539  $this->checkForErrorMessage($ret);
540  }
checkForErrorMessage($xml)
checks for errorMessage tag, throws exceptions
Definition: grima-lib.php:298

◆ deleteItem()

Grima::deleteItem (   $mms_id,
  $holding_id,
  $item_pid,
  $override = "false",
  $holdings = "retain" 
)

Withdraw Item - delete an item record from Alma.

Makes a call to the API: (API docs)

DELETE /almaws/v1/bibs/{mms_id}/holdings/{holding_id}/items/{item_pid}
Parameters
string$mms_idMMS ID of Bib record
string$holding_idHolding ID of holding record
string$item_pidItem ID of item record
string$overrideOverride warnings? (false, true)
string$holdingsHow to handle holdings with inventory? (retain, delete or suppress)

Definition at line 695 of file grima-lib.php.

References checkForErrorMessage().

696  {
697  $ret = $this->delete('/almaws/v1/bibs/{mms_id}/holdings/{holding_id}/items/{item_pid}', array(
698  'mms_id' => $mms_id,
699  'holding_id' => $holding_id,
700  'item_pid' => $item_pid
701  ), array(
702  'override' => $override,
703  'holdings' => $holdings
704  )
705  );
706  $this->checkForErrorMessage($ret);
707  }
checkForErrorMessage($xml)
checks for errorMessage tag, throws exceptions
Definition: grima-lib.php:298

◆ deleteSet()

Grima::deleteSet (   $set_id)

Delete a Set - delete a set (not its items) from Alma.

Makes a call to the API: (API docs)

DELETE /almaws/v1/conf/sets/{set_id}
Parameters
string$set_idSet ID

Definition at line 1111 of file grima-lib.php.

References checkForErrorMessage().

1111  {
1112  $ret = $this->delete('/almaws/v1/conf/sets/{set_id}',
1113  array(
1114  'set_id' => $set_id,
1115  ),
1116  array()
1117  );
1118  $this->checkForErrorMessage($ret);
1119  }
checkForErrorMessage($xml)
checks for errorMessage tag, throws exceptions
Definition: grima-lib.php:298

◆ get()

Grima::get (   $url,
  $URLparams,
  $QSparams 
)

general function for GET (retrieve) API calls

Parameters
string$url- URL pattern string with parameters in {}
array$URLparams- URL parameters
array$QSparams- query string parameters
Returns
DomDocument of requested record

Definition at line 130 of file grima-lib.php.

130  {
131  # returns a DOM document
132  foreach ($URLparams as $k => $v) {
133  $url = str_replace('{'.$k.'}',urlencode($v),$url);
134  }
135  $url = $this->server . $url . '?apikey=' . urlencode($this->apikey);
136  foreach ($QSparams as $k => $v) {
137  $url .= "&$k=$v";
138  }
139  $ch = curl_init();
140  curl_setopt($ch, CURLOPT_URL, $url);
141  curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
142  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
143  curl_setopt($ch, CURLOPT_HEADER, FALSE);
144  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
145  $response = curl_exec($ch);
146  $code = curl_getinfo($ch,CURLINFO_HTTP_CODE);
147  if (curl_errno($ch)) {
148  throw new Exception("Network error: " . curl_error($ch));
149  }
150  curl_close($ch);
151  $xml = new DOMDocument();
152  try {
153  if (!preg_match('/^</',$response)) {
154  throw new Exception($url);
155  }
156  $xml->loadXML($response);
157  } catch (Exception $e) {
158  throw new Exception("Malformed XML from Alma: $e");
159  }
160  return $xml;
161  }

◆ get_config()

Grima::get_config ( )

Definition at line 64 of file grima-lib.php.

References session_init(), and session_save().

Referenced by __construct().

64  {
65  # Precedence:
66  # $_REQUEST, $_SESSION, $_SERVER, $_ENV, grima-config.php
67 
68  if (isset($_REQUEST['apikey']) and isset($_REQUEST['server']) and
69  ($_REQUEST['apikey']) and ($_REQUEST['server'])
70  ) {
71  $this->session_save( array(
72  'apikey' => $_REQUEST['apikey'],
73  'server' => $_REQUEST['server']
74  ) );
75  $this->apikey = $_REQUEST['apikey'];
76  $this->server = $_REQUEST['server'];
77  return true;
78  }
79 
80  $this->session_init();
81  if ( isset($_SESSION) ) {
82  session_write_close();
83  if(
84  isset($_SESSION['apikey']) and
85  isset($_SESSION['server']) and
86  ($_SESSION['apikey']) and
87  ($_SESSION['server'])
88  ) {
89  $this->apikey = $_SESSION['apikey'];
90  $this->server = $_SESSION['server'];
91  return true;
92  }
93  }
94 
95  if ( isset($_SERVER['apikey']) and isset($_SERVER['server']) and
96  ($_SERVER['apikey']) and ($_SERVER['server'])) {
97  $this->apikey = $_SERVER['apikey'];
98  $this->server = $_SERVER['server'];
99  return true;
100  }
101 
102  if ( isset($_ENV['apikey']) and isset($_ENV['server']) and
103  ($_ENV['apikey']) and ($_ENV['server'])) {
104  $this->apikey = $_ENV['apikey'];
105  $this->server = $_ENV['server'];
106  return true;
107  }
108 
109  if( file_exists("grima-config.php") ) {
110  require('grima-config.php'); # this should set those
111  return true;
112  }
113 
114  return false;
115  }
session_save($result)
Definition: grima-lib.php:35
session_init( $force=false)
Definition: grima-lib.php:20

◆ getAnalytics()

Grima::getAnalytics (   $path,
  $filter,
  $limit = 25,
  $token = null 
)

Definition at line 1153 of file grima-lib.php.

1153  {
1154  return $this->get('/almaws/v1/analytics/reports',
1155  array(),
1156  array('path' => urlencode($path), 'filter' => urlencode($filter),
1157  'limit' => $limit, 'token' => $token)
1158  );
1159  }

◆ getBib()

Grima::getBib (   $mms_id,
  $view = 'full',
  $expand = 'None' 
)

Retrieve Bib - retrieve a bib record from Alma.

Makes a call to the API: (API docs)

GET /almaws/v1/bibs/{mms_id}
Parameters
string$mms_idThe Bib Record ID.
string$viewOptional. Default=full
string$expandOptional. Default=None
Returns
DomDocument Bib object https://developers.exlibrisgroup.com/alma/apis/xsd/rest_bib.xsd?tags=GET

Definition at line 330 of file grima-lib.php.

References checkForErrorMessage().

330  {
331  $ret = $this->get('/almaws/v1/bibs/{mms_id}',
332  array('mms_id' => $mms_id),
333  array('view' => $view, 'expand' => $expand)
334  );
335  $this->checkForErrorMessage($ret);
336  return $ret;
337  }
checkForErrorMessage($xml)
checks for errorMessage tag, throws exceptions
Definition: grima-lib.php:298

◆ getElectronicCollection()

Grima::getElectronicCollection (   $collection_id)

Retrieve Electronic Collection - retrieve a collection record from Alma.

Makes a call to the API: (API docs)

GET /almaws/v1/electronic/e-collections/{collection_id}
Parameters
string$collection_idID of collection
Returns
DomDocument Electronic Collection object

Definition at line 919 of file grima-lib.php.

References checkForErrorMessage().

919  {
920  $ret = $this->get('/almaws/v1/electronic/e-collections/{collection_id}',
921  array('collection_id' => $collection_id),
922  array()
923  );
924  $this->checkForErrorMessage($ret);
925  return $ret;
926  }
checkForErrorMessage($xml)
checks for errorMessage tag, throws exceptions
Definition: grima-lib.php:298

◆ getElectronicPortfolio()

Grima::getElectronicPortfolio (   $collection_id,
  $service_id,
  $portfolio_id 
)

Retrieve Portfolio - retrieve a portfolio record from Alma.

Makes a call to the API: (API docs)

GET /almaws/v1/electronic/e-collections/{collection_id}/e-services/{service_id}/portfolios/{portfolio_id}
Parameters
string$collection_idID of collection
string$service_idID of service
string$portfolio_idID of portfolio
Returns
DomDocument Electronic Portfolio object

Definition at line 731 of file grima-lib.php.

References checkForErrorMessage().

731  {
732  $ret = $this->get('/almaws/v1/electronic/e-collections/{collection_id}/e-services/{service_id}/portfolios/{portfolio_id}',
733  array('collection_id' => $collection_id, 'service_id' => $service_id, 'portfolio_id' => $portfolio_id),
734  array()
735  );
736  $this->checkForErrorMessage($ret);
737  return $ret;
738  }
checkForErrorMessage($xml)
checks for errorMessage tag, throws exceptions
Definition: grima-lib.php:298

◆ getElectronicPortfolioFromBib()

Grima::getElectronicPortfolioFromBib (   $mms_id,
  $portfolio_id 
)

Retrieve Portfolio - retrieve a portfolio record from Alma.

Makes a call to the API: (API docs)

 GET /almaws/v1/bibs/{mms_id}/portfolios/{portfolio_id}
Parameters
string$mms_idID of bib record
string$portfolio_idID of portfolio
Returns
DomDocument Electronic Portfolio object

Definition at line 754 of file grima-lib.php.

References checkForErrorMessage().

754  {
755  $ret = $this->get('/almaws/v1/bibs/{mms_id}/portfolios/{portfolio_id}',
756  array('mms_id' => $mms_id, 'portfolio_id' => $portfolio_id),
757  array()
758  );
759  $this->checkForErrorMessage($ret);
760  return $ret;
761  }
checkForErrorMessage($xml)
checks for errorMessage tag, throws exceptions
Definition: grima-lib.php:298

◆ getElectronicPortfoliosForBib()

Grima::getElectronicPortfoliosForBib (   $mms_id,
  $limit,
  $offset 
)

Retrieve Portfolios list (Bib) - retrieve a list of portfolios from Alma.

Makes a call to the API: (API docs)

GET /almaws/v1/bibs/{mms_id}/portfolios
Parameters
string$mms_idID of bib
string$limitMax number of portfolios to retrieve
string$offsetOffset of the results
Returns
DomDocument Portfolios List object

Definition at line 897 of file grima-lib.php.

References checkForErrorMessage().

897  {
898  $ret = $this->get('/almaws/v1/bibs/{mms_id}/portfolios',
899  array('mms_id' => $mms_id),
900  array('limit' => $limit, $offset = $offset)
901  );
902  $this->checkForErrorMessage($ret);
903  return $ret;
904  }
checkForErrorMessage($xml)
checks for errorMessage tag, throws exceptions
Definition: grima-lib.php:298

◆ getElectronicPortfoliosForService()

Grima::getElectronicPortfoliosForService (   $collection_id,
  $service_id,
  $limit,
  $offset 
)

Retrieve Portfolios - retrieve a list of portfolios from Alma.

Makes a call to the API: (API docs)

GET /almaws/v1/electronic/e-collections/{collection_id}/e-services/{service_id}/portfolios
Parameters
string$collection_idID of collection
string$service_idID of service
string$limitMax number of portfolios to retrieve
string$offsetOffset of the results
Returns
DomDocument Retrieve Portfolios object

Definition at line 873 of file grima-lib.php.

References checkForErrorMessage().

873  {
874  $ret = $this->get('/almaws/v1/electronic/e-collections/{collection_id}/e-services/{service_id}/portfolios',
875  array('collection_id' => $collection_id, 'service_id' => $service_id),
876  array('limit' => $limit, $offset = $offset)
877  );
878  $this->checkForErrorMessage($ret);
879  return $ret;
880  }
checkForErrorMessage($xml)
checks for errorMessage tag, throws exceptions
Definition: grima-lib.php:298

◆ getElectronicServices()

Grima::getElectronicServices (   $collection_id)

Retrieve Electronic Services - retrieve a list of services from a collection in Alma.

Makes a call to the API: (API docs)

GET /almaws/v1/electronic/e-collections/{collection_id}/e-services
Parameters
string$collection_idID of collection
Returns
DomDocument Services object

Definition at line 942 of file grima-lib.php.

References checkForErrorMessage().

942  {
943  $ret = $this->get('/almaws/v1/electronic/e-collections/{collection_id}/e-services',
944  array('collection_id' => $collection_id),
945  array()
946  );
947  $this->checkForErrorMessage($ret);
948  return $ret;
949  }
checkForErrorMessage($xml)
checks for errorMessage tag, throws exceptions
Definition: grima-lib.php:298

◆ getHolding()

Grima::getHolding (   $mms_id,
  $holding_id 
)

Retrieve Holdings Record - retrieve holdings record from Alma.

Makes a call to the API: (API docs)

GET /almaws/v1/bibs/{mms_id}/holdings/{holding_id}
Parameters
string$mms_idMMS ID of Alma Bib
string$holding_idHoldings ID of Alma Holding
Returns
DomDocument Holding object

Definition at line 458 of file grima-lib.php.

References checkForErrorMessage().

458  {
459  $ret = $this->get('/almaws/v1/bibs/{mms_id}/holdings/{holding_id}',
460  array(
461  'mms_id' => $mms_id,
462  'holding_id' => $holding_id
463  ),
464  array()
465  );
466  $this->checkForErrorMessage($ret);
467  return $ret;
468  }
checkForErrorMessage($xml)
checks for errorMessage tag, throws exceptions
Definition: grima-lib.php:298

◆ getHoldingsList()

Grima::getHoldingsList (   $mms_id)

Retrieve Holdings list - download brief descriptions of holdings for the bib.

Makes a call to the API: (API docs)

GET /almaws/v1/bibs/{mms_id}/holdings
Parameters
string$mms_idMMS ID of Alma Bib to gather holdings from
Returns
DomDocument Holdings List object

Definition at line 428 of file grima-lib.php.

References checkForErrorMessage().

428  {
429  $ret = $this->get('/almaws/v1/bibs/{mms_id}/holdings',
430  array('mms_id' => $mms_id),
431  array()
432  );
433  $this->checkForErrorMessage($ret);
434  return $ret;
435  }
checkForErrorMessage($xml)
checks for errorMessage tag, throws exceptions
Definition: grima-lib.php:298

◆ getItem()

Grima::getItem (   $mms_id,
  $holding_id,
  $item_pid 
)

Retrieve Item and print label information.

Makes a call to the API: (API docs)

GET /almaws/v1/bibs/{mms_id}/holdings/{holding_id}/items/{item_pid}
Parameters
string$mms_idMMS ID of Alma Bib
string$holding_idHolding ID of Alma Holding
string$item_pidItem ID of Alma Holding

Definition at line 594 of file grima-lib.php.

References checkForErrorMessage().

594  {
595  $ret = $this->get('/almaws/v1/bibs/{mms_id}/holdings/{holding_id}/items/{item_pid}', array(
596  'mms_id' => $mms_id,
597  'holding_id' => $holding_id,
598  'item_pid' => $item_pid
599  ),
600  array()
601  );
602  $this->checkForErrorMessage($ret);
603  return $ret;
604  }
checkForErrorMessage($xml)
checks for errorMessage tag, throws exceptions
Definition: grima-lib.php:298

◆ getItemBC()

Grima::getItemBC (   $barcode)

Retrieve Item and print label information (by barcode))

Makes a call to the API: (API docs)

GET /almaws/v1/items?item_barcode={item_barcode}
Parameters
string$barcodeBarcode of Alma item

Definition at line 618 of file grima-lib.php.

References checkForErrorMessage().

618  {
619  $ret = $this->get('/almaws/v1/items',
620  array(),
621  array(
622  'item_barcode' => $barcode,
623  )
624  );
625  $this->checkForErrorMessage($ret);
626  return $ret;
627  }
checkForErrorMessage($xml)
checks for errorMessage tag, throws exceptions
Definition: grima-lib.php:298

◆ getItemList()

Grima::getItemList (   $mms_id,
  $holding_id,
  $limit,
  $offset 
)

Retrieve Items list - retrieve the items list from a holding or bib from Alma.

Makes a call to the API: (API docs)

GET /almaws/v1/bibs/{mms_id}/holdings/{holding_id}/items
Parameters
string$mms_idMMS ID of Alma bib
string$holding_idMMS ID of Alma holding
string$limitMax number of items to retrieve
string$offsetOffset of the results returned
Returns
DomDocument Item List object

Definition at line 565 of file grima-lib.php.

References checkForErrorMessage().

565  {
566  $ret = $this->get('/almaws/v1/bibs/{mms_id}/holdings/{holding_id}/items', array('mms_id' => $mms_id, 'holding_id' => $holding_id),
567  array('limit' => $limit, 'offset' => $offset)
568  );
569  $this->checkForErrorMessage($ret);
570  return $ret;
571  }
checkForErrorMessage($xml)
checks for errorMessage tag, throws exceptions
Definition: grima-lib.php:298

◆ getLibrary()

Grima::getLibrary (   $libraryCode)

Retrieve a Library - retrieve a Library from Alma.

Makes a call to the API: (API docs)

GET /almaws/v1/conf/libraries/{libraryCode}
Parameters
string$libraryCodeID of the library to retrieve
Returns
DomDocument Library object

Definition at line 971 of file grima-lib.php.

References checkForErrorMessage().

971  {
972  $ret = $this->get('/almaws/v1/conf/libraries/{libraryCode}',
973  array('libraryCode' => $libraryCode),
974  array()
975  );
976  $this->checkForErrorMessage($ret);
977  return $ret;
978  }
checkForErrorMessage($xml)
checks for errorMessage tag, throws exceptions
Definition: grima-lib.php:298

◆ getLocation()

Grima::getLocation (   $libraryCode,
  $locationCode 
)

Retrieve Location - retrieve a Library Location from Alma.

Makes a call to the API: (API docs)

GET /almaws/v1/conf/libraries/{libraryCode}/locations/{locationCode}
Parameters
string$libraryCodeID of the library to retrieve
Returns
DomDocument Library object

Definition at line 1000 of file grima-lib.php.

References checkForErrorMessage().

1000  {
1001  $ret = $this->get('/almaws/v1/conf/libraries/{libraryCode}/locations/{locationCode}',
1002  array(
1003  'libraryCode' => $libraryCode,
1004  'locationCode' => $locationCode,
1005  ),
1006  array()
1007  );
1008  $this->checkForErrorMessage($ret);
1009  return $ret;
1010  }
checkForErrorMessage($xml)
checks for errorMessage tag, throws exceptions
Definition: grima-lib.php:298

◆ getSet()

Grima::getSet (   $set_id)

Retrieve a Set - retrieve a Set from Alma.

Makes a call to the API: (API docs)

GET /almaws/v1/conf/sets/{set_id}
Parameters
string$set_idID of the set to retrieve
Returns
DomDocument Set object

Definition at line 1032 of file grima-lib.php.

References checkForErrorMessage().

1032  {
1033  $ret = $this->get('/almaws/v1/conf/sets/{set_id}',
1034  array('set_id' => $set_id),
1035  array()
1036  );
1037  $this->checkForErrorMessage($ret);
1038  return $ret;
1039  }
checkForErrorMessage($xml)
checks for errorMessage tag, throws exceptions
Definition: grima-lib.php:298

◆ getSetMembers()

Grima::getSetMembers (   $set_id,
  $limit = 10,
  $offset = 0 
)

get the members of a set, IF IT WORKS?!?!

Makes a call to the API: (API docs)

GET /almaws/v1/conf/sets/{set_id}/members
Parameters
string$set_idSet ID
number$limitHow many to return at most (default 10)
number$offsetWhere to start from, for continuation (default 0, the beginning)

Definition at line 1135 of file grima-lib.php.

References checkForErrorMessage().

1135  {
1136  $ret = $this->get('/almaws/v1/conf/sets/{set_id}/members',
1137  array('set_id' => $set_id),
1138  array('limit' => $limit, 'offset' => $offset)
1139  );
1140  $this->checkForErrorMessage($ret);
1141  return $ret;
1142  }
checkForErrorMessage($xml)
checks for errorMessage tag, throws exceptions
Definition: grima-lib.php:298

◆ post()

Grima::post (   $url,
  $URLparams,
  $QSparams,
  $body 
)

general function for POST (create) API calls

Parameters
string$url- URL pattern string with parameters in {}
array$URLparams- URL parameters
array$QSparams- query string parameters
DomDocument$body- object to add to Alma
Returns
DomDocument $body - object as it now appears in Alma

Definition at line 174 of file grima-lib.php.

Referenced by createSetFromImport(), postBib(), postElectronicPortfolio(), postElectronicPortfolioOnBib(), postHolding(), and postItem().

174  {
175  foreach ($URLparams as $k => $v) {
176  $url = str_replace('{'.$k.'}',urlencode($v),$url);
177  }
178  $url = $this->server . $url . '?apikey=' . urlencode($this->apikey);
179  foreach ($QSparams as $k => $v) {
180  $url .= "&$k=$v";
181  }
182 
183  $bodyxml = $body->saveXML();
184 
185  $ch = curl_init();
186  curl_setopt($ch, CURLOPT_URL, $url);
187  curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
188  curl_setopt($ch, CURLOPT_HEADER, FALSE);
189  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
190  curl_setopt($ch, CURLOPT_POSTFIELDS, $bodyxml);
191  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
192  $response = curl_exec($ch);
193  $code = curl_getinfo($ch,CURLINFO_HTTP_CODE);
194  if (curl_errno($ch)) {
195  throw new Exception("Network error: " . curl_error($ch));
196  }
197  curl_close($ch);
198  $xml = new DOMDocument();
199  try {
200  $xml->loadXML($response);
201  } catch (Exception $e) {
202  throw new Exception("Malformed XML from Alma: $e");
203  }
204  return $xml;
205  }

◆ postBib()

Grima::postBib (   $bib)

Create Record - adds a new bib record to Alma.

Makes a call to the API: (API docs)

POST /almaws/v1/bibs
https://developers.exlibrisgroup.com/alma/apis/bibs#Resources
Parameters
DomDocument$bibBib object to add to Alma as new record
Returns
DomDocument Bib object as it now appears in Alma https://developers.exlibrisgroup.com/alma/apis/xsd/rest_bib.xsd?tags=GET

Definition at line 352 of file grima-lib.php.

References checkForErrorMessage(), and post().

352  {
353  $ret = $this->post('/almaws/v1/bibs',
354  array(),
355  array(),
356  $bib
357  );
358  $this->checkForErrorMessage($ret);
359  return $ret;
360  }
checkForErrorMessage($xml)
checks for errorMessage tag, throws exceptions
Definition: grima-lib.php:298
post($url, $URLparams, $QSparams, $body)
general function for POST (create) API calls
Definition: grima-lib.php:174

◆ postElectronicPortfolio()

Grima::postElectronicPortfolio (   $collection_id,
  $service_id,
  $portfolio 
)

Create Electronic Portfolio - add a new portfolio to Alma.

Makes a call to the API: (API docs)

POST /almaws/v1/electronic/e-collections/{collection_id}/e-services/{service_id}/portfolios/
Parameters
string$collection_idID of collection
string$service_idID of service
string$portfolioA portfolio object to add to Alma
Returns
DomDocument Electronic Portfolio object as it appears in Alma

Definition at line 778 of file grima-lib.php.

References checkForErrorMessage(), and post().

778  {
779  $ret = $this->post('/almaws/v1/electronic/e-collections/{collection_id}/e-services/{service_id}/portfolios',
780  array('collection_id' => $collection_id, 'service_id' => $service_id),
781  array(),
782  $portfolio
783  );
784  $this->checkForErrorMessage($ret);
785  return $ret;
786  }
checkForErrorMessage($xml)
checks for errorMessage tag, throws exceptions
Definition: grima-lib.php:298
post($url, $URLparams, $QSparams, $body)
general function for POST (create) API calls
Definition: grima-lib.php:174

◆ postElectronicPortfolioOnBib()

Grima::postElectronicPortfolioOnBib (   $mms_id,
  $portfolio 
)

Create Electronic Portfolio - add a new portfolio to Alma Bib.

Makes a call to the API: (API docs)

POST /almaws/v1/bibs/{mms_id}/portfolios/
Parameters
string$portfolio_idID of portfolio
Returns
DomDocument Electronic Portfolio object as it appears in Alma

Definition at line 801 of file grima-lib.php.

References checkForErrorMessage(), and post().

801  {
802  $ret = $this->post('/almaws/v1/bibs/{mms_id}/portfolios/',
803  array('mms_id' => $mms_id),
804  array(),
805  $portfolio
806  );
807  $this->checkForErrorMessage($ret);
808  return $ret;
809  }
checkForErrorMessage($xml)
checks for errorMessage tag, throws exceptions
Definition: grima-lib.php:298
post($url, $URLparams, $QSparams, $body)
general function for POST (create) API calls
Definition: grima-lib.php:174

◆ postHolding()

Grima::postHolding (   $mms_id,
  $holding 
)

Create holding record - add a new holdings record to a bib.

Makes a call to the API: (API docs)

POST /almaws/v1/bibs/{mms_id}/holdings
Parameters
string$mms_idMMS ID of bib record
DomDocument$holdingHolding object to add to Alma as new record
Returns
DomDocument Holding object as it now appears in Alma https://developers.exlibrisgroup.com/alma/apis/xsd/rest_bib.xsd?tags=GET

Definition at line 484 of file grima-lib.php.

References checkForErrorMessage(), and post().

484  {
485  $ret = $this->post('/almaws/v1/bibs/{mms_id}/holdings',
486  array('mms_id' => $mms_id),
487  array(),
488  $holding
489  );
490  $this->checkForErrorMessage($ret);
491  return $ret;
492  }
checkForErrorMessage($xml)
checks for errorMessage tag, throws exceptions
Definition: grima-lib.php:298
post($url, $URLparams, $QSparams, $body)
general function for POST (create) API calls
Definition: grima-lib.php:174

◆ postItem()

Grima::postItem (   $mms_id,
  $holding_id,
  $item 
)

Create Item - add a new item to a holding in Alma.

Makes a call to the API: (API docs)

POST /almaws/v1/bibs/{mms_id}/holdings/{holding_id}/items
Parameters
string$mms_id- MMS ID of Bib record
string$holding_id- Holding ID of Holding record
DomDocument$item- Item object to add to Alma as new record
Returns
DomDocument Bib object as it now appears in Alma https://developers.exlibrisgroup.com/alma/apis/xsd/rest_bib.xsd?tags=GET

Definition at line 644 of file grima-lib.php.

References checkForErrorMessage(), and post().

644  {
645  $ret = $this->post('/almaws/v1/bibs/{mms_id}/holdings/{holding_id}/items',
646  array('mms_id' => $mms_id, 'holding_id' => $holding_id),
647  array(),
648  $item
649  );
650  $this->checkForErrorMessage($ret);
651  return $ret;
652  }
checkForErrorMessage($xml)
checks for errorMessage tag, throws exceptions
Definition: grima-lib.php:298
post($url, $URLparams, $QSparams, $body)
general function for POST (create) API calls
Definition: grima-lib.php:174

◆ put()

Grima::put (   $url,
  $URLparams,
  $QSparams,
  $body 
)

general function for PUT (update) API calls

Parameters
string$url- URL pattern string with parameters in {}
array$URLparams- URL parameters
array$QSparams- query string parameters
DomDocument$body- record to update Alma record with
Returns
DomDocument - record as it now appears in Alma

Definition at line 218 of file grima-lib.php.

Referenced by putBib(), putElectronicPortfolioOnBib(), putHolding(), and putItem().

218  {
219  foreach ($URLparams as $k => $v) {
220  $url = str_replace('{'.$k.'}',urlencode($v),$url);
221  }
222  $url = $this->server . $url . '?apikey=' . urlencode($this->apikey);
223  foreach ($QSparams as $k => $v) {
224  $url .= "&$k=$v";
225  }
226 
227  $bodyxml = $body->saveXML();
228 
229  $ch = curl_init();
230  curl_setopt($ch, CURLOPT_URL, $url);
231  curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
232  curl_setopt($ch, CURLOPT_HEADER, FALSE);
233  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
234  curl_setopt($ch, CURLOPT_POSTFIELDS, $bodyxml);
235  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
236  $response = curl_exec($ch);
237  $code = curl_getinfo($ch,CURLINFO_HTTP_CODE);
238  if (curl_errno($ch)) {
239  throw new Exception("Network error: " . curl_error($ch));
240  }
241  curl_close($ch);
242  $xml = new DOMDocument();
243  try {
244  $xml->loadXML($response);
245  } catch (Exception $e) {
246  throw new Exception("Malformed XML from Alma: $e");
247  }
248  return $xml;
249  }

◆ putBib()

Grima::putBib (   $mms_id,
  $bib 
)

Update Bib Record - updates the copy of the bib in Alma.

Makes a call to the API: (API docs)

PUT /almaws/v1/bibs/{mms_id}

Parameters
string$mms_idAlma Bib record to update
DomDocument$bibBib to replace old record
Returns
DomDocument Bib object as it now appears in Alma https://developers.exlibrisgroup.com/alma/apis/xsd/rest_bib.xsd?tags=GET

Definition at line 376 of file grima-lib.php.

References checkForErrorMessage(), and put().

376  {
377  $ret = $this->put('/almaws/v1/bibs/{mms_id}',
378  array('mms_id' => $mms_id),
379  array(),
380  $bib
381  );
382  $this->checkForErrorMessage($ret);
383  return $ret;
384  }
checkForErrorMessage($xml)
checks for errorMessage tag, throws exceptions
Definition: grima-lib.php:298
put($url, $URLparams, $QSparams, $body)
general function for PUT (update) API calls
Definition: grima-lib.php:218

◆ putElectronicPortfolioOnBib()

Grima::putElectronicPortfolioOnBib (   $mms_id,
  $portfolio_id,
  $portfolio 
)

Update Electronic Portfolio - update portfolio in Alma.

Makes a call to the API: (API docs)

PUT /almaws/v1/bibs/{mms_id}/portfolios/{portfolio_id}   
Parameters
string$mms_idID of bibliographic record
string$portfolio_idID of portfolio
Returns
DomDocument Electronic Portfolio object as it appears in Alma

Definition at line 825 of file grima-lib.php.

References checkForErrorMessage(), and put().

825  {
826  $ret = $this->put('/almaws/v1/bibs/{mms_id}/portfolios/{portfolio_id}',
827  array('mms_id' => $mms_id, 'portfolio_id' => $portfolio_id),
828  array(),
829  $portfolio
830  );
831  $this->checkForErrorMessage($ret);
832  return $ret;
833  }
checkForErrorMessage($xml)
checks for errorMessage tag, throws exceptions
Definition: grima-lib.php:298
put($url, $URLparams, $QSparams, $body)
general function for PUT (update) API calls
Definition: grima-lib.php:218

◆ putHolding()

Grima::putHolding (   $mms_id,
  $holding_id,
  $holding 
)

Update Holdings Record - replace the holdings record in Alma.

Makes a call to the API: (API docs)

PUT /almaws/v1/bibs/{mms_id}/holdings/{holding_id}
Parameters
string$mms_idMMS ID of Bib
string$holding_idHolding ID of holding to replace
DomDocument$holdingHolding object to add to Alma as new record
Returns
DomDocument Bib object as it now appears in Alma https://developers.exlibrisgroup.com/alma/apis/xsd/rest_bib.xsd?tags=GET

Definition at line 509 of file grima-lib.php.

References put().

509  {
510  $ret = $this->put('/almaws/v1/bibs/{mms_id}/holdings/{holding_id}',
511  array('mms_id' => $mms_id, 'holding_id' => $holding_id),
512  array(),
513  $holding
514  );
515  }
put($url, $URLparams, $QSparams, $body)
general function for PUT (update) API calls
Definition: grima-lib.php:218

◆ putItem()

Grima::putItem (   $mms_id,
  $holding_id,
  $item_pid,
  $item 
)

Update Item information - replace item record in Alma.

Makes a call to the API: (API docs)

PUT /almaws/v1/bibs/{mms_id}/holdings/{holding_id}/items/{item_pid}
Parameters
string$mms_idMMS ID of Bib record
string$holding_idHolding ID of Holding record
string$item_pidItem ID of Item record
DomDocument$itemItem object to update record with in Alma
Returns
DomDocument Bib object as it now appears in Alma https://developers.exlibrisgroup.com/alma/apis/xsd/rest_bib.xsd?tags=GET

Definition at line 670 of file grima-lib.php.

References put().

670  {
671  $ret = $this->put('/almaws/v1/bibs/{mms_id}/holdings/{holding_id}/items/{item_pid}',
672  array('mms_id' => $mms_id, 'holding_id' => $holding_id, 'item_pid' => $item_pid),
673  array(),
674  $item
675  );
676  return $ret;
677  }
put($url, $URLparams, $QSparams, $body)
general function for PUT (update) API calls
Definition: grima-lib.php:218

◆ session_destroy()

Grima::session_destroy ( )

Definition at line 43 of file grima-lib.php.

References session_init().

43  {
44  $this->session_init(true);
45  session_start();
46  if (ini_get("session.use_cookies")) {
47  $params = session_get_cookie_params();
48  setcookie(session_name(), '', time() - 42000,
49  $params["path"], $params["domain"],
50  $params["secure"], $params["httponly"]
51  );
52  }
54  $_SESSION=array();
55  }
session_init( $force=false)
Definition: grima-lib.php:20
session_destroy()
Definition: grima-lib.php:43

◆ session_init()

Grima::session_init (   $force = false)

Definition at line 20 of file grima-lib.php.

References join_paths().

Referenced by get_config(), session_destroy(), and session_save().

20  {
21  if( !isset($_SESSION) ) {
22  $session_name = 'grima';
23  $session_dir = join_paths( sys_get_temp_dir(), 'grima' );
24  @mkdir($session_dir, 0777, true);
25  session_save_path($session_dir);
26  session_name( $session_name );
27  session_set_cookie_params(365*24*60*60); # one year
28  ini_set('session.gc_maxlifetime',525600*60); # of love
29  if( $force || isset($_COOKIE[$session_name]) ) {
30  session_start();
31  }
32  }
33  }
join_paths(... $paths)
Definition: grima-util.php:114

◆ session_save()

Grima::session_save (   $result)

Definition at line 35 of file grima-lib.php.

References session_init().

Referenced by get_config().

35  {
36  $this->session_init(true);
37  foreach( $result as $key => $value ) {
38  $_SESSION[$key] = $value;
39  }
40  session_write_close();
41  }
session_init( $force=false)
Definition: grima-lib.php:20

Member Data Documentation

◆ $apikey

Grima::$apikey

Definition at line 16 of file grima-lib.php.

◆ $server

Grima::$server

Definition at line 15 of file grima-lib.php.


The documentation for this class was generated from the following file: