Beispiel #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;
 }
 /**
  * Create a global layer
  * Route: POST api/projects/:id/layers
  *
  * @return Layer|response
  */
 public function postProjectSequencesItemframesAction($sequenceId, $projectId)
 {
     $dm = $this->get('doctrine_mongodb')->getManager();
     $project = $dm->getRepository('ZeegaDataBundle:Project')->findOneById($projectId);
     // create ids for the frame and the layer
     $layerId = new \MongoId();
     $frameId = new \MongoId();
     // create the frame, set the id and add the layer
     $frame = new MongoFrame();
     $frame->setId($frameId);
     $frame->setLayers(array((string) $layerId));
     // create the layer and set the id
     $layer = new MongoLayer();
     $layer->setId($layerId);
     $layer->setEnabled(true);
     $request = $this->getRequest();
     if ($request->request->has("layer_type")) {
         $layer->setAttr($request->request->all());
         $layer->setType($request->request->get("layer_type"));
         $project->addLayer($layer);
     }
     // get the sequence and update the frames
     $sequence = $project->getSequences()->filter(function ($seq) use($sequenceId) {
         return $seq->getId() == $sequenceId;
     })->first();
     $sequenceFrames = $sequence->getFrames();
     array_push($sequenceFrames, (string) $frameId);
     $sequence->setFrames($sequenceFrames);
     // add the frame and the layer to the project; publish the project
     $project->addFrame($frame);
     $project->setPublished(true);
     $dm->persist($project);
     $dm->flush();
     $frame->setId((string) $frameId);
     // hack to properly display ids on the view; don't flush after this
     $frameView = $this->renderView('ZeegaApiBundle:Frames:show.json.twig', array('frame' => $frame));
     return new Response($frameView);
 }