/**
  * Persist template and move zip archive's elements.
  *
  * @param Layout $layout
  */
 public function save(Layout $layout)
 {
     $archiveDir = $this->getUploadDir() . '/archives';
     $templateDir = $this->getUploadDir() . '/templates';
     $tmpDir = $this->getUploadDir() . '/tmp/' . time();
     // Copy the archive to the archive directory
     $file = $layout->getFile()->move($archiveDir, $layout->getFile()->getClientOriginalName());
     // Extract the archive
     $zip = new \ZipArchive();
     $zip->open($archiveDir . '/' . $layout->getFile()->getClientOriginalName());
     $zip->extractTo($tmpDir);
     $zip->close();
     $id = $this->getUniqueId($layout);
     $config = $this->readConfiguration($tmpDir);
     // Move the assets
     $this->moveFiles(array('*.png', '*.jpg'), $tmpDir, $templateDir . '/img/' . $id);
     $this->moveFiles('*.twig', $tmpDir, $templateDir . '/twig/' . $id);
     $this->moveFiles('*.css', $tmpDir, $templateDir . '/css/' . $id, false);
     // If the layout has a fonts directory, we copy this directory to the css one.
     if ($fontsDirs = $this->getDirectories($tmpDir, 'fonts')) {
         $this->filesystem->remove($templateDir . '/css/' . $id . '/fonts');
         $this->filesystem->rename(current($fontsDirs), $templateDir . '/css/' . $id . '/fonts', true);
     }
     // Remove the tmp directory
     $this->filesystem->remove($tmpDir);
     $this->saveInDb($config['label'], 'uploads/' . $id . '/' . $config['templateName'], '/bundles/canaltpmtt/img/uploads/' . $id . '/' . $config['previewFileName'], $config['orientation']);
 }
Example #2
0
 public function getLayouts()
 {
     $defaultLayout = new Layout();
     $landscapeLayout = new Layout();
     $landscapeLayout->setOrientation(LAYOUT::ORIENTATION_LANDSCAPE);
     $portraitLayout = new Layout();
     $portraitLayout->setOrientation(LAYOUT::ORIENTATION_PORTRAIT);
     $nonExistingOrientationLayout = new Layout();
     $nonExistingOrientationLayout->setOrientation('whatever');
     return array(array($defaultLayout, 'landscape'), array($landscapeLayout, 'landscape'), array($portraitLayout, 'portrait'), array($nonExistingOrientationLayout, 'landscape'));
 }
 private function createLayout($layoutProperties, $networks = array())
 {
     $layout = new Layout();
     $layout->setLabel($layoutProperties['label']);
     $layout->setPath($layoutProperties['path']);
     $layout->setPreviewPath($layoutProperties['previewPath']);
     $layout->setOrientation($layoutProperties['orientation']);
     $layout->setNotesModes($layoutProperties['notesModes']);
     $layout->setCssVersion($layoutProperties['cssVersion']);
     $this->om->persist($layout);
     return $layout;
 }
Example #4
0
 private function createLayout(ObjectManager $em, $layoutProperties, $perimeters = array())
 {
     $layout = new Layout();
     $layout->setLabel($layoutProperties['label']);
     $layout->setTwig($layoutProperties['twig']);
     $layout->setPreview($layoutProperties['preview']);
     $layout->setOrientation($layoutProperties['orientation']);
     $layout->setCalendarStart($layoutProperties['calendarStart']);
     $layout->setCalendarEnd($layoutProperties['calendarEnd']);
     $layout->setPerimeters($perimeters);
     foreach ($perimeters as $perimeter) {
         $perimeter->addLayout($layout);
         $em->persist($perimeter);
     }
     $em->persist($layout);
     return $layout;
 }