コード例 #1
0
 public function updateBeneficiaryEvent($beneficiaryId, $event)
 {
     // Create sub-events
     $recurrence = $event->getRecurrence();
     if (null != $recurrence && $recurrence->getNb() > 1) {
         // Remove previous events
         $childs = $event->getChilds();
         if (null == $childs && $childs->count() <= 0 && null != $event->getParent() && null != $event->getParent()->getChilds() && $event->getParent()->getChilds()->count() >= 0) {
             $childs = $parent->getChilds();
         }
         $childsSize = $childs->count();
         $stillSomeChild = true;
         $participants = $event->getParticipants();
         $nbEvent = $event->getRecurrence()->getNb();
         for ($i = 0; $i < $nbEvent - 1; $i++) {
             // Update childs (if any)
             if ($stillSomeChild && $i < $childsSize) {
                 $subEvent = $childs->get($i);
                 $subEvent->setObject('[' . $event->getCategory() . '] ' . $event->getObject());
             } else {
                 $stillSomeChild = false;
                 $subEvent = new Event('[' . $event->getCategory() . '] ' . $event->getObject());
             }
             foreach ($participants as $participant) {
                 $subEvent->addParticipant($participant);
             }
             $diff = '+' . ($i + 1) * $event->getRecurrence()->getFrequency() . ' ' . $event->getRecurrence()->getType();
             $dateStart = clone $event->getDateStart();
             $dateEnd = clone $event->getDateEnd();
             $subEvent->setDateStart($dateStart->modify($diff));
             $subEvent->setDateEnd($dateEnd->modify($diff));
             $subEvent->setRecurrence($recurrence);
             $event->addChild($subEvent);
         }
         // Remove remaining childs (if any)
         if ($stillSomeChild) {
             for ($i = $i; $i < $childsSize; $i++) {
                 $child = $childs->get($i);
                 $event->removeChild($i);
                 $this->em->remove($child);
                 $childsSize--;
                 $i--;
             }
         }
     }
     $this->em->persist($event);
     $this->em->flush();
     return $event->getId();
 }