/**
  * Get the leave days and leave ids.
  *
  * @param integer $year year
  * @param integer $month month
  * @return array of leave data
  */
 private function getLeaveData($year, $month)
 {
     $em = $this->getDoctrine()->getManager();
     $leaveData['leaveDays'] = array();
     $leaveData['leaveIds'] = array();
     // Get the leave requests
     $leaveRequests = $em->getRepository('OpitOpitHrmLeaveBundle:LeaveRequest')->findApprovedLeaveRequestsByDates(date($year . '-' . $month . '-01'), date($year . '-' . $month . '-31'));
     // Fetch leaves for every leave day.
     foreach ($leaveRequests as $leaveRequest) {
         foreach ($leaveRequest->getLeaves() as $leave) {
             // Fetch leave ids to the serialization.
             $leaveData['leaveIds'][$leaveRequest->getId()][] = $leave->getId();
             $days = Utils::diffDays($leave->getStartDate(), $leave->getEndDate());
             // Fetch leave days by employee id and category name
             foreach ($days as $day) {
                 $leaveData['leaveDays'][$day->format('Y-m-d')][$leaveRequest->getEmployee()->getId()] = $leave->getCategory()->getName();
             }
         }
     }
     return $leaveData;
 }
Exemple #2
0
 public function testDiffDays()
 {
     $result = Utils::diffDays(new \DateTime('2014-01-01'), new \DateTime('2014-01-15'));
     $this->assertCount(15, $result, 'Utils::diffDays: Count does not match.');
     $this->assertTrue($result[0] instanceof \DateTime, 'Utils::diffDays: Wrong object type.');
     // Test overlapping month including time
     $result2 = Utils::diffDays(new \DateTime('2014-01-30 08:00:00'), new \DateTime('2014-02-02 07:00:00'));
     $this->assertCount(3, $result2, 'Utils::diffDays: Count does not match.');
 }