Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ jobs:
run: vendor/bin/behat --colors --strict -vvv --no-interaction || vendor/bin/behat --colors --strict -vvv --no-interaction --rerun

- name: Upload Behat logs
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
if: failure()
with:
name: Behat logs
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ parameters:

ignoreErrors:
- '/Parameter #1 \$configuration of method Symfony\\Component\\DependencyInjection\\Extension\\Extension::processConfiguration\(\) expects Symfony\\Component\\Config\\Definition\\ConfigurationInterface, Symfony\\Component\\Config\\Definition\\ConfigurationInterface\|null given\./'
- '#Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\NodeDefinition::children\(\).#'
76 changes: 76 additions & 0 deletions src/Fixture/BannerSectionFixture.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

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

declare(strict_types=1);

namespace BitBag\SyliusBannerPlugin\Fixture;

use BitBag\SyliusBannerPlugin\Fixture\Factory\FixtureFactoryInterface;
use Sylius\Bundle\FixturesBundle\Fixture\AbstractFixture;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;

final class BannerSectionFixture extends AbstractFixture
{
public function __construct(private FixtureFactoryInterface $factory)
{
}

public function load(array $options): void
{
$this->factory->load($options['sections']);
}

public function getName(): string
{
return 'banner_section';
}

protected function configureOptionsNode(ArrayNodeDefinition $optionsNode): void
{
$optionsNode
->children()
->arrayNode('sections')
->prototype('array')
->children()
->scalarNode('name')->isRequired()->cannotBeEmpty()->end()
->scalarNode('code')->isRequired()->cannotBeEmpty()->end()
->integerNode('width')->defaultNull()->end()
->integerNode('height')->defaultNull()->end()
->arrayNode('banners')
->prototype('array')
->children()
->scalarNode('path')->isRequired()->cannotBeEmpty()->end()
->scalarNode('alt')->defaultNull()->end()
->scalarNode('filename')->isRequired()->cannotBeEmpty()->end()
->scalarNode('link')->defaultNull()->end()
->integerNode('priority')->isRequired()->end()
->integerNode('clicks')->defaultValue(0)->end()
->scalarNode('locale')->isRequired()->cannotBeEmpty()->end()
->arrayNode('ads')
->prototype('array')
->children()
->scalarNode('name')->isRequired()->cannotBeEmpty()->end()
->booleanNode('enabled')->isRequired()->end()
->scalarNode('startAt')->isRequired()->cannotBeEmpty()->end()
->scalarNode('endAt')->isRequired()->cannotBeEmpty()->end()
->integerNode('priority')->isRequired()->end()
->scalarNode('code')->isRequired()->cannotBeEmpty()->end()
->end()
->end()
->end()
->end()
->end()
->end()
->end()
->end()
->end()
->end()
;
}
}
98 changes: 98 additions & 0 deletions src/Fixture/Factory/BannerSectionFixtureFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php

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

declare(strict_types=1);

namespace BitBag\SyliusBannerPlugin\Fixture\Factory;

use BitBag\SyliusBannerPlugin\Entity\AdInterface;
use BitBag\SyliusBannerPlugin\Entity\BannerInterface;
use BitBag\SyliusBannerPlugin\Entity\SectionInterface;
use BitBag\SyliusBannerPlugin\Repository\AdRepositoryInterface;
use BitBag\SyliusBannerPlugin\Repository\BannerRepositoryInterface;
use BitBag\SyliusBannerPlugin\Repository\SectionRepositoryInterface;
use Sylius\Component\Locale\Model\LocaleInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;

