/** * Delete a employee. */ 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 employees."); } // Get the ids of the employees to delete. $ids = $this->getInts('ids'); // Determine if there are multiple employees to delete. $multiple = count($ids) > 1 ? true : false; // Wrap the whole thing in a try/catch. try { // Get the DAO. $employeeDao = new EmployeeDao(); // Delete all the employees. $count = $employeeDao->remove($ids); // Make sure some employees were deleted. if (isset($count) && $count > 0) { // Create the JSON object to return. $json = new stdClass(); $json->success = true; if ($multiple) { $json->msg = 'The employees were removed successfully.'; } else { $json->msg = 'The employee 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 employees.'; } else { $json->msg = 'Failed to delete the employee.'; } } } 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); }