Пример #1
0
 /**
  * Modify Overlap leave request
  * @param LeaveRequest $leaveRequest
  * @return boolean
  */
 public function modifyOverlapLeaveRequest(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());
     }
 }