Skip to content

Commit

Permalink
Init boolean filter and conference resource
Browse files Browse the repository at this point in the history
  • Loading branch information
loic425 committed Oct 1, 2024
1 parent fdf48e9 commit 280d222
Show file tree
Hide file tree
Showing 21 changed files with 629 additions and 3 deletions.
6 changes: 4 additions & 2 deletions app/DataFixtures/AppFixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
namespace App\DataFixtures;

use App\Story\DefaultBooksStory;
use App\Story\DefaultConferencesStory;
use App\Story\DefaultSpeakersStory;
use App\Story\DefaultTalksStory;
use App\Story\DefaultSyliusCon2024TalksStory;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;

Expand All @@ -24,7 +25,8 @@ class AppFixtures extends Fixture
public function load(ObjectManager $manager): void
{
DefaultBooksStory::load();
DefaultConferencesStory::load();
DefaultSpeakersStory::load();
DefaultTalksStory::load();
DefaultSyliusCon2024TalksStory::load();
}
}
105 changes: 105 additions & 0 deletions app/Entity/Conference.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace App\Entity;

use App\Form\ConferenceType;
use App\Grid\ConferenceGrid;
use App\Repository\ConferenceRepository;
use Doctrine\ORM\Mapping as ORM;
use Sylius\Resource\Metadata\AsResource;
use Sylius\Resource\Metadata\BulkDelete;
use Sylius\Resource\Metadata\Create;
use Sylius\Resource\Metadata\Delete;
use Sylius\Resource\Metadata\Index;
use Sylius\Resource\Metadata\Update;
use Sylius\Resource\Model\ResourceInterface;

#[ORM\Entity(repositoryClass: ConferenceRepository::class)]
#[AsResource(
section: 'admin',
formType: ConferenceType::class,
templatesDir: '@SyliusAdminUi/crud',
routePrefix: '/admin',
operations: [
new Create(),
new Update(),
new Index(grid: ConferenceGrid::class),
new Delete(),
new BulkDelete(),
],
)]
class Conference implements ResourceInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;

#[ORM\Column(length: 255)]
private ?string $name = null;

#[ORM\Column]
private ?\DateTimeImmutable $startsAt = null;

#[ORM\Column]
private ?\DateTimeImmutable $endsAt = null;

#[ORM\Column]
private ?bool $pastEvent = null;

public function getId(): ?int
{
return $this->id;
}

public function getName(): ?string
{
return $this->name;
}

public function setName(string $name): void
{
$this->name = $name;
}

public function getStartsAt(): ?\DateTimeImmutable
{
return $this->startsAt;
}

public function setStartsAt(\DateTimeImmutable $startsAt): void
{
$this->startsAt = $startsAt;
}

public function getEndsAt(): ?\DateTimeImmutable
{
return $this->endsAt;
}

public function setEndsAt(\DateTimeImmutable $endsAt): void
{
$this->endsAt = $endsAt;
}

public function isPastEvent(): ?bool
{
return $this->pastEvent;
}

public function setPastEvent(bool $pastEvent): void
{
$this->pastEvent = $pastEvent;
}
}
14 changes: 14 additions & 0 deletions app/Entity/Talk.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ class Talk implements ResourceInterface
#[ORM\Column(enumType: Track::class)]
private ?Track $track = null;

#[ORM\ManyToOne]
#[ORM\JoinColumn(nullable: false)]
private ?Conference $conference = null;

public function getId(): ?int
{
return $this->id;
Expand Down Expand Up @@ -131,4 +135,14 @@ public function setTrack(Track $track): void
{
$this->track = $track;
}

public function getConference(): ?Conference
{
return $this->conference;
}

public function setConference(?Conference $conference): void
{
$this->conference = $conference;
}
}
58 changes: 58 additions & 0 deletions app/Factory/ConferenceFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace App\Factory;

use App\Entity\Conference;
use Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory;

/**
* @extends PersistentProxyObjectFactory<Conference>
*/
final class ConferenceFactory extends PersistentProxyObjectFactory
{
public static function class(): string
{
return Conference::class;
}

public function withName(string $name): self
{
return $this->with(['name' => $name]);
}

public function withStartingDate(\DateTimeImmutable $startsAt): self
{
return $this->with(['startsAt' => $startsAt]);
}

public function withEndingDate(\DateTimeImmutable $endsAt): self
{
return $this->with(['endsAt' => $endsAt]);
}

public function pastEvent(bool $pastEvent): self
{
return $this->with(['pastEvent' => $pastEvent]);
}

protected function defaults(): array|callable
{
return [
'endsAt' => \DateTimeImmutable::createFromMutable(self::faker()->dateTime()),
'name' => ucfirst(self::faker()->words(2, true)) . ' ' . self::faker()->year(),
'pastEvent' => self::faker()->boolean(),
'startsAt' => \DateTimeImmutable::createFromMutable(self::faker()->dateTime()),
];
}
}
11 changes: 11 additions & 0 deletions app/Factory/TalkFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@

