Exemple #1
0
 /**
  * Test Utils::groupingArrayByCounter
  */
 public function testgroupingArrayByCounter()
 {
     $input = array(array('User 1'), array('User 2'), array('User 3'), array('User 4'), array('User 5'), array('User 6'));
     $result = Utils::groupingArrayByCounter($input, 2);
     $this->assertCount(3, $result, 'Utils::groupingArrayByCounter: Count does not match.');
     $this->assertEquals(array(array(array('User 1'), array('User 2')), array(array('User 3'), array('User 4')), array(array('User 5'), array('User 6'))), $result, 'Utils::arrayValueRecursive: Arrays do not match.');
 }
 /**
  * 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));
 }