final class BannerSectionFixtureFactory implements FixtureFactoryInterface
{
public function __construct(
private FactoryInterface $sectionFactory,
private FactoryInterface $bannerFactory,
private FactoryInterface $adFactory,
private SectionRepositoryInterface $sectionRepository,
private BannerRepositoryInterface $bannerRepository,
private AdRepositoryInterface $adRepository,
private RepositoryInterface $localeRepository,
) {
}

public function load(array $data): void
{
foreach ($data as $fields) {
/** @var SectionInterface $section */
$section = $this->sectionFactory->createNew();

$section->setCode($fields['code']);
$section->setName($fields['name']);
$section->setHeight($fields['height']);
$section->setWidth($fields['width']);

$this->sectionRepository->add($section);

if (($fields['banners'] ?? false) && is_array($fields['banners'])) {
foreach ($fields['banners'] as $bannerData) {
/** @var BannerInterface $banner */
$banner = $this->bannerFactory->createNew();

$banner->setPath($bannerData['path']);
$banner->setAlt($bannerData['alt'] ?? null);
$banner->setFileName($bannerData['filename']);
$banner->setLink($bannerData['link'] ?? null);
$banner->setPriority($bannerData['priority']);
$banner->setClicks($bannerData['clicks'] ?? 0);

/** @var ?LocaleInterface $locale */
$locale = $this->localeRepository->findOneBy(['code' => $bannerData['locale']]);

if (null === $locale) {
throw new \Exception(sprintf('Locale with code "%s" not found', $bannerData['locale']));
}

$banner->setLocale($locale);

$this->bannerRepository->add($banner);

if (isset($bannerData['ads']) && is_array($bannerData['ads'])) {
foreach ($bannerData['ads'] as $adData) {
/** @var AdInterface $ad */
$ad = $this->adFactory->createNew();

$ad->setName($adData['name']);
$ad->setEnabled($adData['enabled']);
$ad->setStartAt(new \DateTime($adData['startAt']));
$ad->setEndAt(new \DateTime($adData['endAt']));
$ad->setPriority($adData['priority']);
$ad->setCode($adData['code']);

$this->adRepository->add($ad);

$banner->addAds($ad);
}
}

$banner->setSection($section);

$this->bannerRepository->add($banner);
}
}
}
}
}
17 changes: 17 additions & 0 deletions src/Fixture/Factory/FixtureFactoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

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

declare(strict_types=1);

namespace BitBag\SyliusBannerPlugin\Fixture\Factory;

interface FixtureFactoryInterface
{
public function load(array $data): void;
}
3 changes: 2 additions & 1 deletion src/Repository/AdRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
namespace BitBag\SyliusBannerPlugin\Repository;

use BitBag\SyliusBannerPlugin\Entity\AdInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;

interface AdRepositoryInterface
interface AdRepositoryInterface extends RepositoryInterface
{
public function findAllActiveAds(): array;

Expand Down
3 changes: 2 additions & 1 deletion src/Repository/SectionRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@

use BitBag\SyliusBannerPlugin\Entity\AdInterface;
use BitBag\SyliusBannerPlugin\Entity\SectionInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;

interface SectionRepositoryInterface
interface SectionRepositoryInterface extends RepositoryInterface
{
public function findAllActiveAdsBanners(string $sectionCode, string $localeCode): ?SectionInterface;

Expand Down
14 changes: 14 additions & 0 deletions src/Resources/config/services/fixture/fixtures.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>

<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="bitbag.sylius_banner_plugin.fixture.banner_section_fixture"
class="BitBag\SyliusBannerPlugin\Fixture\BannerSectionFixture"
public="true"
>
<argument type="service" id="bitbag.sylius_banner_plugin.fixture.factory.banner_section_fixture_factory" />

<tag name="sylius_fixtures.fixture" />
</service>
</services>
</container>
18 changes: 18 additions & 0 deletions src/Resources/config/services/fixture/fixtures_factories.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>

<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="bitbag.sylius_banner_plugin.fixture.factory.banner_section_fixture_factory"
class="BitBag\SyliusBannerPlugin\Fixture\Factory\BannerSectionFixtureFactory"
public="true"
>
<argument type="service" id="bitbag_sylius_banner_plugin.factory.section" />
<argument type="service" id="bitbag_sylius_banner_plugin.factory.banner" />
<argument type="service" id="bitbag_sylius_banner_plugin.factory.ad" />
<argument type="service" id="bitbag_sylius_banner_plugin.repository.section" />
<argument type="service" id="bitbag_sylius_banner_plugin.repository.banner" />
<argument type="service" id="bitbag_sylius_banner_plugin.repository.ad" />
<argument type="service" id="sylius.repository.locale" />
</service>
</services>
</container>
Loading