diff --git a/app/Livewire/PartnerContentComponent.php b/app/Livewire/PartnerContentComponent.php index a8ca0a18e..44c2d30d9 100644 --- a/app/Livewire/PartnerContentComponent.php +++ b/app/Livewire/PartnerContentComponent.php @@ -1,6 +1,7 @@ |null Lazy-filled default partners list (used when DB is empty). */ + private static $defaultPartnersRaw = null; + public $filter = 'Partners'; public $selectedPartner = null; @@ -87,7 +91,13 @@ public function mount() private function getAllPartners() { - return collect([ + $fromDb = Partner::active()->ordered()->get(); + if ($fromDb->isNotEmpty()) { + return $fromDb->map(fn (Partner $p) => $p->toPartnerObject()); + } + + if (self::$defaultPartnersRaw === null) { + self::$defaultPartnersRaw = [ (object)[ 'id' => 1, 'name' => 'JA EUROPE', @@ -576,10 +586,23 @@ private function getAllPartners() 'link_url' => 'https://www.athenarc.gr/en', 'main_img_url' => 'images/partners/Athena_RC_logo.png' ], - ]); + ]; + } + return collect(self::$defaultPartnersRaw); + } + + /** + * Return default partners as array of arrays (for seeding into DB). Call after getAllPartners() or ensure defaults are loaded. + */ + public static function getDefaultPartnersForSeeding(): array + { + if (self::$defaultPartnersRaw === null) { + (new self())->getAllPartners(); + } + return array_map(fn ($o) => (array) $o, self::$defaultPartnersRaw); } -public function render() + public function render() { if ($this->filter === 'Council Presidency') { // Council Presidency content diff --git a/app/Nova/Partner.php b/app/Nova/Partner.php new file mode 100644 index 000000000..c8657ceca --- /dev/null +++ b/app/Nova/Partner.php @@ -0,0 +1,93 @@ +sortable(), + + Text::make('Name', 'name') + ->nullable() + ->help('Display name. Optional for sponsor logos (e.g. EU Code Week Supporters).'), + + Text::make('Logo URL', 'logo_url') + ->rules('required') + ->help('Path from site root, e.g. images/partners/logo.png (no leading slash), or full URL.'), + + Select::make('Category', 'categories') + ->options([ + 'Partners' => 'Partners', + 'Sponsor' => 'EU Code Week Supporters (Sponsor)', + ]) + ->help('Partners = "Partners" tab; Sponsor = "EU Code Week Supporters" tab.') + ->resolveUsing(function ($value) { + $arr = is_array($value) ? $value : (array) json_decode($value ?? '[]', true); + return $arr[0] ?? null; + }) + ->fillUsing(function ($request, $model, $attribute, $requestAttribute) { + $v = $request->get($requestAttribute); + $model->{$attribute} = $v !== null && $v !== '' ? [$v] : []; + }), + + Textarea::make('Description', 'description') + ->nullable() + ->help('HTML allowed. Shown when partner is selected (Partners tab only).'), + + Text::make('Link URL', 'link_url') + ->nullable() + ->help('Website URL for "Visit Partner" link.'), + + Text::make('Main image URL', 'main_img_url') + ->nullable() + ->help('Larger image path (optional).'), + + Number::make('Position', 'position') + ->min(0) + ->default(0) + ->help('Order on partners page (lower = first).'), + + Boolean::make('Active', 'active') + ->help('Inactive partners are hidden from the sponsors page.'), + ]; + } + + public static function indexQuery(NovaRequest $request, $query) + { + return $query->orderBy('position')->orderBy('id'); + } +} diff --git a/app/Partner.php b/app/Partner.php new file mode 100644 index 000000000..5de0efac9 --- /dev/null +++ b/app/Partner.php @@ -0,0 +1,51 @@ + 'array', + 'active' => 'boolean', + 'position' => 'integer', + ]; + + public function scopeOrdered($query) + { + return $query->orderBy('position')->orderBy('id'); + } + + public function scopeActive($query) + { + return $query->where('active', true); + } + + /** + * Convert to the same stdClass shape used by the Livewire component (id, name, logo_url, categories, description, link_url, main_img_url). + */ + public function toPartnerObject(): \stdClass + { + $o = new \stdClass; + $o->id = $this->id; + $o->name = $this->name; + $o->logo_url = $this->logo_url; + $o->categories = $this->categories ?? []; + $o->description = $this->description; + $o->link_url = $this->link_url; + $o->main_img_url = $this->main_img_url; + return $o; + } +} diff --git a/database/migrations/2026_02_09_190000_create_partners_table.php b/database/migrations/2026_02_09_190000_create_partners_table.php new file mode 100644 index 000000000..14c9f5a3e --- /dev/null +++ b/database/migrations/2026_02_09_190000_create_partners_table.php @@ -0,0 +1,29 @@ +id(); + $table->string('name')->nullable(); + $table->string('logo_url'); + $table->json('categories')->nullable(); // ['Partners'] or ['Sponsor'] + $table->longText('description')->nullable(); + $table->string('link_url')->nullable(); + $table->string('main_img_url')->nullable(); + $table->unsignedInteger('position')->default(0); + $table->boolean('active')->default(true); + $table->timestamps(); + }); + } + + public function down(): void + { + Schema::dropIfExists('partners'); + } +}; diff --git a/database/seeders/PartnerSeeder.php b/database/seeders/PartnerSeeder.php new file mode 100644 index 000000000..91e01ed0b --- /dev/null +++ b/database/seeders/PartnerSeeder.php @@ -0,0 +1,41 @@ + 0) { + $this->command->info('Partners table already has data. Skipping seed. Delete partners first to re-seed from defaults.'); + + return; + } + + $defaults = PartnerContentComponent::getDefaultPartnersForSeeding(); + + foreach ($defaults as $i => $row) { + Partner::create([ + 'name' => $row['name'] ?? null, + 'logo_url' => $row['logo_url'] ?? '', + 'categories' => $row['categories'] ?? ['Partners'], + 'description' => $row['description'] ?? null, + 'link_url' => $row['link_url'] ?? null, + 'main_img_url' => $row['main_img_url'] ?? null, + 'position' => $i, + 'active' => true, + ]); + } + + $this->command->info('Seeded ' . count($defaults) . ' partners. You can now edit them in Nova.'); + } +}