Skip to content

Commit

Permalink
Merge pull request #74 from patrick477/master
Browse files Browse the repository at this point in the history
[General] Add resources render by section code
  • Loading branch information
bitbager authored Nov 11, 2017
2 parents d2c8e78 + 364298c commit bba7da2
Show file tree
Hide file tree
Showing 22 changed files with 248 additions and 6 deletions.
45 changes: 45 additions & 0 deletions spec/Entity/SectionSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

/**
* This file was created by the developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.shop and write us
* an email on [email protected].
*/

declare(strict_types=1);

namespace spec\BitBag\CmsPlugin\Entity;

use BitBag\CmsPlugin\Entity\Section;
use BitBag\CmsPlugin\Entity\SectionInterface;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Resource\Model\ResourceInterface;

/**
* @author Patryk Drapik <[email protected]>
*/
final class SectionSpec extends ObjectBehavior
{
function it_is_initializable(): void
{
$this->shouldHaveType(Section::class);
}

function it_is_a_resource(): void
{
$this->shouldHaveType(ResourceInterface::class);
}

function it_implements_section_interface(): void
{
$this->shouldHaveType(SectionInterface::class);
}

function it_allows_access_via_properties(): void
{
$this->setCode('blog');
$this->getCode()->shouldReturn('blog');
}
}
47 changes: 47 additions & 0 deletions spec/Entity/SectionTranslationSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

/**
* This file was created by the developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.shop and write us
* an email on [email protected].
*/

declare(strict_types=1);

namespace spec\BitBag\CmsPlugin\Entity;

use BitBag\CmsPlugin\Entity\SectionTranslation;
use BitBag\CmsPlugin\Entity\SectionTranslationInterface;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Resource\Model\ResourceInterface;
use Sylius\Component\Resource\Model\TranslationInterface;

/**
* @author Patryk Drapik <[email protected]>
*/
final class SectionTranslationSpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType(SectionTranslation::class);
}

function it_is_a_resource()
{
$this->shouldHaveType(ResourceInterface::class);
}

function it_implements_frequently_asked_question_translation_interface()
{
$this->shouldHaveType(SectionTranslationInterface::class);
$this->shouldHaveType(TranslationInterface::class);
}

function it_allows_access_via_properties()
{
$this->setName('Blog');
$this->getName()->shouldReturn('Blog');
}
}
2 changes: 2 additions & 0 deletions src/Entity/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Block implements BlockInterface
{
use ToggleableTrait;
use SectionAssociationTrait;
use ProductAssociationTrait;
use TranslatableTrait {
__construct as protected initializeTranslationsCollection;
}
Expand All @@ -33,6 +34,7 @@ public function __construct()
{
$this->initializeTranslationsCollection();
$this->initializeSectionsCollection();
$this->initializeProductsCollection();
}

/**
Expand Down
5 changes: 5 additions & 0 deletions src/Form/Type/BlockType.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use BitBag\CmsPlugin\Form\Type\Translation\HtmlBlockTranslationType;
use BitBag\CmsPlugin\Form\Type\Translation\ImageBlockTranslationType;
use BitBag\CmsPlugin\Form\Type\Translation\TextBlockTranslationType;
use Sylius\Bundle\ProductBundle\Form\Type\ProductAutocompleteChoiceType;
use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType;
use Sylius\Bundle\ResourceBundle\Form\Type\ResourceTranslationsType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
Expand Down Expand Up @@ -48,6 +49,10 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
->add('enabled', CheckboxType::class, [
'label' => 'bitbag.ui.enabled',
])
->add('products', ProductAutocompleteChoiceType::class, [
'label' => 'bitbag.ui.products',
'multiple' => true,
])
;

$this->resolveBlockType($block, $builder);
Expand Down
15 changes: 15 additions & 0 deletions src/Repository/BlockRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,19 @@ public function findOneByTypeAndContent(string $type, string $content): ?BlockIn
->getOneOrNullResult()
;
}

/**
* {@inheritdoc}
*/
public function findEnabledBySectionCode(string $code): array
{
return $this->createQueryBuilder('o')
->innerJoin('o.sections', 'section')
->andWhere('section.code = :sectionCode')
->andWhere('o.enabled = true')
->setParameter('sectionCode', $code)
->getQuery()
->getResult()
;
}
}
7 changes: 7 additions & 0 deletions src/Repository/BlockRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,11 @@ public function findEnabledByCodeAndContent(string $code, string $content): ?Blo
* @return null|BlockInterface
*/
public function findOneByTypeAndContent(string $type, string $content): ?BlockInterface;

