Пример #1
0
 /**
  * Get Patron Transactions
  *
  * This is responsible for retrieving all transactions (i.e. checked out items)
  * by a specific patron.
  *
  * @param array $patron The patron array from patronLogin
  *
  * @throws ILSException
  * @return mixed        Array of the patron's transactions on success.
  */
 public function getMyTransactions($patron)
 {
     // Get local loans from the database so that we can get more details
     // than available via the API.
     $transactions = parent::getMyTransactions($patron);
     // Get remote loans and renewability for local loans via the API
     // Build Hierarchy
     $hierarchy = ['patron' => $patron['id'], 'circulationActions' => 'loans'];
     // Add Required Params
     $params = ["patron_homedb" => $this->ws_patronHomeUbId, "view" => "full"];
     $results = $this->makeRequest($hierarchy, $params);
     if ($results === false) {
         throw new ILSException('System error fetching loans');
     }
     $replyCode = (string) $results->{'reply-code'};
     if ($replyCode != 0 && $replyCode != 8) {
         throw new ILSException('System error fetching loans');
     }
     if (isset($results->loans->institution)) {
         foreach ($results->loans->institution as $institution) {
             foreach ($institution->loan as $loan) {
                 if ($this->isLocalInst((string) $institution->attributes()->id)) {
                     // Take only renewability for local loans, other information
                     // we have already
                     $renewable = (string) $loan->attributes()->canRenew == 'Y';
                     foreach ($transactions as &$transaction) {
                         if (!isset($transaction['institution_id']) && $transaction['item_id'] == (string) $loan->itemId) {
                             $transaction['renewable'] = $renewable;
                             break;
                         }
                     }
                     continue;
                 }
                 $dueStatus = false;
                 $now = time();
                 $dueTimeStamp = strtotime((string) $loan->dueDate);
                 if ($dueTimeStamp !== false && is_numeric($dueTimeStamp)) {
                     if ($now > $dueTimeStamp) {
                         $dueStatus = 'overdue';
                     } else {
                         if ($now > $dueTimeStamp - 1 * 24 * 60 * 60) {
                             $dueStatus = 'due';
                         }
                     }
                 }
                 try {
                     $dueDate = $this->dateFormat->convertToDisplayDate('Y-m-d H:i', (string) $loan->dueDate);
                 } catch (DateException $e) {
                     // If we can't parse out the date, use the raw string:
                     $dueDate = (string) $loan->dueDate;
                 }
                 try {
                     $dueTime = $this->dateFormat->convertToDisplayTime('Y-m-d H:i', (string) $loan->dueDate);
                 } catch (DateException $e) {
                     // If we can't parse out the time, just ignore it:
                     $dueTime = false;
                 }
                 $transactions[] = ['id' => (string) $institution->attributes()->id . '_' . (string) $loan->itemId, 'item_id' => (string) $loan->itemId, 'duedate' => $dueDate, 'dueTime' => $dueTime, 'dueStatus' => $dueStatus, 'title' => (string) $loan->title, 'renewable' => (string) $loan->attributes()->canRenew == 'Y', 'institution_id' => (string) $institution->attributes()->id, 'institution_name' => (string) $loan->dbName, 'institution_dbkey' => (string) $loan->dbKey];
             }
         }
     }
     return $transactions;
 }
Пример #2
0
 /**
  * Protected support method for getMyTransactions.
  *
  * @param array $sqlRow An array of keyed data
  * @param array $patron An array of keyed patron data
  *
  * @return array Keyed data for display by template files
  */
 protected function processMyTransactionsData($sqlRow, $patron = false)
 {
     $transactions = parent::processMyTransactionsData($sqlRow, $patron);
     // Do we need to check renewals up front?  If so, do the check; otherwise,
     // set up fake "success" data to move us forward.
     $renewData = $this->checkRenewalsUpFront ? $this->isRenewable($patron['id'], $transactions['item_id']) : array('message' => false, 'renewable' => true);
     $transactions['renewable'] = $renewData['renewable'];
     $transactions['message'] = $renewData['message'];
     return $transactions;
 }