/** * Get Item Statuses * * This is responsible for printing the holdings information for a * collection of records in JSON format. * * @return void * @access public * @author Chris Delis <*****@*****.**> * @author Tuan Nguyen <*****@*****.**> */ public function getItemStatuses() { global $interface; global $configArray; $catalog = ConnectionManager::connectToCatalog(); if (!$catalog || !$catalog->status) { $this->output(translate('An error has occurred'), JSON::STATUS_ERROR); } $printIds = array(); $econtentIds = array(); $allIds = array(); foreach ($_GET['id'] as $id) { if (preg_match('/econtentRecord(\\d+)$/i', $id, $matches)) { $econtentIds[] = $matches[1]; } else { $printIds[] = $id; } } $allIds = array_merge($printIds, $econtentIds); $results = array(); if (count($printIds) > 0) { $results = $catalog->getStatuses($printIds); if (PEAR_Singleton::isError($results)) { $this->output($results->getMessage(), JSON::STATUS_ERROR); } else { if (!is_array($results)) { // If getStatuses returned garbage, let's turn it into an empty array // to avoid triggering a notice in the foreach loop below. $results = array(); } } } // In order to detect IDs missing from the status response, create an // array with a key for every requested ID. We will clear keys as we // encounter IDs in the response -- anything left will be problems that // need special handling. $missingIds = array_flip($printIds); // Load messages for response: $messages = array('available' => $interface->fetch('AJAX/status-available.tpl'), 'unavailable' => $interface->fetch('AJAX/status-unavailable.tpl')); // Load callnumber and location settings: $callnumberSetting = isset($configArray['Item_Status']['multiple_call_nos']) ? $configArray['Item_Status']['multiple_call_nos'] : 'msg'; $locationSetting = isset($configArray['Item_Status']['multiple_locations']) ? $configArray['Item_Status']['multiple_locations'] : 'msg'; // Loop through all the status information that came back $statuses = array(); foreach ($results as $record) { // Skip errors and empty records: if (!PEAR_Singleton::isError($record) && count($record)) { if ($locationSetting == "group") { $current = $this->_getItemStatusGroup($record, $messages, $callnumberSetting); } else { $current = $this->_getItemStatus($record, $messages, $locationSetting, $callnumberSetting); } $statuses[] = $current; // The current ID is not missing -- remove it from the missing list. unset($missingIds[$current['id']]); } } // If any IDs were missing, send back appropriate dummy data foreach ($missingIds as $missingId => $junk) { $statuses[] = array('id' => $missingId, 'availability' => 'false', 'availability_message' => $messages['unavailable'], 'location' => translate('Unknown'), 'locationList' => false, 'reserve' => 'false', 'reserve_message' => translate('Not On Reserve'), 'callnumber' => ''); } if (count($econtentIds) > 0) { require_once ROOT_DIR . '/Drivers/EContentDriver.php'; $econtentDriver = new EContentDriver(); $econtentResults = $econtentDriver->getStatuses($econtentIds); foreach ($econtentResults as $result) { $available = $result['available']; $interface->assign('status', $result['status']); if ($available) { $message = $interface->fetch('AJAX/status-available.tpl'); } else { $message = $interface->fetch('AJAX/status-unavailable.tpl'); } $statuses[] = array('id' => $result['id'], 'shortId' => $result['id'], 'availability' => $available ? 'true' : 'false', 'availability_message' => $message, 'location' => translate('Unknown'), 'locationList' => false, 'reserve' => 'false', 'reserve_message' => translate('Not On Reserve'), 'callnumber' => ''); } } // Done $this->output($statuses, JSON::STATUS_OK); }