namespace App\Factory;

use App\Entity\Conference;
use App\Entity\Speaker;
use App\Entity\Talk;
use App\Enum\Track;
use function Zenstruck\Foundry\lazy;
use Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory;
use Zenstruck\Foundry\Persistence\Proxy;

Expand Down Expand Up @@ -60,6 +62,14 @@ public function withTrack(Track $track): self
return $this->with(['track' => $track]);
}

/**
* @param Proxy<Conference>|Conference $conference
*/
public function withConference(Proxy|Conference $conference): self
{
return $this->with(['conference' => $conference]);
}

protected function defaults(): array|callable
{
return [
Expand All @@ -68,6 +78,7 @@ protected function defaults(): array|callable
'startsAt' => \DateTimeImmutable::createFromMutable(self::faker()->dateTime()),
'endsAt' => \DateTimeImmutable::createFromMutable(self::faker()->dateTime()),
'track' => self::faker()->randomElement(Track::cases()),
'conference' => lazy(fn () => ConferenceFactory::randomOrCreate()),
];
}
}
42 changes: 42 additions & 0 deletions app/Form/ConferenceType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace App\Form;

use App\Entity\Conference;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class ConferenceType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('name')
->add('startsAt', null, [
'widget' => 'single_text',
])
->add('endsAt', null, [
'widget' => 'single_text',
])
;
}

public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Conference::class,
]);
}
}
102 changes: 102 additions & 0 deletions app/Grid/ConferenceGrid.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace App\Grid;

use App\Entity\Conference;
use Sylius\Bundle\GridBundle\Builder\Action\Action;
use Sylius\Bundle\GridBundle\Builder\Action\CreateAction;
use Sylius\Bundle\GridBundle\Builder\Action\DeleteAction;
use Sylius\Bundle\GridBundle\Builder\Action\UpdateAction;
use Sylius\Bundle\GridBundle\Builder\ActionGroup\BulkActionGroup;
use Sylius\Bundle\GridBundle\Builder\ActionGroup\ItemActionGroup;
use Sylius\Bundle\GridBundle\Builder\ActionGroup\MainActionGroup;
use Sylius\Bundle\GridBundle\Builder\Field\DateTimeField;
use Sylius\Bundle\GridBundle\Builder\Field\StringField;
use Sylius\Bundle\GridBundle\Builder\Filter\BooleanFilter;
use Sylius\Bundle\GridBundle\Builder\Filter\DateFilter;
use Sylius\Bundle\GridBundle\Builder\GridBuilderInterface;
use Sylius\Bundle\GridBundle\Grid\AbstractGrid;
use Sylius\Bundle\GridBundle\Grid\ResourceAwareGridInterface;

final class ConferenceGrid extends AbstractGrid implements ResourceAwareGridInterface
{
public static function getName(): string
{
return 'app_conference';
}

public function buildGrid(GridBuilderInterface $gridBuilder): void
{
$gridBuilder
->addOrderBy('startsAt', 'desc')
->addFilter(
BooleanFilter::create('pastEvent')
->setLabel('app.ui.past_event'),
)
->addFilter(
DateFilter::create('startsAt')
->setLabel('app.ui.starts_at'),
)
->addField(
StringField::create('name')
->setLabel('Name')
->setSortable(true),
)
->addField(
DateTimeField::create('startsAt')
->setLabel('app.ui.starts_at')
->setSortable(true),
)
->addField(
DateTimeField::create('endsAt')
->setLabel('app.ui.ends_at')
->setSortable(true),
)
->addActionGroup(
MainActionGroup::create(
CreateAction::create(),
),
)
->addActionGroup(
ItemActionGroup::create(
Action::create('show_talks', 'show')
->setIcon('list_letters')
->setLabel('app.ui.show_talks')
->setOptions([
'link' => [
'route' => 'app_admin_talk_index',
'parameters' => [
'criteria' => [
'conference' => 'resource.id',
],
],
],
]),
UpdateAction::create(),
DeleteAction::create(),
),
)
->addActionGroup(
BulkActionGroup::create(
DeleteAction::create(),
),
)
;
}

public function getResourceClass(): string
{
return Conference::class;
}
}
Loading

0 comments on commit 280d222

Please sign in to comment.