diff --git a/module/VuFind/src/VuFind/ILS/Driver/KohaRest.php b/module/VuFind/src/VuFind/ILS/Driver/KohaRest.php index c549a5ea768b4ef5cb3a4572545ea56cd5a796e8..737c4264d8dce994407f9be2cc09ca8433c63f23 100644 --- a/module/VuFind/src/VuFind/ILS/Driver/KohaRest.php +++ b/module/VuFind/src/VuFind/ILS/Driver/KohaRest.php @@ -45,8 +45,7 @@ use VuFind\Exception\Date as DateException; * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License * @link http://vufind.org/wiki/vufind2:building_an_ils_driver Wiki */ - -class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements +class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements \VuFindHttp\HttpServiceAwareInterface, \Zend\Log\LoggerAwareInterface { /** @@ -89,7 +88,6 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements * * @var string */ - protected $db; /** @@ -97,7 +95,6 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements * * @var LoggerInterface */ - protected $logger = false; /** @@ -186,7 +183,7 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements $this->pickupEnableBranchcodes = isset($this->config['Holds']['pickupLocations']) - ? $this->config['Holds']['pickupLocations'] : array(); + ? $this->config['Holds']['pickupLocations'] : []; // Create a dateConverter $this->dateConverter = new \VuFind\Date\Converter; @@ -251,7 +248,7 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements * * @return $contents or $default */ - protected function getField($contents, $default="Unknown") + protected function getField($contents, $default = "Unknown") { if ((string) $contents != "") { return (string) $contents; @@ -271,7 +268,7 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements * @throws ILSException * @return obj */ - protected function makeRequest($api_query, $http_method="GET") + protected function makeRequest($api_query, $http_method = "GET") { //$url = $this->host . $this->api_path . $api_query; @@ -280,10 +277,10 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements if ($this->debug_enabled) { $this->debug("URL: '$url'"); } - $http_headers = array( + $http_headers = [ "Accept: text/xml", "Accept-encoding: plain", - ); + ]; try { $client = $this->httpService->createClient($url); @@ -319,17 +316,17 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements * * Makes a request to the Polaris Restful API * - * @param string $service Called function (GetAvailability, - * GetRecords, - * GetAuthorityRecords, - * LookupPatron, - * AuthenticatePatron, - * GetPatronInfo, - * GetPatronStatus, - * GetServices, - * RenewLoan, - * HoldTitle, - * HoldItem, + * @param string $service Called function (GetAvailability, + * GetRecords, + * GetAuthorityRecords, + * LookupPatron, + * AuthenticatePatron, + * GetPatronInfo, + * GetPatronStatus, + * GetServices, + * RenewLoan, + * HoldTitle, + * HoldItem, * CancelHold) * @param array $params Key is parameter name, value is parameter value * @param string $http_method HTTP method (default = GET) @@ -337,7 +334,7 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements * @throws ILSException * @return obj */ - protected function makeIlsdiRequest($service, $params, $http_method="GET") + protected function makeIlsdiRequest($service, $params, $http_method = "GET") { $start = microtime(true); $url = $this->ilsBaseUrl . "?service=" . $service; @@ -348,10 +345,10 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements if ($this->debug_enabled) { $this->debug("URL: '$url'"); } - $http_headers = array( - "Accept: text/xml", - "Accept-encoding: plain", - ); + $http_headers = [ + "Accept: text/xml", + "Accept-encoding: plain", + ]; try { $client = $this->httpService->createClient($url); @@ -437,7 +434,6 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements return $functionConfig; } - // @codingStandardsIgnoreStart /** * Get Pick Up Locations * @@ -453,11 +449,10 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements * based on this data or other areas of VuFind may behave incorrectly. * * @throws ILSException + * @return array An array of associative arrays with locationID and + * locationDisplay keys * - * @return array An array of associative arrays with locationID and locationDisplay keys * @SuppressWarnings(PHPMD.UnusedFormalParameter) - * @codingStandardsIgnoreEnd - * */ public function getPickUpLocations($patron = false, $holdDetails = null) { @@ -468,9 +463,9 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements $branchcodes = "'" . implode( "','", $this->pickupEnableBranchcodes ) . "'"; - $sql = "SELECT branchcode as locationID, - branchname as locationDisplay - FROM branches + $sql = "SELECT branchcode as locationID, + branchname as locationDisplay + FROM branches WHERE branchcode IN ($branchcodes)"; try { $sqlSt = $this->db->prepare($sql); @@ -508,7 +503,8 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements * placeHold, minus the patron data. May be used to limit the pickup options * or may be ignored. * - * @return string The default pickup location for the patron. + * @return string The default pickup location for the patron. + * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function getDefaultPickUpLocation($patron = false, $holdDetails = null) @@ -531,7 +527,7 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements */ public function placeHold($holdDetails) { - $rsvLst = array(); + $rsvLst = []; $patron = $holdDetails['patron']; $patron_id = $patron['id']; $request_location = isset($patron['ip']) ? $patron['ip'] : "127.0.0.1"; @@ -551,10 +547,10 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements $needed_before_date = $dateObject->format("Y-m-d"); } } catch (\Exception $e) { - return array( + return [ "success" => false, "sysMessage" => "It seems you entered an invalid expiration date." - ); + ]; } if ($this->debug_enabled) { @@ -568,7 +564,7 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements $this->debug("Level: " . $level); } - if ($level == "title" ) { + if ($level == "title") { $rqString = "HoldTitle&patron_id=$patron_id&bib_id=$bib_id" . "&request_location=$request_location" . "&pickup_location=$pickup_location" @@ -612,16 +608,16 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements } if ($rsp->{'code'} != "") { - return array( + return [ "success" => false, - "sysMessage" => $this->getField($rsp->{'code'}) + "sysMessage" => $this->getField($rsp->{'code'}) . $holdDetails['level'], - ); + ]; } - return array( + return [ "success" => true, //"sysMessage" => $message, - ); + ]; } /** @@ -646,37 +642,45 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements $started = microtime(true); - $holding = array(); + $holding = []; $available = true; $duedate = $status = ''; $loc = $shelf = ''; $reserves = "N"; - // @codingStandardsIgnoreStart - $sql = "select i.itemnumber as ITEMNO, i.location, av.lib_opac AS LOCATION, i.holdingbranch as HLDBRNCH, - i.homebranch as HOMEBRANCH, i.reserves as RESERVES, i.itemcallnumber as CALLNO, i.barcode as BARCODE, - i.copynumber as COPYNO, i.notforloan as NOTFORLOAN, i.itemnotes as PERIONAME, b.frameworkcode as DOCTYPE, - t.frombranch as TRANSFERFROM, t.tobranch as TRANSFERTO, i.itemlost as ITEMLOST - from items i join biblio b on i.biblionumber = b.biblionumber - left outer join (SELECT itemnumber, frombranch, tobranch from branchtransfers where datearrived IS NULL) as t USING (itemnumber) - left join authorised_values as av on i.location = av.authorised_value - where i.biblionumber = :id AND av.category = 'LOC' order by i.itemnumber DESC"; - $sqlReserves = "select count(*) as RESERVESCOUNT from reserves WHERE biblionumber = :id AND found IS NULL"; - $sqlWaitingReserve = "select count(*) as WAITING from reserves WHERE itemnumber = :item_id and found = 'W'"; - $sqlHoldings = "SELECT ExtractValue(( SELECT marcxml FROM biblioitems WHERE biblionumber = :id), '//datafield[@tag=\"866\"]/subfield[@code=\"a\"]') AS MFHD;"; - // @codingStandardsIgnoreEnd + $sql = "select i.itemnumber as ITEMNO, i.location, av.lib_opac AS LOCATION, + i.holdingbranch as HLDBRNCH, i.homebranch as HOMEBRANCH, + i.reserves as RESERVES, i.itemcallnumber as CALLNO, i.barcode as BARCODE, + i.copynumber as COPYNO, i.notforloan as NOTFORLOAN, + i.itemnotes as PERIONAME, b.frameworkcode as DOCTYPE, + t.frombranch as TRANSFERFROM, t.tobranch as TRANSFERTO, + i.itemlost as ITEMLOST + from items i join biblio b on i.biblionumber = b.biblionumber + left outer join + (SELECT itemnumber, frombranch, tobranch from branchtransfers + where datearrived IS NULL) as t USING (itemnumber) + left join authorised_values as av on i.location = av.authorised_value + where i.biblionumber = :id AND av.category = 'LOC' + order by i.itemnumber DESC"; + $sqlReserves = "select count(*) as RESERVESCOUNT from reserves " + . "WHERE biblionumber = :id AND found IS NULL"; + $sqlWaitingReserve = "select count(*) as WAITING from reserves " + . "WHERE itemnumber = :item_id and found = 'W'"; + $sqlHoldings = "SELECT ExtractValue(( SELECT marcxml FROM biblioitems " + . "WHERE biblionumber = :id), " + . "'//datafield[@tag=\"866\"]/subfield[@code=\"a\"]') AS MFHD;"; if (!$this->db) { $this->initDB(); } try { $itemSqlStmt = $this->db->prepare($sql); - $itemSqlStmt->execute(array(':id' => $id)); + $itemSqlStmt->execute([':id' => $id]); $sqlStmtReserves = $this->db->prepare($sqlReserves); $sqlStmtWaitingReserve = $this->db->prepare($sqlWaitingReserve); - $sqlStmtReserves->execute(array(':id' => $id)); + $sqlStmtReserves->execute([':id' => $id]); $sqlStmtHoldings = $this->db->prepare($sqlHoldings); - $sqlStmtHoldings->execute(array(':id' => $id)); + $sqlStmtHoldings->execute([':id' => $id]); } catch (PDOException $e) { $this->debug('Connection failed: ' . $e->getMessage()); } @@ -690,7 +694,7 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements foreach ($itemSqlStmt->fetchAll() as $rowItem) { $inum = $rowItem['ITEMNO']; - $sqlStmtWaitingReserve->execute(array(':item_id' => $inum)); + $sqlStmtWaitingReserve->execute([':item_id' => $inum]); $waitingReserveRow = $sqlStmtWaitingReserve->fetch(); $waitingReserve = $waitingReserveRow["WAITING"]; $sql = "select date_due as DUEDATE from issues where itemnumber = :inum"; @@ -699,7 +703,7 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements // If the item is available for loan, then check its current // status $issueSqlStmt = $this->db->prepare($sql); - $issueSqlStmt->execute(array(':inum' => $inum)); + $issueSqlStmt->execute([':inum' => $inum]); $rowIssue = $issueSqlStmt->fetch(); if ($rowIssue) { $available = false; @@ -720,10 +724,10 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements break; } /* - * If the Item is in Location INTERNET or ONLINE, + * If the Item is in Location INTERNET or ONLINE, * the item is considered available */ - if ($rowItem['LOCATION'] == 'INTERNET' + if ($rowItem['LOCATION'] == 'INTERNET' || $rowItem['LOCATION'] == 'ONLINE' ) { $available = true; @@ -732,7 +736,7 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements } // If Item is Lost or Missing, provide that status - if ($rowItem['ITEMLOST'] > 0 ) { + if ($rowItem['ITEMLOST'] > 0) { $available = false; $duedate = '01/01/2099'; $status = 'Lost/Missing'; @@ -752,24 +756,26 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements } if ($loc != "Unknown") { - $sqlBranch = "select branchname as BNAME + $sqlBranch = "select branchname as BNAME from branches where branchcode = :branch"; $branchSqlStmt = $this->db->prepare($sqlBranch); - $branchSqlStmt->execute(array(':branch' => $loc)); + $branchSqlStmt->execute([':branch' => $loc]); $row = $branchSqlStmt->fetch(); if ($row) { $loc = $row['BNAME']; } } - // @codingStandardsIgnoreStart $onTransfer = false; - if (($rowItem["TRANSFERFROM"] != null) && ($rowItem["TRANSFERTO"] != null)) { - $branchSqlStmt->execute(array(':branch' => $rowItem["TRANSFERFROM"])); + if (($rowItem["TRANSFERFROM"] != null) + && ($rowItem["TRANSFERTO"] != null) + ) { + $branchSqlStmt->execute([':branch' => $rowItem["TRANSFERFROM"]]); $rowFrom = $branchSqlStmt->fetch(); - $transferfrom = $rowFrom ? $rowFrom["BNAME"] : $rowItem["TRANSFERFROM"]; - $branchSqlStmt->execute(array(':branch' => $rowItem["TRANSFERTO"])); + $transferfrom = $rowFrom + ? $rowFrom["BNAME"] : $rowItem["TRANSFERFROM"]; + $branchSqlStmt->execute([':branch' => $rowItem["TRANSFERTO"]]); $rowTo = $branchSqlStmt->fetch(); $transferto = $rowTo ? $rowTo["BNAME"] : $rowItem["TRANSFERTO"]; $status = "Na cest? z $transferfrom do $transferto"; @@ -787,31 +793,36 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements } else { $waiting = false; } - $holding[] = array( - 'id' => $id, - 'availability' => (string) $available, - 'item_id' => $rowItem['ITEMNO'], - 'status' => $status, - 'location' => $loc, - 'notes' => $notes["MFHD"], - //'reserve' => (null == $rowItem['RESERVES']) ? 'N' : $rowItem['RESERVES'], - 'reserve' => 'N', - 'callnumber' => ((null == $rowItem['CALLNO']) || ($rowItem['DOCTYPE'] == "PE")) ? '' : $rowItem['CALLNO'], - 'duedate' => ($onTransfer || $waiting) ? '' : (string) $duedate_formatted, - 'barcode' => (null == $rowItem['BARCODE']) ? 'Unknown' : $rowItem['BARCODE'], - 'number' => (null == $rowItem['COPYNO']) ? '' : $rowItem['COPYNO'], - 'requests_placed' => $reservesCount ? $reservesCount : 0, - 'frameworkcode'=> $rowItem['DOCTYPE'], - ); - // @codingStandardsIgnoreEnd + $holding[] = [ + 'id' => $id, + 'availability' => (string) $available, + 'item_id' => $rowItem['ITEMNO'], + 'status' => $status, + 'location' => $loc, + 'notes' => $notes["MFHD"], + //'reserve' => (null == $rowItem['RESERVES']) + // ? 'N' : $rowItem['RESERVES'], + 'reserve' => 'N', + 'callnumber' => + ((null == $rowItem['CALLNO']) || ($rowItem['DOCTYPE'] == "PE")) + ? '' : $rowItem['CALLNO'], + 'duedate' => ($onTransfer || $waiting) + ? '' : (string) $duedate_formatted, + 'barcode' => (null == $rowItem['BARCODE']) + ? 'Unknown' : $rowItem['BARCODE'], + 'number' => (null == $rowItem['COPYNO']) + ? '' : $rowItem['COPYNO'], + 'requests_placed' => $reservesCount ? $reservesCount : 0, + 'frameworkcode' => $rowItem['DOCTYPE'], + ]; } //file_put_contents('holding.txt', print_r($holding,TRUE), FILE_APPEND); $this->debug( - "Processing finished, rows processed: " - . count($holding).", took ".(microtime(true)-$started). + "Processing finished, rows processed: " + . count($holding) . ", took " . (microtime(true) - $started) . " sec" ); @@ -836,7 +847,7 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements public function getHoldingOld($id, $patron = false) { - $holding = array(); + $holding = []; $available = true; $duedate = $status = ''; $loc = $shelf = ''; @@ -878,18 +889,18 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements break; } } - $holding[] = array( - 'id' => (string) $id, - 'availability' => (string) $available, - 'item_id' => $this->getField($item->{'itemnumber'}), - 'status' => (string) $status, - 'location' => $this->getField($item->{'location'}), - 'reserve' => (string) $reserves, - 'callnumber' => $this->getField($item->{'itemcallnumber'}), - 'duedate' => (string) $duedate, - 'barcode' => $this->getField($item->{'barcode'}), - 'number' => $this->getField($item->{'copynumber'}), - ); + $holding[] = [ + 'id' => (string) $id, + 'availability' => (string) $available, + 'item_id' => $this->getField($item->{'itemnumber'}), + 'status' => (string) $status, + 'location' => $this->getField($item->{'location'}), + 'reserve' => (string) $reserves, + 'callnumber' => $this->getField($item->{'itemcallnumber'}), + 'duedate' => (string) $duedate, + 'barcode' => $this->getField($item->{'barcode'}), + 'number' => $this->getField($item->{'copynumber'}), + ]; } return $holding; } @@ -897,10 +908,10 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements /** * This method queries the ILS for new items * - * Comment for $fundID: (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 + * Comment for $fundID: (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. * * @param unknown $page - page number of results to retrieve (starts at 1) @@ -910,19 +921,19 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements * * @return array provides a count and the results of new items. */ - public function getNewItems($page, $limit, $daysOld, $fundId = null) + public function getNewItems($page, $limit, $daysOld, $fundId = null) { $this->debug("getNewItems called $page|$limit|$daysOld|$fundId"); - $items = array(); + $items = []; $daysOld = min(abs(intval($daysOld)), 30); - $sql = "SELECT distinct biblionumber as id - FROM items - WHERE itemlost = 0 - and stocknumber > 1 - and dateaccessioned > DATE_ADD(CURRENT_TIMESTAMP, - INTERVAL -$daysOld day) + $sql = "SELECT distinct biblionumber as id + FROM items + WHERE itemlost = 0 + and stocknumber > 1 + and dateaccessioned > DATE_ADD(CURRENT_TIMESTAMP, + INTERVAL -$daysOld day) ORDER BY dateaccessioned DESC"; if (!$this->db) { @@ -936,19 +947,18 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements $rescount = 0; foreach ($itemSqlStmt->fetchAll() as $rowItem) { - $items[] = array ( - 'id' => $rowItem['id'] - ); + $items[] = [ + 'id' => $rowItem['id'] + ]; $rescount++; } - $this->debug($rescount." fetched"); + $this->debug($rescount . " fetched"); - $results = array_slice($items, ($page - 1) * $limit, ($page * $limit)-1); - return array('count' => $rescount, 'results' => $results); + $results = array_slice($items, ($page - 1) * $limit, ($page * $limit) - 1); + return ['count' => $rescount, 'results' => $results]; } - // @codingStandardsIgnoreStart /** * Get Hold Link * @@ -959,9 +969,9 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements * @param string $id The id of the bib record * @param array $details Item details from getHoldings return array * - * @return string URL to ILS's OPAC's place hold screen. + * @return string URL to ILS's OPAC's place hold screen. + * * @SuppressWarnings(PHPMD.UnusedFormalParameter) - * @codingStandardsIgnoreEnd */ /*public function getHoldLink($id, $details) { @@ -983,7 +993,7 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements public function getMyFines($patron) { $id = 0; - $transactionLst = array(); + $transactionLst = []; $row = $sql = $sqlStmt = ''; try { $id = $patron['id']; @@ -997,9 +1007,9 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements } $sqlStmt = $this->db->prepare($sql); - $sqlStmt->execute(array(':id' => $id)); + $sqlStmt->execute([':id' => $id]); foreach ($sqlStmt->fetchAll() as $row) { - $transactionLst[] = array( + $transactionLst[] = [ 'duedate' => date_format( new \DateTime($row['DUEDATE']), "m/d/Y" ), @@ -1008,7 +1018,7 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements 'renew' => $row['RENEWALS'], 'item_id' => $row['ITEM_ID'], 'message' => $row['NOTES'], - ); + ]; } return $transactionLst; } @@ -1017,7 +1027,6 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements } } - /** * Get Patron Fines * @@ -1032,7 +1041,7 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements public function getMyFinesILS($patron) { $id = $patron['id']; - $fineLst = array(); + $fineLst = []; $rsp = $this->makeRequest( "GetPatronInfo&patron_id=$id" . "&show_contact=0&show_fines=1" @@ -1044,7 +1053,7 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements } foreach ($rsp->{'fines'}->{'fine'} as $fine) { - $fineLst[] = array( + $fineLst[] = [ 'amount' => 100 * $this->getField($fine->{'amount'}), // FIXME: require accountlines.itemnumber -> issues.issuedate data 'checkout' => "N/A", @@ -1055,7 +1064,7 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements 'duedate' => "N/A", // FIXME: require accountlines.itemnumber -> items.biblionumber data 'id' => "N/A", - ); + ]; } return $fineLst; } @@ -1074,7 +1083,7 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements public function getMyHolds($patron) { $id = $patron['id']; - $holdLst = array(); + $holdLst = []; $rsp = $this->makeRequest( "GetPatronInfo&patron_id=$id" . "&show_contact=0&show_holds=1" @@ -1085,7 +1094,7 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements //print_r($rsp); // Proof that no itemnumber is returned. } foreach ($rsp->{'holds'}->{'hold'} as $hold) { - $holdLst[] = array( + $holdLst[] = [ 'id' => $this->getField($hold->{'biblionumber'}), 'location' => $this->getField($hold->{'branchname'}), // FIXME: require exposure of reserves.expirationdate @@ -1095,9 +1104,9 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements ), 'position' => $this->getField($hold->{'priority'}), 'title' => $this->getField($hold->{'title'}), - 'available' => ($this->getField($hold->{'found'}) == "W")?true:false, - 'reserve_id' => $this->getField($hold->{'reserve_id'}), - ); + 'available' => ($this->getField($hold->{'found'}) == "W"), + 'reserve_id' => $this->getField($hold->{'reserve_id'}), + ]; } return $holdLst; } @@ -1131,7 +1140,7 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements */ public function cancelHolds($cancelDetails) { - $retVal = array('count' => 0, 'items' => array()); + $retVal = ['count' => 0, 'items' => []]; $details = $cancelDetails['details']; $patron_id = $cancelDetails['patron']['id']; $request_prefix = "CancelHold&patron_id=" . $patron_id . "&item_id="; @@ -1139,17 +1148,17 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements foreach ($details as $cancelItem) { $rsp = $this->makeRequest($request_prefix . $cancelItem); if ($rsp->{'code'} != "Canceled") { - $retVal['items'][$cancelItem] = array( + $retVal['items'][$cancelItem] = [ 'success' => false, 'status' => 'hold_cancel_fail', 'sysMessage' => $this->getField($rsp->{'code'}), - ); + ]; } else { $retVal['count']++; - $retVal['items'][$cancelItem] = array( + $retVal['items'][$cancelItem] = [ 'success' => true, 'status' => 'hold_cancel_success', - ); + ]; } } return $retVal; @@ -1168,7 +1177,7 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements public function getMyProfile($patron) { $id = $patron['id']; - $profile = array(); + $profile = []; $rsp = $this->makeRequest( "GetPatronInfo&patron_id=$id" . "&show_contact=1" @@ -1180,7 +1189,7 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements } if ($rsp->{'code'} != 'PatronNotFound') { - $profile = array( + $profile = [ 'firstname' => $this->getField($rsp->{'firstname'}), 'lastname' => $this->getField($rsp->{'surname'}), 'address1' => $this->getField($rsp->{'address'}), @@ -1188,7 +1197,7 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements 'zip' => $this->getField($rsp->{'zipcode'}), 'phone' => $this->getField($rsp->{'phone'}), 'group' => $this->getField($rsp->{'categorycode'}), - ); + ]; return $profile; } else { return null; @@ -1211,7 +1220,7 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements { echo "<!--"; $id = $patron['id']; - $transactionLst = array(); + $transactionLst = []; $start = microtime(true); $rsp = $this->makeRequest( "GetPatronInfo&patron_id=$id" . "&show_contact=0&show_loans=1" @@ -1226,10 +1235,10 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements foreach ($rsp->{'loans'}->{'loan'} as $loan) { $start = microtime(true); $rsp2 = $this->makeIlsdiRequest( - "GetServices", array( - "patron_id" => $id, - "item_id" => $this->getField($loan->{'itemnumber'}) - ) + "GetServices", [ + "patron_id" => $id, + "item_id" => $this->getField($loan->{'itemnumber'}) + ] ); $end = microtime(true); $requestTimes[] = $end - $start; @@ -1240,11 +1249,11 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements } } - $transactionLst[] = array( + $transactionLst[] = [ 'duedate' => date_format( new \DateTime( $this->getField($loan->{'date_due'}) - ), + ), "m/d/Y" ), 'id' => $this->getField($loan->{'biblionumber'}), @@ -1252,7 +1261,7 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements 'barcode' => $this->getField($loan->{'barcode'}), 'renew' => $this->getField($loan->{'renewals'}, '0'), 'renewable' => $renewable, - ); + ]; } foreach ($requestTimes as $time) { echo "\n$time\n"; @@ -1261,7 +1270,6 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements return $transactionLst; } - /** * Get Renew Details * @@ -1293,7 +1301,7 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements */ public function renewMyItems($renewDetails) { - $retVal = array('blocks' => false, 'details' => array()); + $retVal = ['blocks' => false, 'details' => []]; $details = $renewDetails['details']; $patron_id = $renewDetails['patron']['id']; $request_prefix = "RenewLoan&patron_id=" . $patron_id . "&item_id="; @@ -1303,19 +1311,19 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements if ($rsp->{'success'} != '0') { list($date, $time) = explode(" ", $this->getField($rsp->{'date_due'})); - $retVal['details'][$renewItem] = array( + $retVal['details'][$renewItem] = [ "success" => true, "new_date" => $date, "new_time" => $time, "item_id" => $renewItem, - ); + ]; } else { - $retVal['details'][$renewItem] = array( + $retVal['details'][$renewItem] = [ "success" => false, "new_date" => false, "item_id" => $renewItem, //"sysMessage" => $this->getField($rsp->{'error'}), - ); + ]; } } return $retVal; @@ -1329,14 +1337,15 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements * * @param string $id The record id to retrieve the info for * - * @throws ILSException - * @return array An array with the acquisitions data on success. + * @throws ILSException + * @return array An array with the acquisitions data on success. + * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function getPurchaseHistory($id) { // TODO - return array(); + return []; } /** @@ -1369,9 +1378,9 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements */ public function getStatuses($idLst) { - $this->debug("IDs:".implode(',', $idLst)); + $this->debug("IDs:" . implode(',', $idLst)); - $statusLst = array(); + $statusLst = []; foreach ($idLst as $id) { $statusLst[] = $this->getStatus($id); } @@ -1393,12 +1402,12 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements $sql = "SELECT biblio.biblionumber AS biblionumber FROM biblioitems JOIN biblio USING (biblionumber) - WHERE ExtractValue( + WHERE ExtractValue( marcxml, '//datafield[@tag=\"942\"]/subfield[@code=\"n\"]' ) IN ('Y', '1')"; $sqlStmt = $this->db->prepare($sql); $sqlStmt->execute(); - $result = array(); + $result = []; foreach ($sqlStmt->fetchAll() as $rowItem) { $result[] = $rowItem["biblionumber"]; } @@ -1420,7 +1429,7 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements $sql = "SELECT DISTINCT department as abv, lib_opac AS DEPARTMENT FROM courses - INNER JOIN `authorised_values` + INNER JOIN `authorised_values` ON courses.department = `authorised_values`.`authorised_value`"; try { if (!$this->db) { @@ -1428,7 +1437,7 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements } $sqlStmt = $this->db->prepare($sql); $sqlStmt->execute(); - $result = array(); + $result = []; foreach ($sqlStmt->fetchAll() as $rowItem) { $deptList[$rowItem["abv"]] = $rowItem["DEPARTMENT"]; } @@ -1448,7 +1457,7 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements { $instList = []; - $sql = "SELECT DISTINCT borrowernumber, + $sql = "SELECT DISTINCT borrowernumber, CONCAT(firstname, ' ', surname) AS name FROM course_instructors LEFT JOIN borrowers USING(borrowernumber)"; @@ -1459,7 +1468,7 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements } $sqlStmt = $this->db->prepare($sql); $sqlStmt->execute(); - $result = array(); + $result = []; foreach ($sqlStmt->fetchAll() as $rowItem) { $instList[$rowItem["borrowernumber"]] = $rowItem["name"]; } @@ -1479,7 +1488,7 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements { $courseList = []; - $sql = "SELECT course_id, + $sql = "SELECT course_id, CONCAT (course_number, ' - ', course_name) AS course FROM courses WHERE enabled = 1"; @@ -1489,7 +1498,7 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements } $sqlStmt = $this->db->prepare($sql); $sqlStmt->execute(); - $result = array(); + $result = []; foreach ($sqlStmt->fetchAll() as $rowItem) { $courseList[$rowItem["course_id"]] = $rowItem["course"]; } @@ -1535,12 +1544,12 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements $reserveWhere = empty($reserveWhere) ? "" : "where (" . implode(' AND ', $reserveWhere) . ")"; - $sql = "SELECT biblionumber AS `BIB_ID`, - courses.course_id AS COURSE_ID, - course_instructors.borrowernumber as INSTRUCTOR_ID, - courses.department AS DEPARTMENT_ID + $sql = "SELECT biblionumber AS `BIB_ID`, + courses.course_id AS COURSE_ID, + course_instructors.borrowernumber as INSTRUCTOR_ID, + courses.department AS DEPARTMENT_ID FROM courses - INNER JOIN `authorised_values` + INNER JOIN `authorised_values` ON courses.department = `authorised_values`.`authorised_value` INNER JOIN `course_reserves` USING (course_id) INNER JOIN `course_items` USING (ci_id) @@ -1552,7 +1561,7 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements try { $sqlStmt = $this->db->prepare($sql, $bindParams); $sqlStmt->execute(); - $result = array(); + $result = []; foreach ($sqlStmt->fetchAll() as $rowItem) { $result[] = $rowItem; } @@ -1576,7 +1585,7 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements */ public function patronLogin($username, $password) { - $patron = array(); + $patron = []; // $idObj = $this->makeRequest( // "AuthenticatePatron" . "&username=" . $username @@ -1596,7 +1605,7 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements $rsp = $this->makeRequest( "GetPatronInfo&patron_id=$id&show_contact=1" ); - $profile = array( + $profile = [ 'id' => $this->getField($idObj->{'id'}), 'firstname' => $this->getField($rsp->{'firstname'}), 'lastname' => $this->getField($rsp->{'lastname'}), @@ -1605,7 +1614,7 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements 'email' => $this->getField($rsp->{'email'}), 'major' => null, 'college' => null, - ); + ]; return $profile; } else { return null;