Skip to content
Draft
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: 2 additions & 0 deletions app/DataFixtures/AppFixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace App\DataFixtures;

use App\Story\DefaultApplicationsStory;
use App\Story\DefaultBooksStory;
use App\Story\DefaultConferencesStory;
use App\Story\DefaultSpeakersStory;
Expand All @@ -32,5 +33,6 @@ public function load(ObjectManager $manager): void
DefaultSyliusCon2024TalksStory::load();
DefaultTalksStory::load();
DefaultUsersStory::load();
DefaultApplicationsStory::load();
}
}
111 changes: 111 additions & 0 deletions app/Entity/Application.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?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\Enum\ApplicationStatus;
use App\Grid\ApplicationGrid;
use App\Repository\ApplicationRepository;
use Doctrine\ORM\Mapping as ORM;
use Sylius\Component\Resource\Model\ResourceInterface;
use Sylius\Resource\Metadata\ApplyStateMachineTransition;
use Sylius\Resource\Metadata\AsResource;
use Sylius\Resource\Metadata\Index;

#[ORM\Entity(repositoryClass: ApplicationRepository::class)]
#[AsResource(
section: 'admin',
templatesDir: '@SyliusAdminUi/crud',
routePrefix: '/admin',
operations: [
new Index(grid: ApplicationGrid::class),
new ApplyStateMachineTransition(stateMachineTransition: 'submit'),
new ApplyStateMachineTransition(stateMachineTransition: 'accept'),
new ApplyStateMachineTransition(stateMachineTransition: 'reject'),
new ApplyStateMachineTransition(stateMachineTransition: 'hold'),
new ApplyStateMachineTransition(stateMachineTransition: 'cancel'),
],
)]
class Application implements ResourceInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;

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

#[ORM\OneToOne(inversedBy: 'application', cascade: ['persist', 'remove'])]
#[ORM\JoinColumn(nullable: false)]
private ?Talk $talk = null;

#[ORM\Column(enumType: ApplicationStatus::class)]
private ?ApplicationStatus $status = null;

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

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

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

public function setSubmittedAt(\DateTimeImmutable $submittedAt): static
{
$this->submittedAt = $submittedAt;

return $this;
}

public function getTalk(): ?Talk
{
return $this->talk;
}

public function setTalk(Talk $talk): static
{
$this->talk = $talk;

return $this;
}

public function getStatus(): ?ApplicationStatus
{
return $this->status;
}

public function setStatus(ApplicationStatus $status): static
{
$this->status = $status;

return $this;
}

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

public function setUpdatedAt(\DateTimeImmutable $updatedAt): static
{
$this->updatedAt = $updatedAt;

return $this;
}
}
5 changes: 5 additions & 0 deletions app/Entity/Speaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,9 @@ public function getTalks(): Collection
{
return $this->talks;
}

public function __toString(): string
{
return $this->getFullName();
}
}
20 changes: 20 additions & 0 deletions app/Entity/Talk.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ class Talk implements ResourceInterface
#[ORM\ManyToMany(targetEntity: Speaker::class, inversedBy: 'talks')]
private Collection $speakers;

#[ORM\OneToOne(mappedBy: 'talk', cascade: ['persist', 'remove'])]
private ?Application $application = null;

public function __construct()
{
$this->speakers = new ArrayCollection();
Expand Down Expand Up @@ -181,4 +184,21 @@ public function removeSpeaker(Speaker $speaker): void
{
$this->speakers->removeElement($speaker);
}

public function getApplication(): ?Application
{
return $this->application;
}

public function setApplication(Application $application): static
{
// set the owning side of the relation if necessary
if ($application->getTalk() !== $this) {
$application->setTalk($this);
}

$this->application = $application;

return $this;
}
}
23 changes: 23 additions & 0 deletions app/Enum/ApplicationStateMachineTransition.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?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\Enum;

enum ApplicationStateMachineTransition: string
{
case REJECT = 'reject';
case ACCEPT = 'accept';
case SUBMIT = 'submit';
case HOLD = 'hold';
case CANCEL = 'cancel';
}
24 changes: 24 additions & 0 deletions app/Enum/ApplicationStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?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\Enum;

enum ApplicationStatus: string
{
case DRAFT = 'draft';
case SUBMITTED = 'submitted';
case ACCEPTED = 'accepted';
case REJECTED = 'rejected';
case CANCELLED = 'cancelled';
case WAITING_LIST = 'waiting list';
}
48 changes: 48 additions & 0 deletions app/Factory/ApplicationFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?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\Application;
use App\Enum\ApplicationStatus;
use Zenstruck\Foundry\Persistence\PersistentObjectFactory;

