Пример #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;
 }
Пример #2
0
 /**
  * Create a new project
  * Route: POST api/projects
  *
  * @return Project id|response
  */
 public function postProjectAction()
 {
     $user = $this->get('security.context')->getToken()->getUser();
     $request = $this->getRequest();
     if ($request->request->has('title')) {
         $title = $request->request->get('title');
         $project->setTitle($title);
     }
     if ($request->request->has('version')) {
         $version = $request->request->get('version');
     } else {
         $version = 1.1;
     }
     $frame = new MongoFrame();
     $frame->setId(new \MongoId());
     $frame->setEnabled(true);
     $frame->setLayers(array());
     $sequence = new MongoSequence();
     $sequence->setEnabled(true);
     $sequence->setFrames(array((string) $frame->getId()));
     $project = new MongoProject();
     $project->setDateCreated(new \DateTime("now"));
     $project->setEnabled(true);
     $project->setPublished(false);
     $project->setAuthors($user->getDisplayName());
     $project->setUser($user);
     $project->setMobile(true);
     $project->setVersion($version);
     $project->addSequence($sequence);
     $project->addFrame($frame);
     $dm = $this->get('doctrine_mongodb')->getManager();
     $dm->persist($project);
     $dm->flush();
     return new Response($project->getPublicId());
 }