ed209

Untitled

Nov 27th, 2011
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.15 KB | None | 0 0
  1.     public function saveAction()
  2.     {
  3.  
  4.  
  5.         $user = $this->get('security.context')->getToken()->getUser();
  6.         if (false === $this->get('security.context')->isGranted('ROLE_USER')) {
  7.             throw new AccessDeniedException('This user does not have access to this section.');
  8.         }
  9.        
  10.         $request = $this->getRequest();
  11.        
  12.         if (!$request->isXmlHttpRequest()) {
  13.             return $this->redirect('/');
  14.         }
  15.        
  16.         // load the serivce
  17.         $themeDesigner = $this->get('themedesigner');
  18.        
  19.         // get the current variant for that user \ or null if there is none
  20.         $variant = $themeDesigner->getVariantByUser($user);
  21.  
  22.         $form = $this->get('qiip_design.form.variant');
  23.         $form->bindRequest($request);
  24.        
  25.         if($form->isValid()){
  26.             $logger->info("Valid");
  27.         }else{
  28.             $logger->info("Not Valid");
  29.         }
  30.          $logger->info($form->getData()->getCssParams());
  31.  
  32.  
  33.  
  34.  
  35.        
  36. /*
  37.         // add some other data to the request
  38.        // $request->request->css_generated = $this->CssFormatter($request->request->get('cssParams'));
  39.  
  40.  
  41.         // load the serivce
  42.         $themeDesigner = $this->get('themedesigner');
  43.  
  44.         // get the current variant for that user \ or null if there is none
  45.         $variant = $themeDesigner->getVariantByUser($user);
  46.        
  47.         //$form = $this->get('qiip_design.form.variant');
  48.        
  49.         $form = $this->createForm(new VariantType(), $variant);
  50.         $form->bindRequest($request);
  51.        
  52.        
  53.  
  54.  
  55.         // $varDump = var_export($request->request->all(), true);
  56.         $varDump = var_export($variant, true);
  57.         $logger = $this->get('logger');
  58.         $logger->info($varDump);
  59.        
  60. */
  61. /*
  62.         // grab the data
  63.         $themeData   = $request->request->get('themeData');
  64.         $advancedCss = $request->request->get('advancedCss');
  65.         $generated   = $this->CssFormatter($themeData);
  66.         $styleId     = $request->request->get('styleId');
  67.        
  68.         // if no style Id has been passed we choose the default style
  69.         $styleId     = (!$styleId) ? $this->container->getParameter('style.default_layout') : $styleId;
  70.        
  71.         // get the relevant style
  72.         $style = $themeDesigner->getStyleById($styleId);
  73.        
  74.  
  75.  
  76.         // prepare the form
  77.         $form = $this->createForm(new VariantType(), $variant);
  78. */
  79.            
  80.            
  81. /*
  82.             $variant = new Variant();
  83.             $variant->setStyle($style);
  84.             $variant->setUser($user);
  85.             $variant->setCssParams($themeData);
  86.             $variant->setAdvancedCss($advancedCss);
  87.             $variant->setGeneratedCss($generated);
  88. */
  89.            
  90.             //$this->get('service_id')->persist($data, $variant);
  91.  
  92.        
  93.        
  94.        
  95.        
  96.        
  97.        
  98.        
  99.        
  100.        
  101.        
  102.        
  103.       //  $em = $this->getDoctrine()->getEntityManager();        
  104.        
  105.         // check it's an ajax request
  106.        // if ( $request->isXmlHttpRequest() ) {
  107.        
  108. /*
  109.             // grab the data
  110.             $themeData   = $request->request->get('themeData');
  111.             $advancedCss = $request->request->get('advancedCss');
  112.             $generated   = $this->CssFormatter($themeData);
  113.             $styleId     = $request->request->get('styleId');
  114.            
  115.             // if no style Id has been passed we choose the default style
  116.             $styleId     = (!$styleId) ? $this->container->getParameter('style.default_layout') : $styleId;
  117.            
  118.             // get the relevant style
  119.             $style = $themeDesigner->getStyleById($styleId);
  120.            
  121.             // load the service
  122.             $themeDesigner = $this->get('themedesigner');
  123. */
  124.            
  125.        
  126.  
  127.  
  128.            
  129.            
  130.            
  131.            
  132. /*
  133.             $variant = $themeDesigner->getVariantByUser($user);
  134.            
  135.             if (!$variant instanceof Entity\Variant) {
  136.                 // update
  137.                 $variant = $themeDesigner->getVariantByUser($user);
  138.                 $variant->setStyle($style);
  139.                 $variant->setUser($user);
  140.                 $variant->setCssParams($themeData);
  141.                 $variant->setAdvancedCss($advancedCss);
  142.                 $variant->setGeneratedCss($generated);
  143.                 $em->flush();
  144.             }else{
  145.                 // create new
  146.                 $variant = new Variant();
  147.                 $variant->setStyle($style);
  148.                 $variant->setUser($user);
  149.                 $variant->setCssParams($themeData);
  150.                 $variant->setAdvancedCss($advancedCss);
  151.                 $variant->setGeneratedCss($generated);
  152.                 $em->persist($variant);
  153.                 $em->flush();
  154.             }
  155. */
  156.            
  157. /*
  158.        // } else {
  159.             throw new AccessDeniedException('Request type not permitted');
  160.         }
  161. */
  162.        
  163.        
  164.         $response = new Response(json_encode(array( "message" => "Your changes have been saved")));
  165.         $response->headers->set('Content-Type', 'application/json');
  166.         return $response;
  167.     }
  168.    
  169.  
Advertisement
Add Comment
Please, Sign In to add comment