diff --git a/Controller/BlockController.php b/Controller/BlockController.php index e71d9e3..c09bacc 100644 --- a/Controller/BlockController.php +++ b/Controller/BlockController.php @@ -133,10 +133,10 @@ public function newAction(Request $request, $template) ) ); - $blocksForm = $this->renderView('BigfootContentBundle:'.ucfirst($contentType).':Block/list.html.twig', array('form' => $contentForm->createView())); + $prototype = $this->renderView('BigfootContentBundle:'.ucfirst($contentType).':Block/prototype.html.twig', array('form' => $contentForm->createView())); $content = array( - 'prototype' => $blocksForm, + 'prototype' => $prototype, 'option' => array( 'label' => $block->getName().' - '.$block->getParentTemplate(), 'value' => $block->getId() @@ -213,10 +213,10 @@ public function editAction(Request $request, $id) ) ); - $blocksForm = $this->renderView('BigfootContentBundle:'.ucfirst($contentType).':Block/list.html.twig', array('form' => $contentForm->createView())); + $prototype = $this->renderView('BigfootContentBundle:'.ucfirst($contentType).':Block/prototype.html.twig', array('form' => $contentForm->createView())); $content = array( - 'prototype' => $blocksForm, + 'prototype' => $prototype, 'option' => array( 'id' => $block->getId(), 'label' => $block->getName().' - '.$block->getParentTemplate(), diff --git a/Controller/PageController.php b/Controller/PageController.php index f53c351..bac84ae 100644 --- a/Controller/PageController.php +++ b/Controller/PageController.php @@ -157,117 +157,45 @@ public function editAction(Request $request, $id) $dbSidebars4 = new ArrayCollection(); $dbSidebars5 = new ArrayCollection(); - foreach ($page->getBlocks() as $block) { - $dbBlocks->add($block); - } - - foreach ($page->getBlocks2() as $block2) { - $dbBlocks2->add($block2); - } - - foreach ($page->getBlocks3() as $block3) { - $dbBlocks3->add($block3); - } - - foreach ($page->getBlocks4() as $block4) { - $dbBlocks4->add($block4); - } - - foreach ($page->getBlocks5() as $block5) { - $dbBlocks5->add($block5); - } - - foreach ($page->getSidebars() as $sidebar) { - $dbSidebars->add($sidebar); - } - - foreach ($page->getSidebars2() as $sidebar2) { - $dbSidebars2->add($sidebar2); - } + for ($i = 1; $i <= 5; $i++) { + $j = ($i > 1) ? $i : ''; - foreach ($page->getSidebars3() as $sidebar3) { - $dbSidebars3->add($sidebar3); + foreach ($page->{'getBlocks'.$j}() as ${'block'.$j}) { + ${'dbBlocks'.$j}->add(${'block'.$j}); + } } - foreach ($page->getSidebars4() as $sidebar4) { - $dbSidebars4->add($sidebar4); - } + for ($i = 1; $i <= 5; $i++) { + $j = ($i > 1) ? $i : ''; - foreach ($page->getSidebars5() as $sidebar5) { - $dbSidebars5->add($sidebar5); + foreach ($page->{'getSidebars'.$j}() as ${'sidebar'.$j}) { + ${'dbSidebars'.$j}->add(${'sidebar'.$j}); + } } if ('POST' === $request->getMethod()) { $form->handleRequest($request); if ($form->isValid()) { - foreach ($dbBlocks as $block) { - if ($page->getBlocks()->contains($block) === false) { - $page->getBlocks()->removeElement($block); - $this->getEntityManager()->remove($block); + for ($i = 1; $i <= 5; $i++) { + $j = ($i > 1) ? $i : ''; + + foreach (${'dbBlocks'.$j} as ${'block'.$j}) { + if ($page->{'getBlocks'.$j}()->contains(${'block'.$j}) === false) { + $page->{'getBlocks'.$j}()->removeElement(${'block'.$j}); + $this->getEntityManager()->remove(${'block'.$j}); + } } } - foreach ($dbBlocks2 as $block2) { - if ($page->getBlocks2()->contains($block2) === false) { - $page->getBlocks2()->removeElement($block2); - $this->getEntityManager()->remove($block2); - } - } - - foreach ($dbBlocks3 as $block3) { - if ($page->getBlocks3()->contains($block3) === false) { - $page->getBlocks3()->removeElement($block3); - $this->getEntityManager()->remove($block3); - } - } - - foreach ($dbBlocks4 as $block4) { - if ($page->getBlocks4()->contains($block4) === false) { - $page->getBlocks4()->removeElement($block4); - $this->getEntityManager()->remove($block4); - } - } - - foreach ($dbBlocks5 as $block5) { - if ($page->getBlocks5()->contains($block5) === false) { - $page->getBlocks5()->removeElement($block5); - $this->getEntityManager()->remove($block5); - } - } - - foreach ($dbSidebars as $sidebar) { - if ($page->getSidebars()->contains($sidebar) === false) { - $page->getSidebars()->removeElement($sidebar); - $this->getEntityManager()->remove($sidebar); - } - } - - foreach ($dbSidebars2 as $sidebar2) { - if ($page->getSidebars2()->contains($sidebar2) === false) { - $page->getSidebars2()->removeElement($sidebar2); - $this->getEntityManager()->remove($sidebar2); - } - } - - foreach ($dbSidebars3 as $sidebar3) { - if ($page->getSidebars3()->contains($sidebar3) === false) { - $page->getSidebars3()->removeElement($sidebar3); - $this->getEntityManager()->remove($sidebar3); - } - } - - foreach ($dbSidebars4 as $sidebar4) { - if ($page->getSidebars4()->contains($sidebar4) === false) { - $page->getSidebars4()->removeElement($sidebar4); - $this->getEntityManager()->remove($sidebar4); - } - } + for ($i = 1; $i <= 5; $i++) { + $j = ($i > 1) ? $i : ''; - foreach ($dbSidebars5 as $sidebar5) { - if ($page->getSidebars5()->contains($sidebar5) === false) { - $page->getSidebars5()->removeElement($sidebar5); - $this->getEntityManager()->remove($sidebar5); + foreach (${'dbSidebars'.$j} as ${'sidebar'.$j}) { + if ($page->{'getSidebars'.$j}()->contains(${'sidebar'.$j}) === false) { + $page->{'getSidebars'.$j}()->removeElement(${'sidebar'.$j}); + $this->getEntityManager()->remove(${'sidebar'.$j}); + } } } diff --git a/Entity/Page.php b/Entity/Page.php index b7e095d..43a00f3 100644 --- a/Entity/Page.php +++ b/Entity/Page.php @@ -10,9 +10,13 @@ use Bigfoot\Bundle\ContentBundle\Entity\Page\Block as PageBlock; use Bigfoot\Bundle\ContentBundle\Entity\Page\Block2 as PageBlock2; use Bigfoot\Bundle\ContentBundle\Entity\Page\Block3 as PageBlock3; -use Bigfoot\Bundle\ContentBundle\Entity\Page\Block3 as PageBlock4; -use Bigfoot\Bundle\ContentBundle\Entity\Page\Block3 as PageBlock5; +use Bigfoot\Bundle\ContentBundle\Entity\Page\Block4 as PageBlock4; +use Bigfoot\Bundle\ContentBundle\Entity\Page\Block5 as PageBlock5; use Bigfoot\Bundle\ContentBundle\Entity\Page\Sidebar as PageSidebar; +use Bigfoot\Bundle\ContentBundle\Entity\Page\Sidebar2 as PageSidebar2; +use Bigfoot\Bundle\ContentBundle\Entity\Page\Sidebar3 as PageSidebar3; +use Bigfoot\Bundle\ContentBundle\Entity\Page\Sidebar4 as PageSidebar4; +use Bigfoot\Bundle\ContentBundle\Entity\Page\Sidebar5 as PageSidebar5; /** * Page @@ -138,41 +142,6 @@ public function getId() return $this->id; } - /** - * Add sidebar - * - * @param PageSidebar $sidebar - * @return Page - */ - public function addSidebar(PageSidebar $sidebar) - { - $this->sidebars[] = $sidebar; - - return $this; - } - - /** - * Remove sidebar - * - * @param PageSidebar $sidebar - */ - public function removeSidebar(PageSidebar $sidebar) - { - $this->sidebars->removeElement($sidebar); - - return $this; - } - - /** - * Get sidebars - * - * @return \Doctrine\Common\Collections\Collection - */ - public function getSidebars() - { - return $this->sidebars; - } - /** * Add block * @@ -198,6 +167,16 @@ public function removeBlock(PageBlock $block) return $this; } + /** + * @param \Doctrine\Common\Collections\ArrayCollection $blocks + */ + public function setBlocks($blocks) + { + $this->blocks = $blocks; + + return $this; + } + /** * Get blocks * @@ -233,6 +212,16 @@ public function removeBlock2(PageBlock2 $block2) return $this; } + /** + * @param \Doctrine\Common\Collections\ArrayCollection $blocks2 + */ + public function setBlocks2($blocks2) + { + $this->blocks2 = $blocks2; + + return $this; + } + /** * Get blocks2 * @@ -268,6 +257,16 @@ public function removeBlock3(PageBlock3 $block3) return $this; } + /** + * @param \Doctrine\Common\Collections\ArrayCollection $blocks3 + */ + public function setBlocks3($blocks3) + { + $this->blocks3 = $blocks3; + + return $this; + } + /** * Get blocks3 * @@ -303,6 +302,16 @@ public function removeBlock4(PageBlock4 $block4) return $this; } + /** + * @param \Doctrine\Common\Collections\ArrayCollection $blocks4 + */ + public function setBlocks4($blocks4) + { + $this->blocks4 = $blocks4; + + return $this; + } + /** * Get blocks4 * @@ -338,6 +347,16 @@ public function removeBlock5(PageBlock5 $block5) return $this; } + /** + * @param \Doctrine\Common\Collections\ArrayCollection $blocks5 + */ + public function setBlocks5($blocks5) + { + $this->blocks5 = $blocks5; + + return $this; + } + /** * Get blocks5 * @@ -349,22 +368,57 @@ public function getBlocks5() } /** - * @param \Doctrine\Common\Collections\ArrayCollection $attributes + * Add sidebar + * + * @param PageSidebar $sidebar + * @return Page */ - public function setAttributes($attributes) + public function addSidebar(PageSidebar $sidebar) { - $this->attributes = $attributes; + $this->sidebars[] = $sidebar; return $this; } + /** + * Remove sidebar + * + * @param PageSidebar $sidebar + */ + public function removeSidebar(PageSidebar $sidebar) + { + $this->sidebars->removeElement($sidebar); + + return $this; + } + + /** + * @param \Doctrine\Common\Collections\ArrayCollection $sidebars + */ + public function setSidebars($sidebars) + { + $this->sidebars = $sidebars; + + return $this; + } + + /** + * Get sidebars + * + * @return \Doctrine\Common\Collections\Collection + */ + public function getSidebars() + { + return $this->sidebars; + } + /** * Add sidebars2 * - * @param \Bigfoot\Bundle\ContentBundle\Entity\Page\Sidebar2 $sidebars2 + * @param PageSidebar2 $sidebars2 * @return Page */ - public function addSidebar2(\Bigfoot\Bundle\ContentBundle\Entity\Page\Sidebar2 $sidebars2) + public function addSidebar2(PageSidebar2 $sidebars2) { $this->sidebars2[] = $sidebars2; @@ -374,13 +428,23 @@ public function addSidebar2(\Bigfoot\Bundle\ContentBundle\Entity\Page\Sidebar2 $ /** * Remove sidebars2 * - * @param \Bigfoot\Bundle\ContentBundle\Entity\Page\Sidebar2 $sidebars2 + * @param PageSidebar2 $sidebars2 */ - public function removeSidebar2(\Bigfoot\Bundle\ContentBundle\Entity\Page\Sidebar2 $sidebars2) + public function removeSidebar2(PageSidebar2 $sidebars2) { $this->sidebars2->removeElement($sidebars2); } + /** + * @param \Doctrine\Common\Collections\ArrayCollection $sidebars2 + */ + public function setSidebars2($sidebars2) + { + $this->sidebars2 = $sidebars2; + + return $this; + } + /** * Get sidebars2 * @@ -394,10 +458,10 @@ public function getSidebars2() /** * Add sidebars3 * - * @param \Bigfoot\Bundle\ContentBundle\Entity\Page\Sidebar3 $sidebars3 + * @param PageSidebar3 $sidebars3 * @return Page */ - public function addSidebar3(\Bigfoot\Bundle\ContentBundle\Entity\Page\Sidebar3 $sidebars3) + public function addSidebar3(PageSidebar3 $sidebars3) { $this->sidebars3[] = $sidebars3; @@ -407,13 +471,23 @@ public function addSidebar3(\Bigfoot\Bundle\ContentBundle\Entity\Page\Sidebar3 $ /** * Remove sidebars3 * - * @param \Bigfoot\Bundle\ContentBundle\Entity\Page\Sidebar3 $sidebars3 + * @param PageSidebar3 $sidebars3 */ - public function removeSidebar3(\Bigfoot\Bundle\ContentBundle\Entity\Page\Sidebar3 $sidebars3) + public function removeSidebar3(PageSidebar3 $sidebars3) { $this->sidebars3->removeElement($sidebars3); } + /** + * @param \Doctrine\Common\Collections\ArrayCollection $sidebars3 + */ + public function setSidebars3($sidebars3) + { + $this->sidebars3 = $sidebars3; + + return $this; + } + /** * Get sidebars3 * @@ -427,10 +501,10 @@ public function getSidebars3() /** * Add sidebars4 * - * @param \Bigfoot\Bundle\ContentBundle\Entity\Page\Sidebar4 $sidebars4 + * @param PageSidebar4 $sidebars4 * @return Page */ - public function addSidebar4(\Bigfoot\Bundle\ContentBundle\Entity\Page\Sidebar4 $sidebars4) + public function addSidebar4(PageSidebar4 $sidebars4) { $this->sidebars4[] = $sidebars4; @@ -440,13 +514,23 @@ public function addSidebar4(\Bigfoot\Bundle\ContentBundle\Entity\Page\Sidebar4 $ /** * Remove sidebars4 * - * @param \Bigfoot\Bundle\ContentBundle\Entity\Page\Sidebar4 $sidebars4 + * @param PageSidebar4 $sidebars4 */ - public function removeSidebar4(\Bigfoot\Bundle\ContentBundle\Entity\Page\Sidebar4 $sidebars4) + public function removeSidebar4(PageSidebar4 $sidebars4) { $this->sidebars4->removeElement($sidebars4); } + /** + * @param \Doctrine\Common\Collections\ArrayCollection $sidebars4 + */ + public function setSidebars4($sidebars4) + { + $this->sidebars4 = $sidebars4; + + return $this; + } + /** * Get sidebars4 * @@ -460,10 +544,10 @@ public function getSidebars4() /** * Add sidebars5 * - * @param \Bigfoot\Bundle\ContentBundle\Entity\Page\Sidebar5 $sidebars5 + * @param PageSidebar5 $sidebars5 * @return Page */ - public function addSidebar5(\Bigfoot\Bundle\ContentBundle\Entity\Page\Sidebar5 $sidebars5) + public function addSidebar5(PageSidebar5 $sidebars5) { $this->sidebars5[] = $sidebars5; @@ -473,13 +557,23 @@ public function addSidebar5(\Bigfoot\Bundle\ContentBundle\Entity\Page\Sidebar5 $ /** * Remove sidebars5 * - * @param \Bigfoot\Bundle\ContentBundle\Entity\Page\Sidebar5 $sidebars5 + * @param PageSidebar5 $sidebars5 */ - public function removeSidebar5(\Bigfoot\Bundle\ContentBundle\Entity\Page\Sidebar5 $sidebars5) + public function removeSidebar5(PageSidebar5 $sidebars5) { $this->sidebars5->removeElement($sidebars5); } + /** + * @param \Doctrine\Common\Collections\ArrayCollection $sidebars5 + */ + public function setSidebars5($sidebars5) + { + $this->sidebars5 = $sidebars5; + + return $this; + } + /** * Get sidebars5 * @@ -490,7 +584,7 @@ public function getSidebars5() return $this->sidebars5; } - /** + /** * @param Attribute $attribute */ public function addAttribute($attribute) @@ -510,6 +604,16 @@ public function removeAttribute($attribute) return $this; } + /** + * @param \Doctrine\Common\Collections\ArrayCollection $attributes + */ + public function setAttributes($attributes) + { + $this->attributes = $attributes; + + return $this; + } + /** * @return \Doctrine\Common\Collections\ArrayCollection */ diff --git a/Resources/public/images/template/sidebar/img_block_1.svg b/Resources/public/images/template/sidebar/media_block_1.svg similarity index 100% rename from Resources/public/images/template/sidebar/img_block_1.svg rename to Resources/public/images/template/sidebar/media_block_1.svg diff --git a/Resources/public/images/template/sidebar/img_block_2.svg b/Resources/public/images/template/sidebar/media_block_2.svg similarity index 100% rename from Resources/public/images/template/sidebar/img_block_2.svg rename to Resources/public/images/template/sidebar/media_block_2.svg diff --git a/Resources/public/images/template/sidebar/title_desc_img_block_1.svg b/Resources/public/images/template/sidebar/title_desc_media_block_1.svg similarity index 100% rename from Resources/public/images/template/sidebar/title_desc_img_block_1.svg rename to Resources/public/images/template/sidebar/title_desc_media_block_1.svg diff --git a/Resources/public/images/template/sidebar/title_desc_img_block_2.svg b/Resources/public/images/template/sidebar/title_desc_media_block_2.svg similarity index 100% rename from Resources/public/images/template/sidebar/title_desc_img_block_2.svg rename to Resources/public/images/template/sidebar/title_desc_media_block_2.svg diff --git a/Resources/public/images/template/sidebar/title_desc_img_block_3.svg b/Resources/public/images/template/sidebar/title_desc_media_block_3.svg similarity index 100% rename from Resources/public/images/template/sidebar/title_desc_img_block_3.svg rename to Resources/public/images/template/sidebar/title_desc_media_block_3.svg diff --git a/Resources/public/images/template/sidebar/title_img_block_1.svg b/Resources/public/images/template/sidebar/title_media_block_1.svg similarity index 100% rename from Resources/public/images/template/sidebar/title_img_block_1.svg rename to Resources/public/images/template/sidebar/title_media_block_1.svg diff --git a/Resources/public/js/block.js b/Resources/public/js/block.js index e1c3bf9..8633c7e 100644 --- a/Resources/public/js/block.js +++ b/Resources/public/js/block.js @@ -32,11 +32,15 @@ $(function() { $(".chosen-select").chosen(); - // $('.templates-container').last().find('input:first').attr('checked', true); - var blocks = containerBlock.find('.admin_block_select'); handleTemplates(blocks); + + $(this) + .closest('.collection-container') + .find('.templates-container:last') + .find('label.is-shown:first > input') + .attr('checked', true); }); $('.admin-edit-block').unbind('click'); @@ -100,10 +104,12 @@ $(function() { if (values[0] !== template) { $(this) .parent() + .addClass('is-hidden') .hide(); } else { $(this) .parent() + .addClass('is-shown') .show(); } }); diff --git a/Resources/public/js/page.js b/Resources/public/js/page.js index 5b2b1fa..0503ef7 100644 --- a/Resources/public/js/page.js +++ b/Resources/public/js/page.js @@ -28,6 +28,12 @@ $(function() { sidebars = containerSidebar.find('.admin_sidebar_select'); handleSidebarTemplates(sidebars); + + $(this) + .closest('.collection-container') + .find('.templates-container:last') + .find('label.is-shown:first > input') + .attr('checked', true); }); $('body').on('click', '.admin-delete-sidebar', function (event) { @@ -70,10 +76,12 @@ $(function() { if (values[0] !== template) { $(this) .parent() + .addClass('is-hidden') .hide(); } else { $(this) .parent() + .addClass('is-shown') .show(); } }); diff --git a/Resources/views/Page/Block/list.html.twig b/Resources/views/Page/Block/prototype.html.twig similarity index 100% rename from Resources/views/Page/Block/list.html.twig rename to Resources/views/Page/Block/prototype.html.twig diff --git a/Resources/views/Sidebar/Block/list.html.twig b/Resources/views/Sidebar/Block/prototype.html.twig similarity index 100% rename from Resources/views/Sidebar/Block/list.html.twig rename to Resources/views/Sidebar/Block/prototype.html.twig diff --git a/Twig/Extension/ContentExtension.php b/Twig/Extension/ContentExtension.php index a250e6d..f7dd4aa 100644 --- a/Twig/Extension/ContentExtension.php +++ b/Twig/Extension/ContentExtension.php @@ -67,12 +67,12 @@ public function displaySidebar($sidebar, array $data = null) if (!$sidebar) { return ''; - throw new NotFoundHttpException('Unable to find sidebar.'); } $pageSidebar = (!$sidebar instanceof Sidebar) ? $sidebar : false; $template = ($pageSidebar) ? $pageSidebar->getTemplate() : $sidebar->getParentTemplate().'/'.$sidebar->getSlugTemplate(); $template = (isset($data['template'])) ? $data['template'] : $template; + $sidebar = ($sidebar instanceof PageSidebar) ? $sidebar->getSidebar() : $sidebar; return $this->twig->render( 'BigfootContentBundle:templates:sidebar/'.$template.'.html.twig',