result->code ?? null; if ($code == 'od_code_login_for_avail') { $loginForAvail = true; } elseif ($code == 'od_account_noaccess') { $noshow = true; } elseif ($code == 'od_code_resource_not_found' || empty($this->result->status)) { // we must have had a connection error. $isError = true; } $data = []; foreach ($ids as $id) { $current = []; $current['status'] = 'OK'; $current['id'] = $id; $avail = $this->result->data[$id] ?? (object)['code' => '']; $current['full_status'] = ''; if ($noshow) { // patron does not have access to overdrive. don't show avail } elseif ((isset($avail->code) && $avail->code == 'od_code_resource_not_found') || $isError) { $current['error'] = $this->transEsc('status_unknown_message'); } elseif ($loginForAvail) { $current['full_status'] = "

" . $this->transEsc('od_code_login_for_avail') . '

'; } else { $current['full_status'] .= '

'; if ($avail->copiesAvailable > 0) { $current['full_status'] .= ''; $current['full_status'] .= $this->icon('status-available', 'icon-link__icon'); $current['full_status'] .= ' '; } else { $current['full_status'] .= ''; $current['full_status'] .= $this->icon('status-unavailable', 'icon-link__icon'); $current['full_status'] .= ' '; } $copies = $avail->availabilityType == 'AlwaysAvailable' ? $this->transEsc('od_unlimited') : ($avail->copiesAvailable . ' / ' . $avail->copiesOwned); $current['full_status'] .= ' ' . $this->transEsc('od_copies_available', ['%%copies%%' => $copies]); if ($avail->numberOfHolds > 0) { $current['full_status'] .= '; ' . $this->transEsc('od_waiting', ['holds' => $avail->numberOfHolds], null, true); } } $data[] = $current; } // JSON response. Array of HTML strings. echo json_encode(['data' => ['statuses' => $data]]);