/**
  * Get the timesheet page fly on mode.
  * The generated timesheets are not saved.
  *
  * @param string $action the action's name.
  * @param string $token query parameters.
  * @return resource the html page.
  */
 private function getTimeSheetPage($action, $token)
 {
     $em = $this->getDoctrine()->getManager();
     $config = $this->container->getParameter('opit_opit_hrm_leave');
     $arrivalTime = $config['time_sheet']['arrival_time'];
     $lunchTimeInMinutes = $config['time_sheet']['lunch_time_in_minutes'];
     $divison = $config['time_sheet']['user_grouping_number'];
     $startDate = new \DateTime(date('Y-m-01'));
     $year = date('Y');
     $month = date('m');
     if (false === strrpos($arrivalTime, ':')) {
         $arrivalTime = $arrivalTime . ':00';
     }
     $requestQuery = base64_decode($token);
     $tokenArray = explode('|', $requestQuery);
     $dateArray = array('year' => $tokenArray[0], 'month' => $tokenArray[1]);
     // If the year and month parameters are exist then set them.
     if (isset($dateArray['year']) && isset($dateArray['month'])) {
         $year = $dateArray['year'];
         $month = $dateArray['month'];
         $startDate->setDate($year, $month, 1);
     }
     $leaveDatesOfMonth = array();
     $leaveDates = $em->getRepository('OpitOpitHrmLeaveBundle:LeaveDate')->findAllFiltered(array('year' => array($year), 'month' => array($month)));
     // Grouping the leave dates by the date.
     foreach ($leaveDates as $leaveDate) {
         $leaveDatesOfMonth[$leaveDate->getHolidayDate()->format('Y-m-d')] = $leaveDate->getHolidayType();
     }
     // Get the role hierarchy.
     $hierarchy = $this->container->getParameter('security.role_hierarchy.roles');
     // Get all roles which are above the user role in the role hierarchy as time sheet only requires role user and above
     $higherRoles = Utils::getHigherLevelRoles($hierarchy);
     // Get the leave data
     $leaveData = $this->getLeaveData($year, $month);
     $leaveIds = $leaveData['leaveIds'];
     $leaveDays = $leaveData['leaveDays'];
     $this->syncLeaves($leaveIds, $year, $month, $action);
     // Get the days of the actual month.
     $endDate = clone $startDate;
     $endDate->modify('last day of this month');
     $daysOfMonth = Utils::diffDays($startDate, $endDate);
     // Get the employees by the roles and employement.
     $users = $em->getRepository('OpitOpitHrmUserBundle:User')->findEmployedUsers('', new \DateTime($dateArray['year'] . '-' . $dateArray['month']), new \DateTime($dateArray['year'] . '-' . $dateArray['month'] . '-' . count($daysOfMonth)), $higherRoles);
     // Grouping users into subarrays.
     $groupedUsers = Utils::groupingArrayByCounter($users, $divison);
     return $this->render('OpitOpitHrmLeaveBundle:TimeSheet:showTimeSheet.html.twig', array('action' => $action, 'groupedUsers' => $groupedUsers, 'daysOfMonth' => $daysOfMonth, 'leaveDatesOfMonth' => $leaveDatesOfMonth, 'leaveDays' => $leaveDays, 'arrivalTime' => $arrivalTime, 'lunchTimeInMinutes' => $lunchTimeInMinutes, 'division' => $divison, 'year' => $year, 'month' => $month));
 }
Exemple #2
0
 public function testGetHigherLevelRoles()
 {
     $hierarchy = array('ROLE_CUSTOMER' => array(), 'ROLE_USER' => array('ROLE_CUSTOMER'), 'ROLE_PAYROLL' => array('ROLE_CUSTOMER'), 'ROLE_STAKEHOLDER' => array('ROLE_CUSTOMER'), 'ROLE_FINANCE' => array('ROLE_CUSTOMER'), 'ROLE_TEAM_MANAGER' => array('ROLE_USER'), 'ROLE_GENERAL_MANAGER' => array('ROLE_TEAM_MANAGER'), 'ROLE_SYSTEM_ADMIN' => array('ROLE_CUSTOMER', 'ROLE_PAYROLL', 'ROLE_STAKEHOLDER', 'ROLE_FINANCE', 'ROLE_USER'), 'ROLE_ADMIN' => array('ROLE_GENERAL_MANAGER', 'ROLE_SYSTEM_ADMIN'), 'ROLE_SUPER_ADMIN' => array('ROLE_ADMIN', 'ROLE_ALLOWED_TO_SWITCH'));
     $expectedResult = array('ROLE_USER', 'ROLE_TEAM_MANAGER', 'ROLE_GENERAL_MANAGER', 'ROLE_SYSTEM_ADMIN', 'ROLE_ADMIN', 'ROLE_SUPER_ADMIN');
     $role = 'ROLE_USER';
     $result = Utils::getHigherLevelRoles($hierarchy, $role);
     $this->assertTrue(is_array($result), 'Utils::getHigherLevelRoles The result is not an array.');
     $this->assertEquals($expectedResult, $result, 'Utils::getHigherLevelRoles The expected result is not equal to received result.');
 }