Exemplo n.º 1
0
 /**
  *
  * @param array $changes
  * @param string $changeType
  * @return boolean
  */
 public function changeLeaveStatus($changes, $changeType, $changeComments = null, $changedByUserType = null, $changedUserId = null)
 {
     if (is_array($changes)) {
         $groupedChanges = $this->groupChanges($changes);
         $workflowService = $this->getAccessFlowStateMachineService();
         if ($changeType == 'change_leave_request') {
             foreach ($groupedChanges as $workFlowId => $changedItems) {
                 $workFlow = $workflowService->getWorkflowItem($workFlowId);
                 $nextStateStr = $workFlow->getResultingState();
                 $nextState = Leave::getLeaveStatusForText($nextStateStr);
                 $event = LeaveEvents::LEAVE_CHANGE;
                 //LeaveEvents::LEAVE_REJECT
                 //LeaveEvents::LEAVE_CANCEL
                 foreach ($changedItems as $leaveRequestId) {
                     $changedLeave = $this->searchLeave($leaveRequestId);
                     $this->_changeLeaveStatus($changedLeave, $nextState, $changeComments[$leaveRequestId]);
                     $this->_notifyLeaveStatusChange($event, $workFlow, $changedLeave, $changedByUserType, $changedUserId, 'request');
                 }
             }
         } elseif ($changeType == 'change_leave') {
             $actionTypes = count($groupedChanges);
             $workFlowItems = array();
             $changes = array();
             $allDays = array();
             foreach ($groupedChanges as $workFlowId => $changedItems) {
                 $workFlow = $workflowService->getWorkflowItem($workFlowId);
                 $workFlowItems[$workFlow->getId()] = $workFlow;
                 $nextStateStr = $workFlow->getResultingState();
                 $nextState = Leave::getLeaveStatusForText($nextStateStr);
                 $event = LeaveEvents::LEAVE_CHANGE;
                 //LeaveEvents::LEAVE_REJECT
                 //LeaveEvents::LEAVE_CANCEL
                 $changedLeave = array();
                 foreach ($changedItems as $leaveId) {
                     $changedLeave[] = $this->getLeaveRequestDao()->getLeaveById($leaveId);
                 }
                 $this->_changeLeaveStatus($changedLeave, $nextState, $changeComments);
                 if ($actionTypes == 1) {
                     $this->_notifyLeaveStatusChange($event, $workFlow, $changedLeave, $changedByUserType, $changedUserId, 'multiple');
                 } else {
                     $changes[$workFlow->getId()] = $changedLeave;
                     $allDays = array_merge($allDays, $changedLeave);
                 }
             }
             if ($actionTypes > 1) {
                 $this->_notifyLeaveMultiStatusChange($allDays, $changes, $workFlowItems, $changedByUserType, $changedUserId, 'multiple');
             }
         } else {
             throw new LeaveServiceException('Wrong change type passed');
         }
     } else {
         throw new LeaveServiceException('Empty changes list');
     }
 }
 /**
  * Returns leave status based on weekend and holiday
  * 
  * If weekend, returns Leave::LEAVE_STATUS_LEAVE_WEEKEND
  * If holiday, returns Leave::LEAVE_STATUS_LEAVE_HOLIDAY
  * Else, returns LEAVE_STATUS_LEAVE_PENDING_APPROVAL
  * 
  * @param $isWeekend boolean
  * @param $isHoliday boolean
  * @param $leaveDate string 
  * @return status
  * 
  * @todo Check usage of $leaveDate
  * 
  */
 public function getLeaveRequestStatus($isWeekend, $isHoliday, $leaveDate, LeaveParameterObject $leaveAssignmentData)
 {
     $status = null;
     if ($isWeekend) {
         $status = Leave::LEAVE_STATUS_LEAVE_WEEKEND;
     }
     if ($isHoliday) {
         $status = Leave::LEAVE_STATUS_LEAVE_HOLIDAY;
     }
     if (is_null($status)) {
         $workFlowItem = $this->getWorkflowItemForApplyAction($leaveAssignmentData);
         if (!is_null($workFlowItem)) {
             $status = Leave::getLeaveStatusForText($workFlowItem->getResultingState());
         } else {
             $status = Leave::LEAVE_STATUS_LEAVE_PENDING_APPROVAL;
         }
     }
     return $status;
 }
 /**
  *
  * @param type $isWeekend
  * @param type $isHoliday
  * @param type $leaveDate
  * @return type 
  */
 public function getLeaveRequestStatus($isWeekend, $isHoliday, $leaveDate, LeaveParameterObject $leaveAssignmentData)
 {
     // TODO: Change here for leave workflow
     $status = null;
     if ($isWeekend) {
         return Leave::LEAVE_STATUS_LEAVE_WEEKEND;
     }
     if ($isHoliday) {
         return Leave::LEAVE_STATUS_LEAVE_HOLIDAY;
     }
     if (is_null($status)) {
         $workFlowItem = $this->getWorkflowItemForAssignAction($leaveAssignmentData);
         if (!is_null($workFlowItem)) {
             $status = Leave::getLeaveStatusForText($workFlowItem->getResultingState());
         } else {
             throw new LeaveAllocationServiceException('Not Allowed to Assign Leave to Selected Employee!');
         }
         if ($status == Leave::LEAVE_STATUS_LEAVE_APPROVED && strtotime($leaveDate) < strtotime(date('Y-m-d'))) {
             $status = Leave::LEAVE_STATUS_LEAVE_TAKEN;
         }
     }
     return $status;
 }