/** * Process cancellation requests. * * @param \VuFind\ILS\Connection $catalog ILS connection object * @param array $patron Current logged in patron * * @return array The result of the cancellation, an * associative array keyed by item ID (empty if no cancellations performed) */ public function cancelShortLoanRequests($catalog, $patron) { // Retrieve the flashMessenger helper: $flashMsg = $this->getController()->flashMessenger(); $params = $this->getController()->params(); // Pick IDs to cancel based on which button was pressed: $all = $params->fromPost('cancelAll'); $selected = $params->fromPost('cancelSelected'); if (!empty($all)) { $details = $params->fromPost('cancelAllIDS'); } else { if (!empty($selected)) { $details = $params->fromPost('cancelSelectedIDS'); } else { // No button pushed -- no action needed return array(); } } if (!empty($details)) { // Confirm? if ($params->fromPost('confirm') === "0") { if ($params->fromPost('cancelAll') !== null) { return $this->getController()->confirm('hold_cancel_all', $this->getController()->url()->fromRoute('myresearch-bookings'), $this->getController()->url()->fromRoute('myresearch-bookings'), 'confirm_hold_cancel_all_text', array('cancelAll' => 1, 'cancelAllIDS' => $params->fromPost('cancelAllIDS'))); } else { return $this->getController()->confirm('hold_cancel_selected', $this->getController()->url()->fromRoute('myresearch-bookings'), $this->getController()->url()->fromRoute('myresearch-bookings'), 'confirm_hold_cancel_selected_text', array('cancelSelected' => 1, 'cancelSelectedIDS' => $params->fromPost('cancelSelectedIDS'))); } } foreach ($details as $info) { // If the user input contains a value not found in the session // whitelist, something has been tampered with -- abort the process. if (!in_array($info, $this->getSession()->validIds)) { $flashMsg->setNamespace('error')->addMessage('error_inconsistent_parameters'); return array(); } } // Add Patron Data to Submitted Data $cancelResults = $catalog->cancelShortLoanRequest(array('details' => $details, 'patron' => $patron)); if ($cancelResults == false) { $flashMsg->setNamespace('error')->addMessage('hold_cancel_fail'); } else { if ($cancelResults['count'] > 0) { // TODO : add a mechanism for inserting tokens into translated // messages so we can avoid a double translation here. $msg = $this->getController()->translate('hold_cancel_success_items'); $flashMsg->setNamespace('info')->addMessage($cancelResults['count'] . ' ' . $msg); } return $cancelResults; } } else { $flashMsg->setNamespace('error')->addMessage('hold_empty_selection'); } return array(); }