예제 #1
0
 /**
  * Update the employee's profile information.
  */
 public function updateAction()
 {
     // 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'));
         // Set the hashed password value if necessary.
         $password = $this->getStr('password');
         if (isset($password)) {
             $data['hashed_pass'] = hash('SHA512', $password);
         }
         // Make sure the id is set.
         if (isset($me) && isset($me->id) && is_numeric($me->id)) {
             // Get the DAO.
             $employeeDao = new EmployeeDao();
             // Save the new values.
             $employeeDao->save($me->id, $data);
             // Retrieve the updated employee.
             $employee = $employeeDao->get($me->id);
             // Make sure the employee was returned.
             if (isset($employee)) {
                 // Create the JSON object to return.
                 $json = new stdClass();
                 $json->success = true;
                 $json->msg = 'Your profile was updated successfully.';
                 $json->employee = $employee;
             } else {
                 // Create the error JSON object to return.
                 $json = new stdClass();
                 $json->success = false;
                 $json->msg = 'Failed to update your profile.';
             }
         } else {
             // Create the error JSON object to return.
             $json = new stdClass();
             $json->success = false;
             $json->msg = 'Unable to find your profile.';
         }
     } 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);
 }
예제 #2
0
 /**
  * Used to enhance the provided timesheet with data from other tables.
  *
  * @param obj The timesheet object to enhance.
  *
  * @return Returns the enhanced timesheet.
  */
 public function enhanceTimesheet($obj)
 {
     // Set the other timesheet information.
     if (is_numeric($obj->id)) {
         // Set the bills in the timesheet.
         $billDao = new BillDao();
         $obj->bills = $billDao->getForTimesheet($obj->id, $obj->employee_id);
         // Set the employee.
         $employeeDao = new EmployeeDao();
         $obj->employee = $employeeDao->get($obj->employee_id);
         // Set the audit log info.
         $auditLogDao = new AuditLogDao();
         $obj->audit_log = $auditLogDao->getForTimesheet($obj->id);
         // Set the pay period.
         $payPeriodDao = new PayPeriodDao();
         $obj->pay_period = $payPeriodDao->get($obj->pp_start);
         // Set the employee's contracts.
         $contractDao = new ContractDao();
         $obj->contracts = $contractDao->getEmployeeContractsForPayPeriod($obj->employee_id, $obj->pay_period);
         // Set the holidays.
         $holidayDao = new HolidayDao();
         $obj->holidays = $holidayDao->getForPayPeriod($obj->pay_period);
     }
     // Perform post-processing.
     $this->postProcess($obj);
     // Return the enhanced timesheet object.
     return $obj;
 }
예제 #3
0
 /**
  * Update a employee.
  */
 public function updateAction()
 {
     // 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');
         if (isset($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 id of the employee to modify.
         $id = $this->getInt('id');
         // Make sure the id is set.
         if (isset($id)) {
             // Get the DAO.
             $employeeDao = new EmployeeDao();
             // Save the new values.
             $employeeDao->save($id, $data);
             // Retrieve the updated employee.
             $employee = $employeeDao->get($id);
             // Make sure the employee was returned.
             if (isset($employee)) {
                 // Get the RoleDao.
                 $roleDao = new RoleDao();
                 // Remove any existing privileges for this employee.
                 $roleDao->removeForEmployee($employee->id);
                 // Check to see if privileges need to be added.
                 if (count($privileges) > 0) {
                     // Create the roles for this user.
                     foreach ($privileges as $priv) {
                         // Add this role.
                         $roleDao->add(array('name' => $priv, 'employee_id' => $employee->id));
                     }
                 }
                 // Create the JSON object to return.
                 $json = new stdClass();
                 $json->success = true;
                 $json->msg = 'The employee was updated successfully.';
                 $json->employee = $employee;
             } else {
                 // Create the error JSON object to return.
                 $json = new stdClass();
                 $json->success = false;
                 $json->msg = 'Failed to update the employee.';
             }
         } else {
             // Create the error JSON object to return.
             $json = new stdClass();
             $json->success = false;
             $json->msg = 'The id of the employee to modify must ' . 'be specified.';
         }
     } 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);
 }