/** * Creates a EmpLocation object from a resultset row * * @param array $row Resultset row from the database. * @return EmpLocation EmpLocation object. */ private static function _createFromRow($row) { $empLocation = new EmpLocation(); $empLocation->setEmpNumber($row[self::DB_FIELD_EMP_NUMBER]); $empLocation->setLocation($row[self::DB_FIELD_LOC_CODE]); $empLocation->setLocationName($row[self::FIELD_LOCATION_NAME]); return $empLocation; }
/** * Remove given location from employee * * @param int $empNumber Employee number * @param string $locationCode Location code to remove * * @return boolean true if successfully assigned, false otherwise */ public function removeLocation($empNumber, $locationCode) { $result = false; $auth = new authorize($_SESSION['empID'], $_SESSION['isAdmin']); /* Only allow admins and supervisors of the given employee to assign locations */ if ($auth->isAdmin() || $auth->isSupervisor() && $auth->isTheSupervisor($empNumber)) { $empLocation = new EmpLocation($empNumber, $locationCode); try { $empLocation->delete(); $result = true; $history = new LocationHistory(); $history->updateHistory($empNumber, $locationCode, true); } catch (EmpLocationException $e) { } } return $result; }
/** * Assign Location * * @param EmpLocation $empLocation Employee location to assign */ private function _assignLocation($empLocation) { $sql = sprintf("INSERT INTO hs_hr_emp_locations(emp_number, loc_code) " . "VALUES(%d, '%s')", $empLocation->getEmpNumber(), $empLocation->getLocation()); $this->_runQuery($sql); }