-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Init boolean filter and conference resource
- Loading branch information
Showing
21 changed files
with
629 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.