コード例 #1
0
 /**
  * Fired when a ResourceNode of type MediaResource is duplicated.
  *
  * @DI\Observe("copy_innova_media_resource")
  *
  * @param \Claroline\CoreBundle\Event\CopyResourceEvent $event
  *
  * @throws \Exception
  */
 public function onCopy(CopyResourceEvent $event)
 {
     $toCopy = $event->getResource();
     $new = new MediaResource();
     $new->setName($toCopy->getName());
     // copy options
     $this->container->get('innova_media_resource.manager.media_resource')->copyOptions($new, $toCopy);
     // duplicate media resource media(s) (=file(s))
     $medias = $toCopy->getMedias();
     foreach ($medias as $media) {
         $this->container->get('innova_media_resource.manager.media_resource')->copyMedia($new, $media);
     }
     // duplicate regions and region config
     $regions = $toCopy->getRegions();
     foreach ($regions as $region) {
         $this->container->get('innova_media_resource.manager.media_resource_region')->copyRegion($new, $region);
     }
     $event->setCopy($new);
     $event->stopPropagation();
 }