/** * Delete a contract. */ public function deleteAction() { // Get the user's session. $session = new Zend_Session_Namespace('Web'); // Get the current user. if (!$session->employee->admin) { throw new Exception("Only administrators can delete contracts."); } // Get the ids of the contracts to delete. $ids = $this->getInts('ids'); // Determine if there are multiple contracts to delete. $multiple = count($ids) > 1 ? true : false; // Wrap the whole thing in a try/catch. try { // Get the DAO. $contractDao = new ContractDao(); // Delete all the contracts. $count = $contractDao->remove($ids); // Make sure some contracts were deleted. if (isset($count) && $count > 0) { // Create the JSON object to return. $json = new stdClass(); $json->success = true; if ($multiple) { $json->msg = 'The contracts were removed successfully.'; } else { $json->msg = 'The contract was removed successfully.'; } } else { // Create the error JSON object to return. $json = new stdClass(); $json->success = false; if ($multiple) { $json->msg = 'Failed to delete the contracts.'; } else { $json->msg = 'Failed to delete the contract.'; } } } catch (Zend_Exception $ex) { // Create the error JSON object to return. $json = new stdClass(); $json->success = false; $json->msg = $ex->getMessage(); } // Return the JSON. $this->_helper->json($json); }