Ejemplo n.º 1
0
 public function getMyHolds($patron = null, $page = 1, $recordsPerPage = -1, $sortOption = 'title')
 {
     global $timer;
     $patronDump = $this->driver->_getPatronDump($this->driver->_getBarcode());
     //Load the information from millennium using CURL
     $sResult = $this->driver->_fetchPatronInfoPage($patronDump, 'holds');
     $timer->logTime("Got holds page from Millennium");
     $holds = $this->parseHoldsPage($sResult);
     $timer->logTime("Parsed Holds page");
     require_once ROOT_DIR . '/RecordDrivers/MarcRecord.php';
     foreach ($holds as $section => $holdSections) {
         foreach ($holdSections as $key => $hold) {
             disableErrorHandler();
             $recordDriver = new MarcRecord($hold['recordId']);
             if ($recordDriver->isValid()) {
                 $hold['id'] = $recordDriver->getUniqueID();
                 $hold['shortId'] = $recordDriver->getShortId();
                 //Load title, author, and format information about the title
                 $hold['title'] = $recordDriver->getTitle();
                 $hold['sortTitle'] = $recordDriver->getSortableTitle();
                 $hold['author'] = $recordDriver->getAuthor();
                 $hold['format'] = $recordDriver->getFormat();
                 $hold['isbn'] = $recordDriver->getCleanISBN();
                 $hold['upc'] = $recordDriver->getCleanUPC();
                 $hold['format_category'] = $recordDriver->getFormatCategory();
                 //Load rating information
                 $hold['ratingData'] = $recordDriver->getRatingData();
                 $holds[$section][$key] = $hold;
             }
             enableErrorHandler();
         }
     }
     //Process sorting
     //echo ("<br/>\r\nSorting by $sortOption");
     foreach ($holds as $sectionName => $section) {
         $sortKeys = array();
         $i = 0;
         foreach ($section as $key => $hold) {
             $sortTitle = isset($hold['sortTitle']) ? $hold['sortTitle'] : (isset($hold['title']) ? $hold['title'] : "Unknown");
             if ($sectionName == 'available') {
                 $sortKeys[$key] = $sortTitle;
             } else {
                 if ($sortOption == 'title') {
                     $sortKeys[$key] = $sortTitle;
                 } elseif ($sortOption == 'author') {
                     $sortKeys[$key] = (isset($hold['author']) ? $hold['author'] : "Unknown") . '-' . $sortTitle;
                 } elseif ($sortOption == 'placed') {
                     $sortKeys[$key] = $hold['createTime'] . '-' . $sortTitle;
                 } elseif ($sortOption == 'format') {
                     $sortKeys[$key] = (isset($hold['format']) ? $hold['format'] : "Unknown") . '-' . $sortTitle;
                 } elseif ($sortOption == 'location') {
                     $sortKeys[$key] = (isset($hold['location']) ? $hold['location'] : "Unknown") . '-' . $sortTitle;
                 } elseif ($sortOption == 'holdQueueLength') {
                     $sortKeys[$key] = (isset($hold['holdQueueLength']) ? $hold['holdQueueLength'] : 0) . '-' . $sortTitle;
                 } elseif ($sortOption == 'position') {
                     $sortKeys[$key] = str_pad(isset($hold['position']) ? $hold['position'] : 1, 3, "0", STR_PAD_LEFT) . '-' . $sortTitle;
                 } elseif ($sortOption == 'status') {
                     $sortKeys[$key] = (isset($hold['status']) ? $hold['status'] : "Unknown") . '-' . (isset($hold['reactivateTime']) ? $hold['reactivateTime'] : "0") . '-' . $sortTitle;
                 } else {
                     $sortKeys[$key] = $sortTitle;
                 }
                 //echo ("<br/>\r\nSort Key for $key = {$sortKeys[$key]}");
             }
             $sortKeys[$key] = strtolower($sortKeys[$key] . '-' . $i++);
         }
         array_multisort($sortKeys, $section);
         $holds[$sectionName] = $section;
     }
     //Limit to a specific number of records
     if (isset($holds['unavailable'])) {
         $numUnavailableHolds = count($holds['unavailable']);
         if ($recordsPerPage != -1) {
             $startRecord = ($page - 1) * $recordsPerPage;
             $holds['unavailable'] = array_slice($holds['unavailable'], $startRecord, $recordsPerPage);
         }
     } else {
         $numUnavailableHolds = 0;
     }
     if (!isset($holds['available'])) {
         $holds['available'] = array();
     }
     if (!isset($holds['unavailable'])) {
         $holds['unavailable'] = array();
     }
     //Sort the hold sections so available holds are first.
     ksort($holds);
     $patronId = isset($patron) ? $patron['id'] : $this->driver->_getBarcode();
     $this->holds[$patronId] = $holds;
     $timer->logTime("Processed hold pagination and sorting");
     return array('holds' => $holds, 'numUnavailableHolds' => $numUnavailableHolds);
 }