/**
* @param string $sectionCode
*
* @return BlockInterface[]
*/
public function findEnabledBySectionCode(string $sectionCode): array;
}
15 changes: 15 additions & 0 deletions src/Repository/FrequentlyAskedQuestionRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,19 @@ public function findEnabledByCode(string $code): ?FrequentlyAskedQuestionInterfa
->getOneOrNullResult()
;
}

/**
* {@inheritdoc}
*/
public function findEnabledBySectionCode(string $code): array
{
return $this->createQueryBuilder('o')
->innerJoin('o.sections', 'section')
->andWhere('section.code = :sectionCode')
->andWhere('o.enabled = true')
->setParameter('sectionCode', $code)
->getQuery()
->getResult()
;
}
}
10 changes: 9 additions & 1 deletion src/Repository/FrequentlyAskedQuestionRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

/**
* @author Mikołaj Król <[email protected]>
* @author Patryk Drapik <[email protected]>
*/
interface FrequentlyAskedQuestionRepositoryInterface extends RepositoryInterface
{
Expand All @@ -29,7 +30,7 @@ public function createListQueryBuilder(): QueryBuilder;
/**
* @param string $localeCode
*
* @return QueryBuilder
* @return array|FrequentlyAskedQuestionInterface[]
*/
public function findEnabledOrderedByPosition(string $localeCode): array;

Expand All @@ -39,4 +40,11 @@ public function findEnabledOrderedByPosition(string $localeCode): array;
* @return null|FrequentlyAskedQuestionInterface
*/
public function findEnabledByCode(string $code): ?FrequentlyAskedQuestionInterface;

/**
* @param string $sectionCode
*
* @return FrequentlyAskedQuestionInterface[]
*/
public function findEnabledBySectionCode(string $sectionCode): array;
}
16 changes: 15 additions & 1 deletion src/Repository/PageRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use BitBag\CmsPlugin\Entity\PageInterface;
use Doctrine\ORM\QueryBuilder;
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
use Sylius\Component\Core\Model\ChannelInterface;

/**
* @author Patryk Drapik <[email protected]>
Expand Down Expand Up @@ -64,4 +63,19 @@ public function findEnabledBySlug(string $slug, string $localeCode): ?PageInterf
->getOneOrNullResult()
;
}

/**
* {@inheritdoc}
*/
public function findEnabledBySectionCode(string $code): array
{
return $this->createQueryBuilder('o')
->innerJoin('o.sections', 'section')
->andWhere('section.code = :sectionCode')
->andWhere('o.enabled = true')
->setParameter('sectionCode', $code)
->getQuery()
->getResult()
;
}
}
8 changes: 7 additions & 1 deletion src/Repository/PageRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

use BitBag\CmsPlugin\Entity\PageInterface;
use Doctrine\ORM\QueryBuilder;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;

/**
Expand Down Expand Up @@ -43,4 +42,11 @@ public function findEnabledByCode(string $code): ?PageInterface;
* @return null|PageInterface
*/
public function findEnabledBySlug(string $slug, string $localeCode): ?PageInterface;

