Skip to content
Merged
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
4 changes: 2 additions & 2 deletions app-modules/events/database/factories/EventFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public function definition(): array
'active' => true,
'title' => fake()->sentence(4),
'description' => fake()->text(),
'event_at' => Date::now(),
'event_at' => Date::today(),
'start_at' => Date::now(),
'end_at' => Date::now(),
'end_at' => Date::today()->endOfDay(),
'location' => fake()->sentence(3),
'max_attendees' => fake()->numberBetween(10, 100),
'attendees_count' => 0,
Expand Down
2 changes: 2 additions & 0 deletions app-modules/events/database/factories/TalkFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public function definition(): array
'field_type' => fake()->word(),
'title' => fake()->word(),
'description' => fake()->text(),
'starts_at' => Date::now(),
'ends_at' => Date::now(),
Comment thread
danielhe4rt marked this conversation as resolved.
'created_at' => Date::now(),
'updated_at' => Date::now(),
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public function up(): void
$table->string('field_type'); // IA, Dev, Design, etc.
$table->string('title');
$table->text('description');
$table->timestamp('starts_at');
$table->timestamp('ends_at');
$table->timestamps();
});
}
Expand Down
6 changes: 5 additions & 1 deletion app-modules/events/src/Enums/Talks/TalkStatusEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
enum TalkStatusEnum: string implements HasColor, HasIcon, HasLabel
{
case Pending = 'pending';
case Rejected = 'rejected';
case Accepted = 'accepted';
case Done = 'done';

Expand All @@ -21,6 +22,7 @@ public function getColor(): array
return match ($this) {
self::Pending => Color::Yellow,
self::Accepted => Color::Blue,
self::Rejected => Color::Red,
self::Done => Color::Green,
};
}
Expand All @@ -30,6 +32,7 @@ public function getIcon(): Heroicon
return match ($this) {
self::Pending => Heroicon::Clock,
self::Accepted => Heroicon::CircleStack,
self::Rejected => Heroicon::XCircle,
self::Done => Heroicon::ArrowUpCircle,
};
}
Expand All @@ -38,7 +41,8 @@ public function getLabel(): string
{
return match ($this) {
self::Pending => 'Pending',
self::Accepted => 'Live',
self::Accepted => 'Accepted',
self::Rejected => 'Rejected',
self::Done => 'Done',
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,69 @@
use Filament\Forms\Components\RichEditor;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Schemas\Components\Flex;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;
use He4rt\Events\Enums\Talks\TalkStatusEnum;
use He4rt\Events\Filament\Shared\Schemas\StartEndFieldsSchema;

class TalkForm
{
public static function configure(Schema $schema): Schema
{
return $schema
->components([
Select::make('tenant_id')
->label('Tenant')
->relationship('tenant', 'name')
->required(),
Select::make('user_id')
->label('User')
->relationship('user', 'username')
->required(),
Select::make('event_id')
->label('EventModel')
->relationship('event', 'title')
->required(),
TextInput::make('title')
->label('Title')
->minLength(3)
->maxLength(255)
->required(),
Select::make('status')
->enum(TalkStatusEnum::class)
->options(TalkStatusEnum::class)
->required(),
TextInput::make('field_type')
->maxLength(255)
->required(),
RichEditor::make('description')
->minLength(5)
->maxLength(255)
->required(),

Flex::make([
Section::make('Proposta da Palestra')
->description('Defina o evento, título e tipo da sua proposta.')
->icon('heroicon-m-clipboard-document-list')
->schema([
Select::make('tenant_id')
->label('Tenant')
->relationship('tenant', 'name')
->required()
->live()
->columnSpan(1),
Select::make('user_id')
->label('User')
->relationship('user', 'username')
->required()
->live()
->columnSpan(1),

TextInput::make('field_type')
->label('Tipo')
->minLength(3)
->maxlength(255)
->required()
->columnSpan(1),
TextInput::make('title')
->label('Título da Proposta')
->minLength(3)
->maxlength(255)
->required()
->columnSpanFull(),
Section::make('Horários da Palestra')
->description('Forneça os horários da sua palestra')
->schema(
StartEndFieldsSchema::make(),
),
])->columnSpan(3),

])
->columnSpanFull(),

Section::make('Detalhes e Conteúdo')
->description('Forneça a descrição completa da sua palestra e o que o público aprenderá.')
->icon('heroicon-m-document-text')
->schema([
RichEditor::make('description')
->label('Descrição Completa')
->required()
->columnSpanFull(),
])
->columnSpanFull(),

]);
}
}
69 changes: 40 additions & 29 deletions app-modules/events/src/Filament/App/Talks/Schemas/TalkForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
use Filament\Forms\Components\RichEditor;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Schemas\Components\Flex;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;
use He4rt\Events\Enums\Talks\TalkStatusEnum;
use He4rt\Events\Filament\Shared\Schemas\StartEndFieldsSchema;
use Illuminate\Database\Eloquent\Builder;

class TalkForm
Expand All @@ -20,36 +22,45 @@ public static function configure(Schema $schema): Schema
{
return $schema
->components([
Section::make('Proposta da Palestra')
->description('Defina o evento, título e tipo da sua proposta.')
->icon('heroicon-m-clipboard-document-list')
->columns(3)
->columnSpanFull()
->schema([
Select::make('event_id')
->label('Evento')
->searchable()
->relationship(
name: 'event',
titleAttribute: 'title',
modifyQueryUsing: fn (Builder $query) => $query->where('tenant_id', Filament::getTenant()->getKey())
)
->required()
->columnSpan(2),
Flex::make([
Section::make('Proposta da Palestra')
->description('Defina o evento, título e tipo da sua proposta.')
->icon('heroicon-m-clipboard-document-list')
->schema([
Select::make('event_id')
->label('Evento')
->preload()
->searchable()
->relationship(
name: 'event',
titleAttribute: 'title',
modifyQueryUsing: fn (Builder $query) => $query->where('tenant_id', Filament::getTenant()->getKey())
)
->required()
->live()
->columnSpan(1),

TextInput::make('field_type')
->label('Tipo')
->minLength(3)
->maxlength(255)
->required()
->columnSpan(1),
TextInput::make('title')
->label('Título da Proposta')
->minLength(3)
->maxlength(255)
->required()
->columnSpanFull(),
]),
TextInput::make('field_type')
->label('Tipo')
->minLength(3)
->maxlength(255)
->required()
->columnSpan(1),
TextInput::make('title')
->label('Título da Proposta')
->minLength(3)
->maxlength(255)
->required()
->columnSpanFull(),
Section::make('Horários da Palestra')
->description('Forneça os horários da sua palestra')
->schema(
StartEndFieldsSchema::make(),
),
])->columnSpan(3),

])
->columnSpanFull(),

Section::make('Detalhes e Conteúdo')
->description('Forneça a descrição completa da sua palestra e o que o público aprenderá.')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

declare(strict_types=1);

namespace He4rt\Events\Filament\Shared\Schemas;

use App\Rules\AvailableTalkSchedule;
use Carbon\Carbon;
use Filament\Forms\Components\DateTimePicker;
use Filament\Schemas\Components\Utilities\Get;
use He4rt\Events\Models\EventModel;
use Illuminate\Support\Facades\Date;

final class StartEndFieldsSchema
{
public static function make(): array
{
return [
DateTimePicker::make('starts_at')
->label('Starts at')
->minDate(function (Get $get): ?Carbon {

/** @var EventModel $event */
$event = EventModel::query()->where('id', $get('event_id'))->first();
if ($event) {
return Date::parse($event->start_at);
}

return null;
})
->required(),
DateTimePicker::make('ends_at')
->maxDate(function (Get $get): ?Carbon {

/** @var EventModel $event */
$event = EventModel::query()->where('id', $get('event_id'))->first();

if ($event) {
return Date::parse($event->end_at);
}

return null;
})
->after('starts_at')
->rules([
function (Get $get): array {
$eventId = $get('event_id');
$startsAt = $get('starts_at');

if ($eventId && $startsAt) {
return [
new AvailableTalkSchedule(
eventId: (int) $eventId,
start_at: (string) $startsAt,
),
];
}

return [];
},
])
->label('Ends at')
->required(),
];
}
}
36 changes: 36 additions & 0 deletions app-modules/events/src/Models/EventModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@
use He4rt\Events\Database\Factories\EventFactory;
use He4rt\Events\Enums\AttendingStatusEnum;
use He4rt\Events\Enums\EventTypeEnum;
use He4rt\Events\Enums\Talks\TalkStatusEnum;
use He4rt\Events\Models\Pivot\EventAttend;
use He4rt\Tenant\Models\Tenant;
use He4rt\User\Models\User;
use Illuminate\Database\Eloquent\Attributes\Scope;
use Illuminate\Database\Eloquent\Attributes\UseFactory;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
use Illuminate\Database\Eloquent\Relations\Pivot;

/**
Expand All @@ -32,6 +36,7 @@
* @property int $waitlist_count
* @property int $tenant_id
* @property Date $end_at
* @property Date $start_at
*/
#[UseFactory(EventFactory::class)]
class EventModel extends Model
Expand Down Expand Up @@ -135,6 +140,37 @@ public function tenant(): BelongsTo
return $this->belongsTo(Tenant::class);
}

/**
* @return HasMany<Talk, $this>
*/
public function talks(): HasMany
{
return $this->hasMany(Talk::class, 'event_id');
}

/**
* @return HasManyThrough<User, Talk>
*/
public function speakers(): HasManyThrough
{
return $this->hasManyThrough(User::class, Talk::class, 'user_id');
}
Comment thread
danielhe4rt marked this conversation as resolved.

#[Scope]
protected function availableHours(Builder $query, string $start, string $end): Builder
{
$query->where('start_at', '<=', $start)
->where('end_at', '>=', $end);

return $query->whereDoesntHave('talks', function (Builder $talkQuery) use ($start, $end): void {
$talkQuery
->whereIn('status', [TalkStatusEnum::Accepted->value, TalkStatusEnum::Done->value]);

$talkQuery->where('starts_at', '<', $end)
->where('ends_at', '>', $start);
});
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

#[Scope]
protected function active($query)
{
Expand Down
Loading