Ejemplo n.º 2
0
 public function getMyHolds($patron = null, $page = 1, $recordsPerPage = -1, $sortOption = 'title')
 {
     global $configArray;
     if ($patron) {
         if (is_object($patron)) {
             $patron = get_object_vars($patron);
         }
         $userId = $patron['id'];
         $userName = $patron['cat_username'];
         $userPassword = $patron['cat_password'];
     } else {
         global $user;
         $userId = $user->id;
         $userName = $user->cat_username;
         $userPassword = $user->cat_password;
     }
     $availableHolds = array();
     $unavailableHolds = array();
     $holds = array('available' => $availableHolds, 'unavailable' => $unavailableHolds);
     //Get the session token for the user
     if (isset(HorizonAPI::$sessionIdsForUsers[$userId])) {
         $sessionToken = HorizonAPI::$sessionIdsForUsers[$userId];
     } else {
         //Log the user in
         list($userValid, $sessionToken) = $this->loginViaWebService($userName, $userPassword);
         if (!$userValid) {
             //				echo("No session id found for user"); //should log this instead
             return $holds;
         }
     }
     //Now that we have the session token, get holds information
     $lookupMyAccountInfoResponse = $this->getWebServiceResponse($configArray['Catalog']['webServiceUrl'] . '/standard/lookupMyAccountInfo?clientID=' . $configArray['Catalog']['clientId'] . '&sessionToken=' . $sessionToken . '&includeHoldInfo=true');
     if (isset($lookupMyAccountInfoResponse->HoldInfo)) {
         require_once ROOT_DIR . '/RecordDrivers/MarcRecord.php';
         foreach ($lookupMyAccountInfoResponse->HoldInfo as $hold) {
             $curHold = array();
             $bibId = (string) $hold->titleKey;
             $curHold['id'] = $bibId;
             $curHold['holdSource'] = 'ILS';
             $curHold['itemId'] = (string) $hold->itemKey;
             $curHold['cancelId'] = (string) $hold->holdKey;
             $curHold['position'] = (string) $hold->queuePosition;
             $curHold['recordId'] = $bibId;
             $curHold['shortId'] = $bibId;
             $curHold['title'] = (string) $hold->title;
             $curHold['author'] = (string) $hold->author;
             $curHold['location'] = (string) $hold->pickupLocDescription;
             //$curHold['locationId'] = $matches[1];
             $curHold['locationUpdateable'] = true;
             $curHold['currentPickupName'] = $curHold['location'];
             $curHold['status'] = ucfirst(strtolower((string) $hold->status));
             $expireDate = (string) $hold->expireDate;
             $curHold['expire'] = $expireDate;
             $curHold['expireTime'] = strtotime($expireDate);
             $reactivateDate = (string) $hold->reactivateDate;
             $curHold['reactivate'] = $reactivateDate;
             $curHold['reactivateTime'] = strtotime($reactivateDate);
             $curHold['cancelable'] = strcasecmp($curHold['status'], 'Suspended') != 0;
             $curHold['frozen'] = strcasecmp($curHold['status'], 'Suspended') == 0;
             if ($curHold['frozen']) {
                 $curHold['reactivateTime'] = (int) $hold->reactivateDate;
             }
             $curHold['freezeable'] = true;
             $curHold['sortTitle'] = (string) $hold->title;
             $recordDriver = new MarcRecord($bibId);
             if ($recordDriver->isValid()) {
                 $curHold['sortTitle'] = $recordDriver->getSortableTitle();
                 $curHold['format'] = $recordDriver->getFormat();
                 $curHold['isbn'] = $recordDriver->getCleanISBN();
                 $curHold['upc'] = $recordDriver->getCleanUPC();
                 $curHold['format_category'] = $recordDriver->getFormatCategory();
                 //Load rating information
                 $curHold['ratingData'] = $recordDriver->getRatingData();
             }
             if (!isset($curHold['status']) || strcasecmp($curHold['status'], "filled") != 0) {
                 $holds['unavailable'][] = $curHold;
             } else {
                 $holds['available'][] = $curHold;
             }
         }
     }
     return array('holds' => $holds, 'numUnavailableHolds' => count($holds['unavailable']));
 }