/**
* @param string $sectionCode
*
* @return PageInterface[]
*/
public function findEnabledBySectionCode(string $sectionCode): array;
}
2 changes: 1 addition & 1 deletion src/Repository/SectionRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function createListQueryBuilder(string $locale): QueryBuilder;
* @param string $phrase
* @param string|null $locale
*
* @return array|SectionInterface[]
* @return SectionInterface[]
*/
public function findByNamePart(string $phrase, ?string $locale = null): array;
}
11 changes: 11 additions & 0 deletions src/Resources/config/doctrine/Block.orm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,16 @@ BitBag\CmsPlugin\Entity\Block:
referencedColumnName: id
inverseJoinColumns:
section_id:
referencedColumnName: id
onDelete: CASCADE
products:
targetEntity: Sylius\Component\Product\Model\ProductInterface
joinTable:
name: bitbag_block_products
joinColumns:
page_id:
referencedColumnName: id
inverseJoinColumns:
product_id:
referencedColumnName: id
onDelete: CASCADE
6 changes: 6 additions & 0 deletions src/Resources/config/grids/block.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ sylius_grid:
sortable: ~
options:
template: "@SyliusUi/Grid/Field/enabled.html.twig"
sections:
type: twig
label: bitbag.ui.sections
path: .
options:
template: "@BitBagCmsPlugin/Grid/Field/sections.html.twig"
filters:
search:
type: string
Expand Down
6 changes: 6 additions & 0 deletions src/Resources/config/grids/frequently_asked_question.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ sylius_grid:
type: string
label: bitbag.ui.answer
sortable: translation.answer
sections:
type: twig
label: bitbag.ui.sections
path: .
options:
template: "@BitBagCmsPlugin/Grid/Field/sections.html.twig"
filters:
search:
type: string
Expand Down
6 changes: 6 additions & 0 deletions src/Resources/config/grids/page.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ sylius_grid:
type: string
label: bitbag.ui.slug
sortable: translation.slug
sections:
type: twig
label: bitbag.ui.sections
path: .
options:
template: "@BitBagCmsPlugin/Grid/Field/sections.html.twig"
filters:
search:
type: string
Expand Down
6 changes: 6 additions & 0 deletions src/Resources/config/grids/section.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ sylius_grid:
type: string
label: bitbag.ui.name
sortable: translation.name
sections:
type: twig
label: bitbag.ui.sections
path: .
options:
template: "@BitBagCmsPlugin/Grid/Field/sections.html.twig"
filters:
search:
type: string
Expand Down
3 changes: 3 additions & 0 deletions src/Resources/config/routing/shop.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
bitbag_shop_block:
resource: "@BitBagCmsPlugin/Resources/config/routing/shop/block.yml"

bitbag_shop_page:
resource: "@BitBagCmsPlugin/Resources/config/routing/shop/page.yml"

Expand Down
12 changes: 12 additions & 0 deletions src/Resources/config/routing/shop/block.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,17 @@ bitbag_shop_block_show:
_sylius:
repository:
method: findOneByCode
arguments:
- $code

bitbag_render_blocks_by_section_code:
path: /block/section/{code}
methods: [GET]
defaults:
_controller: bitbag.controller.block:indexAction
_sylius:
template: $template
repository:
method: findEnabledBySectionCode
arguments:
- $code
14 changes: 13 additions & 1 deletion src/Resources/config/routing/shop/frequently_asked_question.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,16 @@ bitbag_shop_frequently_asked_question_index:
repository:
method: findEnabledOrderedByPosition
arguments:
- "expr:service('sylius.context.locale').getLocaleCode()"
- "expr:service('sylius.context.locale').getLocaleCode()"

bitbag_render_frequently_asked_questions_by_section_code:
path: /faq/section/{code}
methods: [GET]
defaults:
_controller: bitbag.controller.frequently_asked_question:indexAction
_sylius:
template: $template
repository:
method: findEnabledBySectionCode
arguments:
- $code
Loading

0 comments on commit bba7da2

Please sign in to comment.