/** * Delete a supervisor. */ public function deleteAction() { // Get the employee id for which supervisors are to be deleted. $empId = $this->getInt('employee_id'); // Get the ids of the supervisors to delete. $ids = $this->getInts('supervisor_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. $supervisorDao = new SupervisorDao(); // Delete all the supervisors. $count = $supervisorDao->removeAll($empId, $ids); // Make sure some supervisors were deleted. if (isset($count) && $count > 0) { // Create the JSON object to return. $json = new stdClass(); $json->success = true; if ($multiple) { $json->msg = 'The supervisors were removed successfully.'; } else { $json->msg = 'The supervisor 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 supervisors.'; } else { $json->msg = 'Failed to delete the supervisor.'; } } } 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); }
/** * Add a employee. */ public function addAction() { // Get the user's session. $session = new Zend_Session_Namespace('Web'); // Get the current user. $me = $session->employee; // Wrap the whole thing in a try/catch. try { // Create an array of the fields that represent the employee. $data = array('first_name' => $this->getStr('first_name'), 'last_name' => $this->getStr('last_name'), 'suffix' => $this->getStr('suffix'), 'login' => $this->getStr('login'), 'email' => $this->getStr('email'), 'division' => $this->getStr('division'), 'personnel_type' => $this->getStr('personnel_type'), 'active' => $this->getBool('active')); // Set the hashed password value if necessary. $password = $this->getStr('password'); $data['hashed_pass'] = hash('SHA512', $password); // Collect the privileges for this user. $privileges = array(); if ($this->getBool('admin') && $me->admin) { $privileges[] = 'admin'; } if ($this->getBool('payroll') && ($me->payroll || $me->admin)) { $privileges[] = 'payroll'; } if ($this->getBool('manager') && ($me->manager || $me->admin)) { $privileges[] = 'manager'; } if ($this->getBool('security') && ($me->security || $me->admin)) { $privileges[] = 'security'; } // Get the DAO. $employeeDao = new EmployeeDao(); // Check to see if the login already exists. $exists = $employeeDao->getEmployeeByLogin($data['login']); // Check to see if the requested login already exists. if (isset($exists)) { // Create the error JSON object to return. $json = new stdClass(); $json->success = false; $json->msg = 'Failed to create the employee - an account ' . 'with the specified login already exists.'; } else { // Add the employee. $id = $employeeDao->add($data); // Retrieve the new employee. $employee = $employeeDao->get($id); // Make sure the employee was returned. if (isset($employee)) { // Check to see if privileges need to be added. if (count($privileges) > 0) { // Get the RoleDao. $roleDao = new RoleDao(); // Create the roles for this user. foreach ($privileges as $priv) { // Add this role. $roleDao->add(array('name' => $priv, 'employee_id' => $employee->id)); } } // Get the primary supervisor id. $supervisor = $this->getInt('supervisor'); // Make sure the supervisor is valid. if (isset($supervisor) && is_numeric($supervisor)) { // Get the DAO. $supervisorDao = new SupervisorDao(); // Add the primary supervisor. $supervisorDao->add(array('employee_id' => $employee->id, 'supervisor_id' => $supervisor, 'primary' => true)); } // Create the JSON object to return. $json = new stdClass(); $json->success = true; $json->msg = 'The employee was created successfully.'; $json->employee = $employee; } else { // Create the error JSON object to return. $json = new stdClass(); $json->success = false; $json->msg = 'Failed to create 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); }