コード例 #1
0
ファイル: Level.php プロジェクト: olegfox/landing
 /**
  * Set moduleSquare
  *
  * @param \Site\MainBundle\Entity\ModuleSquare $moduleSquare
  * @return Level
  */
 public function setModuleSquare(\Site\MainBundle\Entity\ModuleSquare $moduleSquare = null)
 {
     $this->moduleSquare = $moduleSquare;
     $moduleSquare->setLevel($this);
     return $this;
 }
コード例 #2
0
ファイル: LevelController.php プロジェクト: olegfox/landing
 /**
  * Creates a new Level entity.
  *
  */
 public function createAction(Request $request, $project_id, $page_id, $type)
 {
     $entity = new Level();
     $form = $this->createCreateForm($entity, $project_id, $page_id, $type);
     $form->handleRequest($request);
     if ($form->isValid()) {
         //          Квадраты
         if (is_object($entity->getModuleSquare())) {
             foreach ($entity->getModuleSquare()->getSquares() as $square) {
                 $square->setModuleSquare($entity->getModuleSquare());
             }
         }
         //          Отзывы
         if (is_object($entity->getModuleComment())) {
             foreach ($entity->getModuleComment()->getComment() as $comment) {
                 $comment->setModuleComment($entity->getModuleComment());
             }
         }
         $em = $this->getDoctrine()->getManager();
         $page = $this->getDoctrine()->getRepository('SiteMainBundle:Page')->find($page_id);
         if (!$page) {
             throw $this->createNotFoundException($this->get('translator')->trans('backend.page.not_found'));
         }
         $entity->setPage($page);
         $em->persist($entity);
         $em->flush();
         switch ($type) {
             case 'header':
                 // Модуль шапка
                 $moduleHeader = new ModuleHeader();
                 $moduleHeader->setLevel($entity);
                 $em->persist($moduleHeader);
                 $em->flush();
                 $entity->setModuleHeader($moduleHeader);
                 $em->flush();
                 break;
             case 'line':
                 // Модуль линия
                 $moduleLine = new ModuleLine();
                 $moduleLine->setLevel($entity);
                 $em->persist($moduleLine);
                 $em->flush();
                 $entity->setModuleLine($moduleLine);
                 $em->flush();
                 break;
             case 'square':
                 // Модуль квадрат
                 $moduleSquare = new ModuleSquare();
                 $moduleSquare->setLevel($entity);
                 $em->persist($moduleSquare);
                 $em->flush();
                 $entity->setModuleSquare($moduleSquare);
                 $em->flush();
                 break;
             case 'map':
                 // Модуль карта
                 $moduleMap = new ModuleMap();
                 $moduleMap->setLevel($entity);
                 $em->persist($moduleMap);
                 $em->flush();
                 $entity->setModuleMap($moduleMap);
                 $em->flush();
                 break;
             case 'comment':
                 // Модуль отзывов
                 $moduleComment = new ModuleComment();
                 $moduleComment->setLevel($entity);
                 $em->persist($moduleComment);
                 $em->flush();
                 $entity->setModuleComment($moduleComment);
                 $em->flush();
                 break;
             default:
                 // Модуль шапка
                 $moduleHeader = new ModuleHeader();
                 $moduleHeader->setLevel($entity);
                 $em->persist($moduleHeader);
                 $em->flush();
                 $entity->setModuleHeader($moduleHeader);
                 $em->flush();
                 break;
         }
         $entity->setType($type);
         $em->flush();
         return $this->redirect($this->generateUrl('backend_level_edit', array('id' => $entity->getId(), 'page_id' => $page_id, 'project_id' => $project_id, 'type' => $type)));
     }
     return $this->render('SiteMainBundle:Backend/Level:new.html.twig', array('entity' => $entity, 'form' => $form->createView()));
 }