src/Controller/Gallery3DController.php line 54

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Doctrine\Persistence\ManagerRegistry;
  4. use Symfony\Component\HttpKernel\KernelInterface;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\Form\Extension\Core\Type\TextType;
  10. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  11. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  12. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  13. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  14. use Symfony\Component\Form\Extension\Core\Type\FileType;
  15. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  16. use Symfony\Component\Console\Input\ArrayInput;
  17. use Symfony\Bundle\FrameworkBundle\Console\Application;
  18. use Ivory\CKEditorBundle\Form\Type\CKEditorType;
  19. use Symfony\Component\Finder\Finder;
  20. use App\Entity\User;
  21. use App\Entity\Gallery;
  22. use App\Entity\GalleryItem;
  23. use App\Entity\Gallery3D;
  24. use App\Entity\FreeWorld3D;
  25. use Symfony\Contracts\Translation\TranslatorInterface;
  26. use Twig\Environment;
  27. class Gallery3DController extends DefaultController
  28. {
  29.     protected ManagerRegistry $doctrine;
  30.     protected TranslatorInterface $translator;
  31.     protected KernelInterface $appKernel;
  32.     protected Environment $twig;
  33.     public function __construct(ManagerRegistry $doctrine,
  34.                                 TranslatorInterface $translator,
  35.                                 KernelInterface $appKernel,
  36.                                 Environment $twig)
  37.     {
  38.         $this->doctrine $doctrine;
  39.         $this->translator $translator;
  40.         $this->appKernel $appKernel;
  41.         $this->twig $twig;
  42.     }
  43.     /**
  44.      * @Route("/user/{userId}/gallery3D/{gallery3DId}", name="gallery3D")
  45.      */
  46.     public function gallery3DAction(Request $request$userId$gallery3DId)
  47.     {
  48.     
  49.         /* we load session data */
  50.         parent::init($request);
  51.         $session $request->getSession();
  52.         $logger $this->getLogger(null'gallery 3D: '.$gallery3DId);
  53.         //print('<br>QQW user ID: ');
  54.         //\Doctrine\Common\Util\Debug::dump($category);
  55.         /* we load entity managers */
  56.         $em $this->doctrine->getManager();
  57.         $dem $this->doctrine->getManager('dynamic_em');
  58.         
  59.         /* we get current user */
  60.         $user $em->getRepository(User::class)->getUser($userId);
  61.         /* we get current 3D gallery */
  62.         $gallery3D $dem->getRepository(Gallery3D::class)->getGallery3D($gallery3DId);
  63.         /* we check if 3D gallery exists
  64.         if(empty($gallery3D)) {
  65.             $this->addFlash('error', '3D gallery with this ID does not exists 22.');
  66.             die('3D gallery with this ID does not exists 22.');
  67.             return $this->redirectToRoute('Home');
  68.         }  
  69.          */
  70.  
  71.         // we get parent gallery items
  72.         $galleryItemCollection null;
  73.         if(!empty($gallery3D->getGallery())) {
  74.             $galId $gallery3D->getGallery()->getGalleryId();
  75.             $galleryItemCollection $dem->getRepository(GalleryItem::class)->getGalleryItemList($galId);
  76.         }
  77.        
  78.         // we get texture gallery items
  79.         $textureItemCollection null;
  80.         if(!empty($gallery3D->getTextureGallery())) {
  81.             $galId $gallery3D->getTextureGallery()->getGalleryId();
  82.             $textureItemCollection $dem->getRepository(GalleryItem::class)->getGalleryItemList($galId);
  83.         }       
  84.         //print('<br>QQW textureItemCollection: ');
  85.         //\Doctrine\Common\Util\Debug::dump($textureItemCollection); 
  86.         //foreach($textureItemCollection as $texture) {
  87.             //print('<hr>QQW texture: ');
  88.             //\Doctrine\Common\Util\Debug::dump($texture); 
  89.         //}
  90.         // we get 3D template
  91.         if(!empty($gallery3D->getTemplate3DPath())) {
  92.             $template3D $gallery3D->getTemplate3DPath();
  93.         } else {       
  94.             $template3D "gallery3D/gallery3D.html.php";
  95.         }
  96.         /*
  97.         print('<br>QQW gallery ID: '.$gallery3DId);
  98.         print('<br>QQW gallery: ');
  99.         \Doctrine\Common\Util\Debug::dump($gallery);
  100.         */
  101.         $userDirs $this->getUserFolderPathsFromUserId($user->getUserId());
  102.         
  103.         if((!empty($gallery3D->isIsMediumResize()) && $gallery3D->isIsMediumResize() == true) || $request->request->get('isFullscreen')==='false') {
  104.             $isFullscreen false;
  105.         } else {
  106.             $isFullscreen true;
  107.         }          
  108.         if($request->request->get('header')==='false') {  
  109.             $isHeader false;
  110.         } else {
  111.             $isHeader true;
  112.         }     
  113.         if(!empty($request->request->get('is_footer')) && $request->request->get('footer')=='false') {  
  114.             $isFooter false;
  115.         } else {
  116.             $isFooter true;
  117.         }
  118.         
  119.         $template3D 'gallery3D/gallery3D.html.php';
  120.         if(!empty($gallery3D->getTemplate3DPath())) {
  121.           $template3D 'gallery3D/'.$gallery3D->getTemplate3DPath();
  122.         }
  123.         $freeWorld null;
  124.         if(!empty($gallery3D->getFreeWorld())) {
  125.             $freeWorldId $gallery3D->getFreeWorld()->getFreeWorld3DId();
  126.             $freeWorld $dem->getRepository(FreeWorld3D::class)->getFreeWorld3D($freeWorldId);
  127.             //print('<br>QQW freeWorld: '.$gallery3D->getFreeWorld()->getFreeWorld3DId());
  128.             //\Doctrine\Common\Util\Debug::dump($freeWorld);
  129.         }
  130.         //adds php functions to twig environment
  131.         $this->twig->addFunction(new \Twig\TwigFunction('deg2rad''deg2rad'));
  132.         $this->twig->addFunction(new \Twig\TwigFunction('sin''sin'));
  133.         $this->twig->addFunction(new \Twig\TwigFunction('imagecreatefromstring''imagecreatefromstring'));
  134.         $this->twig->addFunction(new \Twig\TwigFunction('file_get_contents''file_get_contents'));
  135.         $this->twig->addFunction(new \Twig\TwigFunction('ImageSX''ImageSX'));
  136.         $this->twig->addFunction(new \Twig\TwigFunction('ImageSY''ImageSY'));
  137.         /* we render 3D template HTML, PHP, X3D */
  138.         $response $this->render($template3D,
  139.             array(      'headerData' => '',
  140.                         'gallery3D' => $gallery3D,
  141.                         'user' => $user,
  142.                         'userDirs' => $userDirs,    
  143.                         'logger' => $logger,
  144.                         'galleryItemCollection' => $galleryItemCollection
  145.                         'textureItemCollection' => $textureItemCollection,
  146.                         'isFooter' => $isFooter,     
  147.                         'isHeader' => $isHeader,
  148.                         'isFullscreen' => $isFullscreen,
  149.                         'freeWorld' => $freeWorld
  150.                 )
  151.             );           
  152.         //$response->headers->set('Content-Type', 'model/vrml');
  153.         return $response;      
  154.          
  155.     }   
  156.     /**
  157.      * @Route("/gallery3DAdmin", name="gallery3DAdmin")
  158.      */
  159.     public function gallery3DAdminAction(Request $request)
  160.     {
  161.         /* we load session data */
  162.         parent::init($request);
  163.         $session $request->getSession();
  164.         
  165.         /* we check if an user is logged in */
  166.         if(empty($session->get('user'))) {
  167.             return $this->redirectToRoute('login');
  168.         }   
  169.         
  170.         /* we load entity managers */
  171.         $em $this->doctrine->getManager();
  172.         $dem $this->doctrine->getManager('dynamic_em');
  173.     
  174.         $currentUserId $session->get('user')->getUserId();
  175.         
  176.         $galleryList $dem->getRepository(Gallery3D::class)->getGallery3DListByUser($currentUserId);
  177.         
  178.         $galleryCounts = array();
  179.         foreach($galleryList as $gallery) {    
  180.         
  181.             $gal3DId $gallery->getGallery3DId();
  182.         
  183.             if(!empty($gallery->getGallery())) {
  184.                 $galId $gallery->getGallery()->getGalleryId();
  185.                 $galCount $dem->getRepository(GalleryItem::class)->countGalleryItems($galId);
  186.                 $galleryCounts[$gal3DId] = $galCount;
  187.             } else {
  188.                 $galleryCounts[$gal3DId] = 0;
  189.             }
  190.         
  191.         }
  192.         
  193.         //print('<br>QQW galleryCounts: ');
  194.         //\Doctrine\Common\Util\Debug::dump($galleryCounts);
  195.         
  196.         $user $em->getRepository(User::class)->getUser($currentUserId);
  197.     
  198.         /* we render data */
  199.         return $this->render('gallery3D.html.twig',
  200.                 array('headerData' => $this -> getPageHeader($request),
  201.                 'menu' => $this -> adminMenu($request),
  202.                         'mainMenu' => $this -> adminMainMenu($request),
  203.                         'mainMenu' => $this -> adminMainMenu($request),
  204.                 'galleryList' => $galleryList,
  205.                     'user' => $user,
  206.                 'galleryCounts' => $galleryCounts,                    
  207.                 )
  208.                 );
  209.     
  210.     } 
  211.     
  212.     /**
  213.      * @Route("/gallery3DNew", name="gallery3DNew")
  214.      */
  215.     public function gallery3DNewAction(Request $request)
  216.     {
  217.     
  218.         /* we load session data */
  219.         parent::init($request);
  220.         $session $request->getSession();
  221.     
  222.         /* we load entity managers */
  223.         $em $this->doctrine->getManager();
  224.         $dem $this->doctrine->getManager('dynamic_em');
  225.          
  226.         $currentUserId $session->get('user')->getUserId();
  227.         $user $em->getRepository(User::class)->getUser($currentUserId);
  228.         
  229.         /* we build form */
  230.         $gallery = new Gallery3D;
  231.         $formBuilder $this->createFormBuilder($gallery);
  232.          
  233.         $formBuilder->add('gallery3DName'TextType::class, array(
  234.                 'required' => true,
  235.                 'label' => $this->translator->trans('module.gallery_name'),
  236.                 'attr' => array('class' => 'text_form''size' => 22),
  237.                 'label_attr' => array('class' => 'form_field_label'),
  238.         ));
  239.          
  240.         $formBuilder->add('save'SubmitType::class, array('label' => $this->translator->trans('form.button.save'),
  241.                 'attr' => array('class' => 'butt_big')));
  242.          
  243.         $form $formBuilder->getForm();
  244.         $form->handleRequest($request);
  245.          
  246.         if ($request->getMethod() == 'POST') {
  247.     
  248.             if ($form->isValid()) {
  249.                 $formData $form->getData();
  250.                 /* we load users entity manager */
  251.                 $dem $this->doctrine->getManager('dynamic_em');
  252.                  
  253.                 //$userName = $request->request->get('form')['username'];
  254.                 //$userExist = $em->getRepository(User::class)->getUserFromLogin($userName, $request->request->get('form')['password']);
  255.                 $gallery->setGallery3DName($formData->getGallery3DName());
  256.                 $gallery->setUserId($currentUserId);
  257.                 /* we persist and save */
  258.                 $dem->persist($gallery);
  259.                 $dem->flush();
  260.                  
  261.                 $this->addFlash('notice''New 3D Gallery was created.');
  262.                  
  263.                 return $this->redirectToRoute('gallery3DAdmin');
  264.                  
  265.             }
  266.              
  267.         }
  268.     
  269.         /* we render data */
  270.         return $this->render('gallery3DNew.html.twig',
  271.                 array(  'form' => $formBuilder->getForm()->createView(),
  272.                         'headerData' => $this -> getPageHeader($request),
  273.                         'menu' => $this -> adminMenu($request),
  274.                         'mainMenu' => $this -> adminMainMenu($request),
  275.                         'user' => $user,
  276.                 )
  277.                 );
  278.     
  279.     }    
  280.     
  281.     /**
  282.      * @Route("/gallery3DEdit/{gallery3DId}", name="gallery3DEdit")
  283.      */
  284.     public function gallery3DEditAction(Request $request$gallery3DId)
  285.     {
  286.     
  287.         /* we load session data */
  288.         parent::init($request);
  289.         $session $request->getSession();
  290.         
  291.         /* we check if an user is logged in */
  292.         if(empty($session->get('user'))) {
  293.             return $this->redirectToRoute('login');
  294.         }   
  295.     
  296.         /* we load entity managers */
  297.         $em $this->doctrine->getManager();
  298.         $dem $this->doctrine->getManager('dynamic_em');
  299.          
  300.         $userId $session->get('user')->getUserId();      
  301.         
  302.         /* we get current user */
  303.         $user $em->getRepository(User::class)->getUser($userId);
  304.         /* we get current 3D gallery */
  305.         $gallery $dem->getRepository(Gallery3D::class)->getGallery3D($gallery3DId);
  306.         /* we get galleries ang gallery items */
  307.         $galleryCollection $dem->getRepository(Gallery::class)->getGalleryListByUser($userId);
  308.         /* we get free worlds */
  309.         $freeWorldCollection $dem->getRepository(FreeWorld3D::class)->getFreeWorld3DList();
  310.         $userDirs $this->getUserFolderPaths($request);
  311.         $galleryItemCollection null;
  312.         if(!empty($gallery->getGallery())) {
  313.             $galId $gallery->getGallery()->getGalleryId();
  314.             $galleryItemCollection $dem->getRepository(GalleryItem::class)->getGalleryItemList($galId);
  315.         }
  316.         $galleryItemWebPathCollection = [];
  317.         if(!empty($galleryItemCollection)) {
  318.             foreach ($galleryItemCollection as $galleryItem) {
  319.                 $galleryItemId $galleryItem->getGalleryItemId();
  320.                 //$new_width = $gallery->getImageThumbWidth();
  321.                 $new_width 101;
  322.                 $new_height 101;
  323.                 //$imagePath = 'users/'.$user->getUserName().'/images/'.$product->getImage1();
  324.                 $imagePath str_replace("../web/"""$userDirs['images'] . '/' $galleryItem->getGalleryItemFile());
  325.                 //$imageThumbPath = 'users/'.$user->getUserName().'/images/thumb_'.$product->getImage1();
  326.                 $imageThumbPath str_replace("../web/"""$userDirs['images'] . '/thumb_' $galleryItem->getGalleryItemFile());
  327.                 //print('qqw imagePath: '.$imagePath);
  328.                 if (!is_file($imageThumbPath)) {
  329.                     $imageData getimagesize($imagePath);
  330.                     $thumbWidth $defaultThumbWidth 500;
  331.                     $defaultThumbHeight 150;
  332.                     $thumbHeight = ($imageData[1] / $imageData[0]) * $defaultThumbWidth;
  333.                     /* if the thumb height is bigger than allowed thumb height we generate thumb according to height*/
  334.                     if ($thumbHeight $defaultThumbHeight) {
  335.                         $thumbHeight $defaultThumbHeight;
  336.                         $thumbWidth = ($imageData[0] / $imageData[1]) * $thumbHeight;
  337.                     }
  338.                     /*
  339.                     print('<br>qqw thumbWidth: '.$thumbWidth);
  340.                     print('<br>qqw thumbHeight: '.$thumbHeight);
  341.                     */
  342.                     if (exif_imagetype($imagePath) == IMAGETYPE_JPEG) {
  343.                         $srcimg ImageCreateFromJPEG($imagePath);
  344.                         $destimg imagecreatetruecolor($thumbWidth$thumbHeight);
  345.                         if (is_file($imagePath)) {
  346.                             ImageCopyResized($destimg$srcimg0000$thumbWidth$thumbHeightImageSX($srcimg), ImageSY($srcimg));
  347.                             ImageJPEG($destimg$imageThumbPath100);
  348.                         }
  349.                     }
  350.                 }
  351.                 $webPath $userDirs['web'] . "/images/" $galleryItem->getGalleryItemFile();
  352.                 $galleryItemWebPathCollection[$galleryItemId]['webPath'] = $webPath;
  353.                 $galleryItemWebPathCollection[$galleryItemId]['imageThumbPath'] = $imageThumbPath;
  354.             }
  355.         }
  356.             /* we find 3D templates */
  357.         $views $this->appKernel->getProjectDir() . '/templates/gallery3D/';
  358.         //print('<br>qqw views: '.$views);
  359.         //$views = $this->appKernel->getRootDir().'/../app/Resources/views/gallery3D/';
  360.         //$views = $this->get('kernel')->getRootDir().'/../app/Resources/views/gallery3D/';
  361.         $finder = new Finder();
  362.         $finder->in($views);       
  363.    
  364.         /* we build edit form */
  365.         $formBuilder $this->createFormBuilder($gallery); //$gallery
  366.         
  367.         $formBuilder->add('gallery3DName'TextType::class, array(
  368.                 'required' => true,
  369.                 'label' => $this->translator->trans('module.gallery_name'),
  370.                 'attr' => array('class' => 'text_form''size' => 50'value' => $gallery->getGallery3DName()),
  371.                 'label_attr' => array('class' => 'form_field_label')
  372.         ));
  373.         $formBuilder->add('galleryLogoUrl'TextType::class, array(
  374.                 'required' => false,
  375.                 'label' => $this->translator->trans('system.logo_url'),
  376.                 'attr' => array('class' => 'text_form''size' => 50'value' => $gallery->getGalleryLogoUrl()),
  377.                 'label_attr' => array('class' => 'form_field_label')
  378.         ));   
  379.         /*
  380.         $formBuilder->add('template3DPath', TextType::class, array(
  381.                 'required' => false,
  382.                 'label' => $this->translator->trans('module.gallery3D_template'),
  383.                 'attr' => array('class' => 'text_form', 'size' => 50, 'value' => $gallery->getTemplate3DPath()),
  384.                 'label_attr' => array('class' => 'form_field_label')
  385.         ));
  386.         */           
  387.         $formBuilder->add('gallery3DDescription'TextareaType::class, array(
  388.                 'required' => false,
  389.                 'label' => $this->translator->trans('module.gallery_description'),
  390.                 'attr' => array('class' => 'textarea_form''cols' => 77'rows' => 5'value' => $gallery->getGallery3DDescription()),
  391.                 'label_attr' => array('class' => 'form_textarea_label2'),
  392.                 'data' => $gallery->getGallery3DDescription(),
  393.         ));            
  394.         /* we add gallery list */
  395.         $galleries = array();
  396.         $galleries['-- select --'] = 0;
  397.         foreach($galleryCollection as $gal)
  398.         {
  399.             $galId $gal->getGalleryId();
  400.             //print('<br>qqw dep: '.$depId);
  401.             $galKey $gal->getGalleryName().' (id:'.$gal->getGalleryId().')';
  402.             $galleries[$galKey] = $galId;
  403.              
  404.         }
  405.          
  406.         $selectedGallery 0;
  407.         if(!empty($gallery->getGallery())) {
  408.             $selectedGallery $gallery->getGallery()->getGalleryId();
  409.         }      
  410.          
  411.         $formBuilder->add('xmlSourcePath'TextType::class, array(
  412.                 'required' => false,
  413.                 'label' => $this->translator->trans('system.xml_source'),
  414.                 'attr' => array('class' => 'text_form''size' => 50'value' => $gallery->getXmlSourcePath()),
  415.                 'label_attr' => array('class' => 'form_field_label')
  416.         )); 
  417.         $formBuilder->add('galleryId'ChoiceType::class, array(
  418.                 'choices' => $galleries,
  419.                 'mapped' => false,
  420.                 'label' => $this->translator->trans('module.gallery_parent'),
  421.                 'attr' => array('class' => 'selector'),
  422.                 'label_attr' => array('class' => 'form_field_label'),
  423.                 'data' => $selectedGallery
  424.         ));   
  425.           
  426.         /* we add texture gallery list */
  427.         /*
  428.         $galleries = array();
  429.         $galleries['-- select --'] = 0;
  430.         foreach($galleryCollection as $gal)
  431.         {
  432.             $galId = $gal->getGalleryId();
  433.             //print('<br>qqw dep: '.$depId);
  434.             $galKey = $gal->getGalleryName().' (id:'.$gal->getGalleryId().')';
  435.             $galleries[$galKey] = $galId;
  436.              
  437.         }
  438.         */
  439.          
  440.         $selectedGallery 0;
  441.         if(!empty($gallery->getTextureGallery())) {
  442.             $selectedGallery $gallery->getTextureGallery()->getGalleryId();
  443.         }      
  444.         $formBuilder->add('textureGalleryId'ChoiceType::class, array(
  445.                 'choices' => $galleries,
  446.                 'mapped' => false,
  447.                 'label' => $this->translator->trans('module.gallery_texture'),
  448.                 'attr' => array('class' => 'selector'),
  449.                 'label_attr' => array('class' => 'form_field_label'),
  450.                 'data' => $selectedGallery
  451.         )); 
  452.         /* we add 3D template list */
  453.         $templates3D = array();
  454.         foreach ($finder as $file) {
  455.             $templates3D[$file->getRelativePathname()] = $file->getRelativePathname();
  456.         }
  457.          
  458.         $selectedTemplate3D 0;
  459.         if(!empty($gallery->getTemplate3DPath())) {
  460.             $selectedTemplate3D $gallery->getTemplate3DPath();
  461.         }      
  462.         $formBuilder->add('template3DPath'ChoiceType::class, array(
  463.                 'choices' => $templates3D,
  464.                 'label' => $this->translator->trans('module.gallery3D_template'),
  465.                 'attr' => array('class' => 'selector'),
  466.                 'label_attr' => array('class' => 'form_field_label'),
  467.                 'data' => $selectedTemplate3D
  468.         )); 
  469.         
  470.         $formBuilder->add('preferredViewpointPosition'TextType::class, array(
  471.                 'required' => false,
  472.                 'label' => $this->translator->trans('freeworld.viewpoint_position'),
  473.                 'attr' => array('class' => 'text_form''size' => 30'value' => $gallery->getPreferredViewpointPosition()),
  474.                 'label_attr' => array('class' => 'form_field_label')
  475.         ));      
  476.         
  477.         $formBuilder->add('preferredViewpointRotation'TextType::class, array(
  478.                 'required' => false,
  479.                 'label' => $this->translator->trans('freeworld.viewpoint_rotation'),
  480.                 'attr' => array('class' => 'text_form''size' => 30'value' => $gallery->getPreferredViewpointRotation()),
  481.                 'label_attr' => array('class' => 'form_field_label')
  482.         ));         
  483.         
  484.         $formBuilder->add('preferredBackgroundSkyColor'TextType::class, array(
  485.                 'required' => false,
  486.                 'label' => $this->translator->trans('freeworld.background_skycolor'),
  487.                 'attr' => array('class' => 'text_form''size' => 30'value' => $gallery->getPreferredBackgroundSkyColor()),
  488.                 'label_attr' => array('class' => 'form_field_label')
  489.         ));     
  490.         
  491.         $formBuilder->add('preferredBackgroundGroundColor'TextType::class, array(
  492.                 'required' => false,
  493.                 'label' => $this->translator->trans('freeworld.background_groundcolor'),
  494.                 'attr' => array('class' => 'text_form''size' => 30'value' => $gallery->getPreferredBackgroundGroundColor()),
  495.                 'label_attr' => array('class' => 'form_field_label')
  496.         ));                   
  497.         
  498.         $formBuilder->add('isStartGuide'ChoiceType::class, array(
  499.                 'choices' => array('Yes' => true'No' => false),
  500.                 'required' => false,
  501.                 'mapped' => false,
  502.                 'multiple' => false,
  503.                 'expanded' => true,
  504.                 'placeholder' => false,
  505.                 'label' => $this->translator->trans('module.is_start_guide'),
  506.                 'label_attr' => array('class' => 'form_field_label'),
  507.                 'attr' => array('class' => 'form_field_text'),              
  508.                 'data' => $gallery->isIsStartGuide(),
  509.         ));       
  510.         
  511.         $formBuilder->add('guideCycle'TextType::class, array(
  512.                 'required' => true,
  513.                 'label' => $this->translator->trans('module.guide_cycle'),
  514.                 'attr' => array('class' => 'text_form''size' => 5'value' => $gallery->getGuideCycle()),
  515.                 'label_attr' => array('class' => 'form_field_label')
  516.         ));                    
  517.         $formBuilder->add('isMediumResize'ChoiceType::class, array(
  518.                 'choices' => array('Yes' => true'No' => false),
  519.                 'required' => false,
  520.                 'mapped' => false,
  521.                 'multiple' => false,
  522.                 'expanded' => true,
  523.                 'placeholder' => false,
  524.                 'label' => $this->translator->trans('system.is_medium_resize'),
  525.                 'label_attr' => array('class' => 'form_field_label'),
  526.                 'attr' => array('class' => 'form_field_text'),              
  527.                 'data' => $gallery->isIsMediumResize(),
  528.         ));   
  529.          /* we add 3D freeworld */
  530.         $selectedFreeworld 0;
  531.         if(!empty($gallery->getFreeWorld())) {
  532.             $selectedFreeworld $gallery->getFreeWorld()->getFreeWorld3DId();
  533.         }      
  534.         /* we add freeworld list */
  535.         $freeworlds = array();
  536.         $freeworlds['-- select --'] = 0;
  537.         foreach($freeWorldCollection as $freeworld)
  538.         {
  539.             $freeworldId $freeworld->getFreeWorld3DId();
  540.             //print('<br>qqw dep: '.$depId);
  541.             $freeworldKey $freeworld->getFreeWorld3DName().' (id:'.$freeworld->getFreeWorld3DId().')';
  542.             $freeworlds[$freeworldKey] = $freeworldId;
  543.              
  544.         }
  545.         
  546.         $formBuilder->add('freeWorldId'ChoiceType::class, array(
  547.         'choices' => $freeworlds,
  548.         'mapped' => false,
  549.         'label' => $this->translator->trans('module.FreeWorld3D'),
  550.         'attr' => array('class' => 'selector'),
  551.         'label_attr' => array('class' => 'form_field_label'),
  552.         'data' => $selectedFreeworld
  553.         )); 
  554.         $formBuilder->add('save'SubmitType::class, array('label' => $this->translator->trans('form.button.save'),
  555.                 'attr' => array('class' => 'butt_big')));       
  556.         
  557.         $form $formBuilder->getForm();
  558.         $form->handleRequest($request);
  559.          
  560.         if ($request->getMethod() == 'POST') {
  561.     
  562.             //$form->bindRequest($request);
  563.     
  564.             if ($form->isValid()) {
  565.                 // save the object to the database
  566.                 $formData $form->getData();
  567.                 $gallery->setGallery3DName($formData->getGallery3DName());
  568.                 $gallery->setGallery3DDescription($formData->getGallery3DDescription());
  569. //                if(!empty($request->request->get('form')['galleryDescription'])) {
  570. //                    $gallery->setGallery3DDescription($request->request->get('form')['galleryDescription']);
  571. //                }
  572.                 $gallery->setGalleryLogoUrl($formData->getGalleryLogoUrl());
  573.                 $gallery->setXmlSourcePath($formData->getXmlSourcePath());
  574.                 $gallery->setTemplate3DPath($formData->getTemplate3DPath());
  575.                 
  576.                 $gallery->setPreferredViewpointPosition($formData->getPreferredViewpointPosition());
  577.                 $gallery->setPreferredViewpointRotation($formData->getPreferredViewpointRotation());
  578.                 $gallery->setPreferredBackgroundSkyColor($formData->getPreferredBackgroundSkyColor());
  579.                 $gallery->setPreferredBackgroundGroundColor($formData->getPreferredBackgroundGroundColor());
  580.                 
  581.                 $gallery->setUserId($userId);
  582.                 
  583.                 if(!empty($formData->getGuideCycle())) {
  584.                     $gallery->setGuideCycle($formData->getGuideCycle());
  585.                 }                
  586.                 if(!empty($form['galleryId']->getData()) && $form['galleryId']->getData() > 0) {
  587.                     $newGallery $dem->getRepository(Gallery::class)->getGallery($form['galleryId']->getData());
  588.                     $gallery->setGallery($newGallery);
  589.                 } else {
  590.                     $gallery->setGallery(null);
  591.                 }
  592.                 if(!empty($form['textureGalleryId']->getData()) && $form['textureGalleryId']->getData() > 0) {
  593.                     $textureGallery $dem->getRepository(Gallery::class)->getGallery($form['textureGalleryId']->getData());
  594.                     $gallery->setTextureGallery($textureGallery);
  595.                 } else {
  596.                     $gallery->setTextureGallery(null);
  597.                 }    
  598.                 
  599.                 if(!empty($form['freeWorldId']->getData()) && $form['freeWorldId']->getData() > 0) {
  600.                     $freeWorld $dem->getRepository(FreeWorld3D::class)->getFreeWorld3D($form['freeWorldId']->getData());
  601.                     $gallery->setFreeWorld($freeWorld);
  602.                 } else {
  603.                     $gallery->setFreeWorld(null);
  604.                 }   
  605.                 //if(!empty($form['isStartGuide']->getData())) {
  606.                     $gallery->setIsStartGuide($form['isStartGuide']->getData());
  607.                 //}    
  608.                 //if(!empty($formData->isIsMediumResize())) {
  609.                     $gallery->setIsMediumResize($form['isMediumResize']->getData());
  610.                 //}                           
  611.                 /* we persist and save */
  612.                 $dem->persist($gallery);
  613.                 $dem->flush();
  614.     
  615.                 $this->addFlash('notice''3D Gallery was updated.');
  616.     
  617.                 return $this->redirectToRoute('gallery3DEdit', array('gallery3DId' => $gallery->getGallery3DId()));
  618.                  
  619.             }
  620.     
  621.         }
  622.         /* we render data */
  623.         return $this->render('gallery3DEdit.html.twig',
  624.                 array('headerData' => $this -> getPageHeader($request),
  625.                         'gallery' => $gallery,
  626.                         'form' => $formBuilder->getForm()->createView(),
  627.                         'user' => $user,
  628.                         'userDirs' => $userDirs,
  629.                         'galleryItemCollection' => $galleryItemCollection,
  630.                         'menu' => $this -> adminMenu($request),
  631.                         'mainMenu' => $this -> adminMainMenu($request),
  632.                         'galleryItemWebPathCollection' => $galleryItemWebPathCollection
  633.                 )
  634.                 );
  635.     
  636.     }    
  637.     
  638.     public function adminMenu(Request $request)
  639.     {
  640.         $menuItems = array(=> array('link' => 'services3dAdmin''langKey' => 'service.services3d''routeName' => 'services3dAdmin'),
  641.                 => array('link' => 'gallery3DAdmin''langKey' => 'module.gallery3DAdmin''routeName' => 'gallery3DAdmin'),
  642.                 => array('link' => 'gallery3DNew''langKey' => 'module.gallery3D_new''routeName' => 'gallery3DNew'),
  643.         );
  644.     
  645.         return $menuItems;
  646.     
  647.     }    
  648.     
  649. }