Ejemplo n.º 3
0
 /**
  * Get Patron Holds
  *
  * This is responsible for retrieving all holds by a specific patron.
  *
  * @param array|User $patron      The patron array from patronLogin
  * @param integer $page           The current page of holds
  * @param integer $recordsPerPage The number of records to show per page
  * @param string $sortOption      How the records should be sorted
  * @param string $summaryPage     If the summary page has already been loaded, it can be passed in for performance reasons.
  *
  * @return mixed        Array of the patron's holds on success, PEAR_Error
  * otherwise.
  * @access public
  */
 public function getMyHoldsFromDB($patron, $page = 1, $recordsPerPage = -1, $sortOption = 'title')
 {
     global $user;
     $availableHolds = array();
     $unavailableHolds = array();
     $holds = array('available' => $availableHolds, 'unavailable' => $unavailableHolds);
     $this->initDatabaseConnection();
     $sql = "SELECT *, title, author FROM reserves inner join biblio on biblio.biblionumber = reserves.biblionumber where borrowernumber = ?";
     $holdsStmt = mysqli_prepare($this->dbConnection, $sql);
     $holdsStmt->bind_param('i', $user->username);
     $holdsStmt->execute();
     $results = $holdsStmt->get_result();
     while ($curRow = $results->fetch_assoc()) {
         //Each row in the table represents a hold
         $curHold = array();
         $curHold['holdSource'] = 'ILS';
         $bibId = $curRow['biblionumber'];
         $curHold['id'] = $curRow['biblionumber'];
         $curHold['shortId'] = $curRow['biblionumber'];
         $curHold['recordId'] = $curRow['biblionumber'];
         $curHold['title'] = $curRow['title'];
         $curHold['create'] = date_parse_from_format('Y-M-d H:m:s', $curRow['reservedate']);
         $curHold['expire'] = date_parse_from_format('Y-M-d', $curRow['expirationdate']);
         $curHold['location'] = $curRow['branchcode'];
         $curHold['locationUpdateable'] = false;
         $curHold['currentPickupName'] = $curHold['location'];
         $curHold['position'] = $curRow['priority'];
         $curHold['frozen'] = false;
         $curHold['freezeable'] = false;
         $curHold['cancelable'] = true;
         if ($curRow['found'] == 'S') {
             $curHold['frozen'] = true;
             $curHold['status'] = "Suspended";
             $curHold['cancelable'] = false;
         } elseif ($curRow['found'] == 'W') {
             $curHold['status'] = "Ready to Pickup";
         } elseif ($curRow['found'] == 'T') {
             $curHold['status'] = "In Transit";
         } else {
             $curHold['status'] = "Pending";
             $curHold['freezeable'] = true;
         }
         $curHold['freezeable'] = true;
         $curHold['cancelId'] = $curRow['reservenumber'];
         if ($bibId) {
             require_once ROOT_DIR . '/RecordDrivers/MarcRecord.php';
             $recordDriver = new MarcRecord($bibId);
             if ($recordDriver->isValid()) {
                 $curHold['sortTitle'] = $recordDriver->getSortableTitle();
                 $curHold['format'] = $recordDriver->getFormat();
                 $curHold['isbn'] = $recordDriver->getCleanISBN();
                 $curHold['upc'] = $recordDriver->getCleanUPC();
                 $curHold['format_category'] = $recordDriver->getFormatCategory();
                 //Load rating information
                 $curHold['ratingData'] = $recordDriver->getRatingData();
             }
         }
         if (!isset($curHold['status']) || !preg_match('/^Item waiting.*/i', $curHold['status'])) {
             $holds['unavailable'][] = $curHold;
         } else {
             $holds['available'][] = $curHold;
         }
     }
     return array('holds' => $holds, 'numUnavailableHolds' => count($holds['unavailable']));
 }