public function getLeaveBreakdown()
 {
     $this->_fetchLeave();
     $statusStrings = array();
     foreach ($this->statusCounter as $status => $count) {
         if (!is_null($status)) {
             $statusStrings[] = __(ucwords(strtolower(Leave::getTextForLeaveStatus($status)))) . "(" . number_format($count, 2) . ")";
         }
     }
     return implode(', ', $statusStrings);
 }
 public function testGetLeaveRequestActionsESS()
 {
     $loggedInEmpNumber = 4;
     $cancelAction = new WorkflowStateMachine();
     $cancelAction->fromArray(array('id' => 3, 'workflow' => 'leave', 'state' => 'PENDING APPROVAL', 'role' => 'ADMIN', 'action' => 'CANCEL', 'resulting_state' => 'CANCELLED', 'roles_to_notify' => '', 'priority' => 0));
     $actions = array($cancelAction);
     $leave = $this->getMock('LeaveRequest', array('isStatusDiffer', 'getEmpNumber', 'getLeaveStatusId'));
     $leave->expects($this->once())->method('isStatusDiffer')->will($this->returnValue(false));
     $leave->expects($this->once())->method('getEmpNumber')->will($this->returnValue($loggedInEmpNumber));
     $leave->expects($this->once())->method('getLeaveStatusId')->will($this->returnValue(Leave::LEAVE_STATUS_LEAVE_PENDING_APPROVAL));
     $userManager = $this->getMock('BasicUserRoleManager', array('getAllowedActions'));
     $userManager->expects($this->any())->method('getAllowedActions')->with(WorkflowStateMachine::FLOW_LEAVE, Leave::getTextForLeaveStatus(Leave::LEAVE_STATUS_LEAVE_PENDING_APPROVAL), array(), array('ESS'))->will($this->returnValue($actions));
     $this->leaveRequestService->setUserRoleManager($userManager);
     $result = $this->leaveRequestService->getLeaveRequestActions($leave, $loggedInEmpNumber);
     $this->verifyLeaveActions($actions, $result);
 }
Exemplo n.º 3
0
 public function getLeaveRequestActions($request, $loggedInEmpNumber)
 {
     $actions = array();
     if (!$request->isStatusDiffer()) {
         $includeRoles = array();
         $excludeRoles = array();
         $userRoleManager = $this->getUserRoleManager();
         $empNumber = $request->getEmpNumber();
         // If looking at own leave request, only consider ESS role
         if ($empNumber == $loggedInEmpNumber && ($userRoleManager->essRightsToOwnWorkflow() || !$userRoleManager->isEntityAccessible('Employee', $empNumber))) {
             $includeRoles = array('ESS');
         }
         $leaveTypeDeleted = $request->getLeaveType()->getDeleted();
         $status = Leave::getTextForLeaveStatus($request->getLeaveStatusId());
         if ($leaveTypeDeleted) {
             $status = Leave::LEAVE_STATUS_LEAVE_TYPE_DELETED_TEXT . ' ' . $status;
         }
         $workFlowItems = $userRoleManager->getAllowedActions(WorkflowStateMachine::FLOW_LEAVE, $status, $excludeRoles, $includeRoles, array('Employee' => $empNumber));
         foreach ($workFlowItems as $item) {
             $name = $item->getAction();
             $actions[$item->getId()] = ucfirst(strtolower($name));
         }
     }
     return $actions;
 }