Пример #1
0
 /**
  * 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;
 }
Пример #2
0
 /**
  * Test case for delete function
  */
 public function testDelete()
 {
     // Invalid emp number
     $empLoc = new EmpLocation('a1', 'LOC001');
     try {
         $empLoc->delete();
         $this->fail("Exception expected");
     } catch (EmpLocationException $e) {
         $this->assertEquals(EmpLocationException::INVALID_PARAMETER, $e->getCode());
     }
     // Invalid location code
     $empLoc = new EmpLocation(11, 'LOCX001');
     try {
         $empLoc->delete();
         $this->fail("Exception expected");
     } catch (EmpLocationException $e) {
         $this->assertEquals(EmpLocationException::INVALID_PARAMETER, $e->getCode());
     }
     // Not assigned location
     $this->assertEquals(0, $this->_getNumRows('emp_number = 13'));
     $empLoc = new EmpLocation(13, 'LOC002');
     $empLoc->delete();
     $this->assertEquals(0, $this->_getNumRows('emp_number = 13'));
     $this->assertEquals(2, $this->_getNumRows('emp_number = 12'));
     $empLoc = new EmpLocation(12, 'LOC004');
     $empLoc->delete();
     $this->assertEquals(2, $this->_getNumRows('emp_number = 12'));
     // Emp Number and location ok
     $empLoc = new EmpLocation(12, 'LOC002');
     $empLoc->delete();
     $this->assertEquals(1, $this->_getNumRows('emp_number = 12'));
     $empLoc = new EmpLocation(12, 'LOC003');
     $empLoc->delete();
     $this->assertEquals(0, $this->_getNumRows('emp_number = 12'));
 }