Ejemplo n.º 1
0
 /**
  * Used to retrieve a set of employees assigned to a contract.
  *
  * @param id The contract id for which assigned employees are to be
  * retrieved.
  *
  * @param day The day for which contract assignments must be valid.
  *
  * @return Returns the requested contract employees.
  */
 public function getContractEmployees($id, $day = null)
 {
     // Make sure the id is valid.
     if (!isset($id) || !is_numeric($id)) {
         return array();
     }
     // Get the database adapter.
     $db = $this->getAdapter();
     // Set the fetch mode.
     $db->setFetchMode(Zend_Db::FETCH_OBJ);
     // Get the select object.
     $select = $db->select();
     // Get the DAO for the table we will be joining with.
     $assignmentDao = new ContractAssignmentDao();
     // Build the query.
     $select->from(array('a' => $assignmentDao->_name))->join(array('e' => $this->_name), 'a.employee_id = e.id', array('login', 'email', 'first_name', 'last_name', 'suffix', 'division', 'personnel_type', 'active'))->where('a.contract_id = ?', $id)->where('e.active = true');
     // Make sure the pay period is not null before adding the
     // clause to prevent expired contracts from being retrieved.
     if (isset($day)) {
         $select->where('start IS NULL OR start <= ?', $day);
         $select->where('end IS NULL OR end >= ?', $day);
     }
     // Add ordering.
     $this->setDefaultOrder($select);
     // Retrieve all the objects.
     $objs = $db->query($select)->fetchAll();
     // Perform post-processing on all the objects.
     if (isset($objs) && count($objs) > 0) {
         // Iterate over the identified employees.
         foreach ($objs as $obj) {
             // Make sure the employee id value is valid.
             if (is_numeric($obj->id)) {
                 // Set the employee's roles.
                 $roleDao = new RoleDao();
                 $obj->roles = $roleDao->getForEmployee($obj->id);
                 // Set the employee's supervisors.
                 $obj->supervisors = $this->getSupervisorEmployees($obj->id);
                 // Set the employees this employee is supervising.
                 $obj->supervised = $this->getSupervisedEmployees($obj->id);
             }
             // Perform the post-processing.
             $this->postProcess($obj);
         }
     }
     // Return the objects.
     return $objs;
 }
Ejemplo n.º 2
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);
 }