Exemple #1
0
 public function createRemixProject($pagesNumber = 1, $parentProject, $user)
 {
     // copy the project
     $newProject = clone $parentProject;
     $newProject->setUser($user);
     $newProject->setRemixable(true);
     // clear the original project layers, frames, sequences
     $newProject->setLayers(new \Doctrine\Common\Collections\ArrayCollection());
     $newProject->setFrames(new \Doctrine\Common\Collections\ArrayCollection());
     $newProject->setSequences(new \Doctrine\Common\Collections\ArrayCollection());
     // clear cover image and title
     $newProject->setTitle("");
     $newProject->setCoverImage("");
     // create a new sequence and frames
     $sequence = new Sequence();
     $sequence->setEnabled(true);
     $frames = array();
     while ($pagesNumber > 0) {
         $frame = new Frame();
         $frame->setId(new \MongoId());
         $frame->setEnabled(true);
         $frame->setLayers(array());
         $newProject->addFrame($frame);
         $frames[] = (string) $frame->getId();
         --$pagesNumber;
     }
     $sequence->setFrames($frames);
     // get the soundtrack from the original project
     $parentProjectSequences = $parentProject->getSequences();
     if (isset($parentProjectSequences) && $parentProjectSequences->count() > 0) {
         $soundtrackSequence = $parentProjectSequences[0];
         $soundtrackSequenceAttributes = $soundtrackSequence->getAttr();
         if (isset($soundtrackSequenceAttributes) && isset($soundtrackSequenceAttributes["soundtrack"]) && is_string($soundtrackSequenceAttributes["soundtrack"])) {
             $soundtrackLayerId = $soundtrackSequenceAttributes["soundtrack"];
             $sequence->setAttr(array("soundtrack" => $soundtrackLayerId));
             $soundtrackLayer = $parentProject->getLayers()->filter(function ($layr) use($soundtrackLayerId) {
                 return $layr->getId() == $soundtrackLayerId;
             })->first();
             $newProject->addLayer($soundtrackLayer);
         }
     }
     $ancestors = $parentProject->getAncestors();
     if (isset($ancestors)) {
         foreach ($ancestors as $ancestor) {
             $newProject->addAncestor($ancestor);
         }
     }
     $newProject->addAncestor($parentProject);
     $newProject->setParentProject($parentProject);
     $rootProject = $parentProject->getRootProject();
     if (isset($rootProject)) {
         $newProject->setRootProject($parentProject->getRootProject());
     } else {
         $newProject->setRootProject($parentProject);
     }
     $newProject->addSequence($sequence);
     // persist the project
     $dm = $this->doctrine->getManager();
     $dm->persist($newProject);
     $dm->flush();
     $dm->clear();
     return $newProject;
 }