/** * * @param \Opit\OpitHrm\LeaveBundle\Entity\LeaveRequest $resource * @param boolean $toGeneralManager * @param \Opit\OpitHrm\StatusBundle\Entity\Status $status */ public function addNewLeaveNotification(LeaveRequest $resource, $toGeneralManager, Status $status) { // get last status name from resource $resourceStatus = strtolower($status->getName()); $message = $resource->getLeaveRequestId(); if (strpos('approved', $resourceStatus) !== false || strpos('rejected', $resourceStatus) !== false) { $message .= ' has been ' . $resourceStatus; $message = ucfirst($message); } else { $message .= ' changed to ' . $resourceStatus; } $message .= ' for ' . $resource->getEmployee()->getEmployeeName() . '.'; $receiver = false === $toGeneralManager ? $this->entityManager->getRepository('OpitOpitHrmUserBundle:User')->findOneByEmployee($resource->getEmployee()) : $resource->getGeneralManager(); $notification = new LRNotification(); $notification->setLeaveRequest($resource); $notification->setMessage($message); $notification->setReceiver($receiver); $notification->setDateTime(new \DateTime('now')); $this->setNotificationStatus($notification); $this->entityManager->persist($notification); // Send notifications to additional recipients if status is set to approved if ($status->getId() === Status::APPROVED) { if ($teamManager = $resource->getTeamManager()) { $notificationsTM = clone $notification; $notificationsTM->setReceiver($teamManager); $this->entityManager->persist($notificationsTM); } $ccRecipients = $this->entityManager->getRepository('OpitOpitHrmUserBundle:Employee')->findNotificationRecipients($receiver); $notifications = array(); foreach ($ccRecipients as $i => $employee) { $notifications[$i] = clone $notification; $notifications[$i]->setReceiver($employee->getUser()); $this->entityManager->persist($notifications[$i]); } } $this->entityManager->flush(); }
/** * Compare the date overlapping between leave requests * * @param \Opit\OpitHrm\LeaveBundle\Entity\LeaveRequest $currentLR * @param \Opit\OpitHrm\LeaveBundle\Entity\LeaveRequest $otherLR * @return array of date overlappings */ public function compareLRDateOverlapping($currentLR, $otherLR) { $dateOverlappings = array(); // Iterate the current leave request's leaves. foreach ($currentLR->getLeaves() as $currentElement) { // Iterate the other leave request' leaves. foreach ($otherLR->getLeaves() as $otherElement) { // Checking the date overlapping. if ($currentElement->getStartDate() <= $otherElement->getEndDate() && $otherElement->getStartDate() <= $currentElement->getEndDate()) { $dateOverlappings[$otherLR->getLeaveRequestId()] = array('startDate' => $otherElement->getStartDate(), 'endDate' => $otherElement->getEndDate()); break; } } } return $dateOverlappings; }