diff --git a/module/VuFind/src/VuFind/Controller/AjaxController.php b/module/VuFind/src/VuFind/Controller/AjaxController.php index 5bbdca9fcffc40f2011a8d57968802888f23c66c..43d0eb7773fe75c6a1e8d0db3bdd210ff7784b5a 100644 --- a/module/VuFind/src/VuFind/Controller/AjaxController.php +++ b/module/VuFind/src/VuFind/Controller/AjaxController.php @@ -895,68 +895,70 @@ class AjaxController extends AbstractBase $id = $this->params()->fromQuery('id'); $data = $this->params()->fromQuery('data'); $requestType = $this->params()->fromQuery('requestType'); - if (!empty($id) && !empty($data)) { - // check if user is logged in - $user = $this->getUser(); - if (!$user) { - return $this->output( - [ - 'status' => false, - 'msg' => $this->translate('You must be logged in first') - ], - self::STATUS_NEED_AUTH, - 401 - ); - } + if (empty($id) || empty($data)) { + return $this->output( + $this->translate('bulk_error_missing'), + self::STATUS_ERROR, + 400 + ); + } + // check if user is logged in + $user = $this->getUser(); + if (!$user) { + return $this->output( + $this->translate('You must be logged in first'), + self::STATUS_NEED_AUTH, + 401 + ); + } - try { - $catalog = $this->getILS(); - $patron = $this->getILSAuthenticator()->storedCatalogLogin(); - if ($patron) { - switch ($requestType) { - case 'ILLRequest': - $results = $catalog->checkILLRequestIsValid( - $id, $data, $patron - ); + try { + $catalog = $this->getILS(); + $patron = $this->getILSAuthenticator()->storedCatalogLogin(); + if ($patron) { + switch ($requestType) { + case 'ILLRequest': + $results = $catalog->checkILLRequestIsValid( + $id, $data, $patron + ); - $msg = $results - ? $this->translate( - 'ill_request_place_text' - ) - : $this->translate( - 'ill_request_error_blocked' - ); - break; - case 'StorageRetrievalRequest': - $results = $catalog->checkStorageRetrievalRequestIsValid( - $id, $data, $patron + $msg = $results + ? $this->translate( + 'ill_request_place_text' + ) + : $this->translate( + 'ill_request_error_blocked' ); + break; + case 'StorageRetrievalRequest': + $results = $catalog->checkStorageRetrievalRequestIsValid( + $id, $data, $patron + ); - $msg = $results - ? $this->translate( - 'storage_retrieval_request_place_text' - ) - : $this->translate( - 'storage_retrieval_request_error_blocked' - ); - break; - default: - $results = $catalog->checkRequestIsValid( - $id, $data, $patron + $msg = $results + ? $this->translate( + 'storage_retrieval_request_place_text' + ) + : $this->translate( + 'storage_retrieval_request_error_blocked' ); - - $msg = $results - ? $this->translate('request_place_text') - : $this->translate('hold_error_blocked'); - break; - } - return $this->output( - ['status' => $results, 'msg' => $msg], self::STATUS_OK + break; + default: + $results = $catalog->checkRequestIsValid( + $id, $data, $patron ); + + $msg = $results + ? $this->translate('request_place_text') + : $this->translate('hold_error_blocked'); + break; } - } catch (\Exception $e) { - // Do nothing -- just fail through to the error message below. + return $this->output( + ['status' => $results, 'msg' => $msg], self::STATUS_OK + ); } + } catch (\Exception $e) { + // Do nothing -- just fail through to the error message below. } return $this->output( @@ -984,7 +986,9 @@ class AjaxController extends AbstractBase $comment = $this->params()->fromPost('comment'); if (empty($id) || empty($comment)) { return $this->output( - $this->translate('An error has occurred'), self::STATUS_ERROR, 400 + $this->translate('bulk_error_missing'), + self::STATUS_ERROR, + 400 ); } @@ -1016,13 +1020,17 @@ class AjaxController extends AbstractBase $id = $this->params()->fromQuery('id'); if (empty($id)) { return $this->output( - $this->translate('An error has occurred'), self::STATUS_ERROR, 400 + $this->translate('bulk_error_missing'), + self::STATUS_ERROR, + 400 ); } $table = $this->getTable('Comments'); if (!$table->deleteIfOwnedByUser($id, $user)) { return $this->output( - $this->translate('An error has occurred'), self::STATUS_ERROR, 403 + $this->translate('edit_list_fail'), + self::STATUS_ERROR, + 405 ); } @@ -1169,43 +1177,45 @@ class AjaxController extends AbstractBase $this->writeSession(); // avoid session write timing bug $id = $this->params()->fromQuery('id'); $pickupLib = $this->params()->fromQuery('pickupLib'); - if (!empty($id) && !empty($pickupLib)) { - // check if user is logged in - $user = $this->getUser(); - if (!$user) { - return $this->output( - [ - 'status' => false, - 'msg' => $this->translate('You must be logged in first') - ], - self::STATUS_NEED_AUTH, - 401 - ); - } + if (empty($id) || empty($pickupLib)) { + return $this->output( + $this->translate('bulk_error_missing'), + self::STATUS_ERROR, + 400 + ); + } + // check if user is logged in + $user = $this->getUser(); + if (!$user) { + return $this->output( + $this->translate('You must be logged in first'), + self::STATUS_NEED_AUTH, + 401 + ); + } - try { - $catalog = $this->getILS(); - $patron = $this->getILSAuthenticator()->storedCatalogLogin(); - if ($patron) { - $results = $catalog->getILLPickupLocations( - $id, $pickupLib, $patron - ); - foreach ($results as &$result) { - if (isset($result['name'])) { - $result['name'] = $this->translate( - 'location_' . $result['name'], - [], - $result['name'] - ); - } + try { + $catalog = $this->getILS(); + $patron = $this->getILSAuthenticator()->storedCatalogLogin(); + if ($patron) { + $results = $catalog->getILLPickupLocations( + $id, $pickupLib, $patron + ); + foreach ($results as &$result) { + if (isset($result['name'])) { + $result['name'] = $this->translate( + 'location_' . $result['name'], + [], + $result['name'] + ); } - return $this->output( - ['locations' => $results], self::STATUS_OK - ); } - } catch (\Exception $e) { - // Do nothing -- just fail through to the error message below. + return $this->output( + ['locations' => $results], self::STATUS_OK + ); } + } catch (\Exception $e) { + // Do nothing -- just fail through to the error message below. } return $this->output( @@ -1223,49 +1233,52 @@ class AjaxController extends AbstractBase $this->writeSession(); // avoid session write timing bug $id = $this->params()->fromQuery('id'); $requestGroupId = $this->params()->fromQuery('requestGroupId'); - if (!empty($id) && !empty($requestGroupId)) { - // check if user is logged in - $user = $this->getUser(); - if (!$user) { - return $this->output( - [ - 'status' => false, - 'msg' => $this->translate('You must be logged in first') - ], - self::STATUS_NEED_AUTH, - 401 - ); - } + if (empty($id) || empty($requestGroupId)) { + return $this->output( + $this->translate('bulk_error_missing'), + self::STATUS_ERROR, + 400 + ); + } + // check if user is logged in + $user = $this->getUser(); + if (!$user) { + return $this->output( + $this->translate('You must be logged in first'), + self::STATUS_NEED_AUTH, + 401 + ); + } - try { - $catalog = $this->getILS(); - $patron = $this->getILSAuthenticator()->storedCatalogLogin(); - if ($patron) { - $details = [ - 'id' => $id, - 'requestGroupId' => $requestGroupId - ]; - $results = $catalog->getPickupLocations( - $patron, $details - ); - foreach ($results as &$result) { - if (isset($result['locationDisplay'])) { - $result['locationDisplay'] = $this->translate( - 'location_' . $result['locationDisplay'], - [], - $result['locationDisplay'] - ); - } + try { + $catalog = $this->getILS(); + $patron = $this->getILSAuthenticator()->storedCatalogLogin(); + if ($patron) { + $details = [ + 'id' => $id, + 'requestGroupId' => $requestGroupId + ]; + $results = $catalog->getPickupLocations( + $patron, $details + ); + foreach ($results as &$result) { + if (isset($result['locationDisplay'])) { + $result['locationDisplay'] = $this->translate( + 'location_' . $result['locationDisplay'], + [], + $result['locationDisplay'] + ); } - return $this->output( - ['locations' => $results], self::STATUS_OK - ); } - } catch (\Exception $e) { - // Do nothing -- just fail through to the error message below. + return $this->output( + ['locations' => $results], self::STATUS_OK + ); } + } catch (\Exception $e) { + // Do nothing -- just fail through to the error message below. } + return $this->output( $this->translate('An error has occurred'), self::STATUS_ERROR, 500 );