/**
  * Modify Overlap leave request
  * @param LeaveRequest $leaveRequest
  * @return boolean
  */
 public function xmodifyOverlapLeaveRequest(LeaveRequest $leaveRequest, $leaveList, $leavePeriod = null)
 {
     try {
         $nextLeavePeriod = false;
         $nextLeaveRequest = false;
         if ($leavePeriod == null) {
             $leavePeriod = Doctrine::getTable('LeavePeriod')->find($leaveRequest->getLeavePeriodId());
         }
         foreach ($leaveList as $leave) {
             if ($leave->getLeaveDate() > $leavePeriod->getEndDate()) {
                 if (!$nextLeavePeriod instanceof LeavePeriod) {
                     $leavePeriodService = new LeavePeriodService();
                     $leavePeriodService->setLeavePeriodDao(new LeavePeriodDao());
                     $nextLeavePeriod = $leavePeriodService->createNextLeavePeriod($leave->getLeaveDate());
                     $nextLeaveRequest = new LeaveRequest();
                     $idGenService = new IDGeneratorService();
                     $idGenService->setEntity($leaveRequest);
                     $nextLeaveRequest->setLeaveRequestId($idGenService->getNextID());
                     $nextLeaveRequest->setLeaveTypeId($leaveRequest->getLeaveTypeId());
                     $nextLeaveRequest->setDateApplied($leaveRequest->getDateApplied());
                     $nextLeaveRequest->setLeavePeriodId($nextLeavePeriod->getLeavePeriodId());
                     $nextLeaveRequest->setLeaveTypeName($leaveRequest->getLeaveTypeName());
                     $nextLeaveRequest->setEmpNumber($leaveRequest->getEmpNumber());
                     $nextLeaveRequest->setLeaveComments($leaveRequest->getLeaveComments());
                     $nextLeaveRequest->save();
                 }
                 $q = Doctrine_Query::create()->update('Leave l')->set('l.leave_request_id=', $nextLeaveRequest->getLeaveRequestId())->where('l.leave_id = ?', $leave->getLeaveId());
                 $q->execute();
             }
         }
         return true;
     } catch (Exception $e) {
         throw new DaoException($e->getMessage());
     }
 }
 public function xtestAdjustLeavePeriodOverlapLeaves()
 {
     $leaveList = TestDataService::loadObjectList('Leave', $this->fixture, 'set4');
     $leavePeriod = new LeavePeriod();
     $leavePeriod->setLeavePeriodId(11);
     $leavePeriod->setStartDate("2008-01-31");
     $leavePeriod->setEndDate("2009-01-31");
     $leaveRequestDao = $this->getMock('LeaveRequestDao', array('getLeavePeriodOverlapLeaves', 'fetchLeave', 'modifyOverlapLeaveRequest'));
     $leave = $leaveList[0];
     $leaveRequest = new LeaveRequest();
     $leaveRequest->setLeaveRequestId($leave->getLeaveRequestId());
     $leave->setLeaveRequest($leaveRequest);
     $leaveRequestDao->expects($this->once())->method('getLeavePeriodOverlapLeaves')->with($leavePeriod)->will($this->returnValue(array($leave)));
     $leaveRequestDao->expects($this->once())->method('fetchLeave')->with($leave->getLeaveRequestId())->will($this->returnValue($leaveList));
     $leaveRequestDao->expects($this->once())->method('modifyOverlapLeaveRequest')->with($leave->getLeaveRequest(), $leaveList, $leavePeriod);
     $this->leaveRequestService->setLeaveRequestDao($leaveRequestDao);
     $this->leaveRequestService->adjustLeavePeriodOverlapLeaves($leavePeriod);
 }
 public function testChangeLeaveStatusForLeave()
 {
     $leaveRequest = new LeaveRequest();
     $leaveRequest->setLeaveRequestId(1);
     $leave = new Leave();
     $leave->setLeaveRequest($leaveRequest);
     $changes = array(1 => 'markedForApproval', 21 => 'markedForRejection', 31 => 'markedForCancellation');
     $changeType = 'change_leave';
     $leaveRequestDao = $this->getMock('LeaveRequestDao', array('getLeaveById'));
     $leaveRequestDao->expects($this->any())->method('getLeaveById')->will($this->returnValue($leave));
     $this->leaveRequestService->setLeaveRequestDao($leaveRequestDao);
     $mockLeaveStateManager = new MockLeaveStateManager();
     $this->leaveRequestService->setLeaveStateManager($mockLeaveStateManager);
     $leaveNotificationService = $this->getMock('LeaveNotificationService', array('approve', 'cancel', 'reject', 'cancelEmployee'));
     $this->leaveRequestService->setLeaveNotificationService($leaveNotificationService);
     $this->leaveRequestService->changeLeaveStatus($changes, $changeType);
 }