/**
* @extends PersistentObjectFactory<Application>
*/
final class ApplicationFactory extends PersistentObjectFactory
{

#[\Override]
public static function class(): string
{
return Application::class;
}

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

#[\Override]
protected function defaults(): array|callable
{
return [
'status' => self::faker()->randomElement(ApplicationStatus::cases()),
'submittedAt' => \DateTimeImmutable::createFromMutable(self::faker()->dateTime()),
'talk' => TalkFactory::new(),
'updatedAt' => \DateTimeImmutable::createFromMutable(self::faker()->dateTime()),
];
}
}
89 changes: 89 additions & 0 deletions app/Grid/ApplicationGrid.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?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\Application;
use App\Entity\Conference;
use App\Enum\ApplicationStatus;
use App\Grid\Filter\SpeakerFilter;
use Sylius\Bundle\GridBundle\Builder\Action\ApplyTransitionAction;
use Sylius\Bundle\GridBundle\Builder\Field\DateTimeField;
use Sylius\Bundle\GridBundle\Builder\Field\EnumField;
use Sylius\Bundle\GridBundle\Builder\Field\StringField;
use Sylius\Bundle\GridBundle\Builder\Field\TwigField;
use Sylius\Bundle\GridBundle\Builder\Filter\DateFilter;
use Sylius\Bundle\GridBundle\Builder\Filter\EntityFilter;
use Sylius\Bundle\GridBundle\Builder\Filter\EnumFilter;
use Sylius\Bundle\GridBundle\Builder\Filter\Filter;
use Sylius\Bundle\GridBundle\Builder\Filter\StringFilter;
use Sylius\Bundle\GridBundle\Builder\GridBuilderInterface;
use Sylius\Component\Grid\Attribute\AsGrid;

#[AsGrid(
resourceClass: Application::class,
name: 'app_application',
)]
final class ApplicationGrid
{
public function __invoke(GridBuilderInterface $gridBuilder): void
{
$gridBuilder
->withFilters(
EntityFilter::create(name: 'conference', resourceClass: Conference::class, fields: ['talk.conference'])
->setLabel('app.ui.conference')
->addFormOption('choice_label', 'name'),
Filter::create(name: 'speaker', type: SpeakerFilter::class)
->setLabel('app.ui.speaker')
->setOptions(['fields' => ['talk.speakers.id']]),
StringFilter::create('search', ['talk.title'])
->setLabel('sylius.ui.search'),
EnumFilter::create(name: 'status', enumClass: ApplicationStatus::class, field: 'status')
->addFormOption('choice_value', fn (?ApplicationStatus $enum) => $enum?->value)
->addFormOption('choice_label', fn (ApplicationStatus $choice) => ucfirst($choice->value))
->setLabel('app.ui.status'),
DateFilter::create('submittedAt')
->setLabel('app.ui.submitted_at'),
)
->withFields(
StringField::create('talk.title')
->setLabel('app.ui.talk'),
TwigField::create(name: 'talk.speakers', template: 'talk/grid/field/speakers.html.twig')
->setLabel('app.ui.speakers')
->setSortable(true),
EnumField::create('status')
->setLabel('app.ui.status')
->setSortable(true),
DateTimeField::create('submittedAt')
->setLabel('app.ui.submitted_at')
->setSortable(true),
DateTimeField::create('updatedAt')
->setLabel('app.ui.updated_at')
->setSortable(true),
)
->withItemActions(
ApplyTransitionAction::create(name: 'accept', route: 'app_admin_application_accept')
->setIcon('ep:success-filled')
->setLabel('app.ui.accept'),
ApplyTransitionAction::create(name: 'reject', route: 'app_admin_application_reject')
->setIcon('flat-color-icons:cancel')
->setLabel('app.ui.reject'),
ApplyTransitionAction::create(name: 'hold', route: 'app_admin_application_hold')
->setIcon('iconmind:wait-approval-outline-thin')
->setLabel('app.ui.hold'),
ApplyTransitionAction::create(name: 'cancel', route: 'app_admin_application_cancel')
->setIcon('streamline-stickies-color:cancel-2')
->setLabel('app.ui.cancel'),
);
}
}
4 changes: 4 additions & 0 deletions app/Menu/AdminMenuBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,9 @@ private function addConfigurationSubMenu(ItemInterface $menu): void
$configuration->addChild('speakers', ['route' => 'app_admin_speaker_index'])
->setLabel('app.ui.speakers')
;

$configuration->addChild('applications', ['route' => 'app_admin_application_index'])
->setLabel('app.ui.applications')
;
}
}
Loading
Loading