From 50d034a858bc2ca7d88fa361494e7c7e6bee41aa Mon Sep 17 00:00:00 2001 From: bernardhanna Date: Wed, 11 Feb 2026 14:44:57 +0000 Subject: [PATCH] dynamic GID --- app/GirlsInDigitalButton.php | 31 +++ app/GirlsInDigitalPage.php | 115 ++++++++--- app/Nova/GirlsInDigitalPage.php | 142 +++++++++++-- ..._digital_per_section_and_buttons_table.php | 190 ++++++++++++++++++ .../seeders/GirlsInDigitalButtonSeeder.php | 39 ++-- .../static/girls-in-digital-week.blade.php | 95 +++++---- 6 files changed, 520 insertions(+), 92 deletions(-) create mode 100644 app/GirlsInDigitalButton.php create mode 100644 database/migrations/2026_02_11_100000_girls_in_digital_per_section_and_buttons_table.php diff --git a/app/GirlsInDigitalButton.php b/app/GirlsInDigitalButton.php new file mode 100644 index 000000000..f7eadce36 --- /dev/null +++ b/app/GirlsInDigitalButton.php @@ -0,0 +1,31 @@ + 'boolean', + 'enabled' => 'boolean', + 'position' => 'integer', + ]; + + public function page() + { + return $this->belongsTo(GirlsInDigitalPage::class, 'page_id'); + } +} diff --git a/app/GirlsInDigitalPage.php b/app/GirlsInDigitalPage.php index 4453c248b..36bc6eebb 100644 --- a/app/GirlsInDigitalPage.php +++ b/app/GirlsInDigitalPage.php @@ -9,29 +9,67 @@ class GirlsInDigitalPage extends Model { protected $table = 'girls_in_digital_page'; + /** Content key => DB column (when different). */ + protected static $contentKeyToColumn = [ + 'landing_header' => 'hero_intro', + 'about_girls_title' => 'about_title', + 'about_girls_description_1' => 'about_description_1', + 'about_girls_description_2' => 'about_description_2', + ]; + protected $fillable = [ - 'use_dynamic_content', + 'hero_dynamic', + 'about_dynamic', + 'resources_dynamic', + 'matters_dynamic', + 'faq_dynamic', 'hero_intro', 'hero_video_url', + 'hero_image', 'about_title', 'about_description_1', 'about_description_2', + 'about_image', 'resource_title', 'resource_person_title', 'resource_person_description_1', 'resource_person_description_2', 'resource_educator_title', 'resource_educator_description', - 'buttons', + 'resource_young_image', + 'resource_educator_image', + 'matters_title', + 'matters_graph1_image', + 'matters_graph1_link', + 'matters_graph1_caption', + 'matters_graph2_image', + 'matters_graph2_link', + 'matters_graph2_caption', + 'matters_graph3_image', + 'matters_graph3_link', + 'matters_graph3_caption', + 'matters_paragraph_1', + 'matters_paragraph_2', + 'faq_title', + 'faq_items', 'locale_overrides', ]; protected $casts = [ - 'use_dynamic_content' => 'boolean', - 'buttons' => 'array', + 'hero_dynamic' => 'boolean', + 'about_dynamic' => 'boolean', + 'resources_dynamic' => 'boolean', + 'matters_dynamic' => 'boolean', + 'faq_dynamic' => 'boolean', + 'faq_items' => 'array', 'locale_overrides' => 'array', ]; + public function buttons() + { + return $this->hasMany(GirlsInDigitalButton::class, 'page_id')->orderBy('position'); + } + /** * Get the singleton page config (id = 1). Create if missing. */ @@ -60,9 +98,24 @@ public static function contentKeys(): array 'resource_person_description_2', 'resource_educator_title', 'resource_educator_description', + 'matters_title', + 'matters_graph1_caption', + 'matters_graph2_caption', + 'matters_graph3_caption', + 'matters_paragraph_1', + 'matters_paragraph_2', + 'faq_title', ]; } + /** + * Resolve content key to DB column name. + */ + public static function contentKeyToColumn(string $key): string + { + return self::$contentKeyToColumn[$key] ?? $key; + } + /** * Get content for a key in the current locale: locale override, then main (English) column, then lang file. */ @@ -73,8 +126,9 @@ public function contentForLocale(string $key, ?string $locale = null): string if (! empty($overrides[$locale][$key])) { return (string) $overrides[$locale][$key]; } - if (in_array($key, self::contentKeys(), true)) { - $value = $this->getAttribute($key); + $column = self::contentKeyToColumn($key); + if (in_array($column, self::contentKeys(), true)) { + $value = $this->getAttribute($column); if ($value !== null && $value !== '') { return (string) $value; } @@ -83,43 +137,50 @@ public function contentForLocale(string $key, ?string $locale = null): string } /** - * Get a button by key. Returns stdClass with label, url, open_new_tab, enabled or null. + * Get a button by key from the buttons relationship. Returns stdClass with label, url, open_new_tab, enabled or null. */ public function getButton(string $key, ?string $locale = null): ?object { - $buttons = $this->getButtonsForLocale($locale); - $btn = $buttons->firstWhere('key', $key); - if (! $btn || empty($btn['enabled'])) { + $button = $this->buttons()->where('key', $key)->first(); + if (! $button || ! $button->enabled) { return null; } $o = new \stdClass; - $o->key = $btn['key']; - $o->label = $btn['label'] ?? ''; - $o->url = $btn['url'] ?? '#'; - $o->open_new_tab = ! empty($btn['open_new_tab']); + $o->key = $button->key; + $o->label = $button->label; + $o->url = $button->url ?: '#'; + $o->open_new_tab = $button->open_new_tab; $o->enabled = true; return $o; } /** - * Buttons for locale: merge locale_overrides[locale].buttons onto main buttons. + * All buttons for this page (for Nova / admin). Keys preserved from relationship. */ public function getButtonsForLocale(?string $locale = null): Collection + { + return $this->buttons()->get()->map(fn ($b) => [ + 'key' => $b->key, + 'label' => $b->label, + 'url' => $b->url, + 'open_new_tab' => $b->open_new_tab, + 'enabled' => $b->enabled, + 'position' => $b->position, + ]); + } + + /** + * FAQ items for locale: locale_overrides[locale].faq_items or main faq_items. + * Each item: ['question' => string, 'answer' => string]. + */ + public function faqItemsForLocale(?string $locale = null): array { $locale = $locale ?? app()->getLocale(); - $main = collect($this->buttons ?? []); $overrides = $this->locale_overrides ?? []; - $localeButtons = $overrides[$locale]['buttons'] ?? null; - if (! is_array($localeButtons)) { - return $main; - } - $byKey = $main->keyBy('key'); - foreach ($localeButtons as $b) { - $k = $b['key'] ?? null; - if ($k !== null) { - $byKey->put($k, array_merge($byKey->get($k) ?? [], $b)); - } + if (! empty($overrides[$locale]['faq_items']) && is_array($overrides[$locale]['faq_items'])) { + return $overrides[$locale]['faq_items']; } - return $byKey->values()->sortBy('position')->values(); + $items = $this->faq_items ?? []; + return is_array($items) ? $items : []; } } diff --git a/app/Nova/GirlsInDigitalPage.php b/app/Nova/GirlsInDigitalPage.php index 8b23e64ca..854629be9 100644 --- a/app/Nova/GirlsInDigitalPage.php +++ b/app/Nova/GirlsInDigitalPage.php @@ -2,6 +2,7 @@ namespace App\Nova; +use App\GirlsInDigitalButton; use Illuminate\Http\Request; use Laravel\Nova\Fields\Boolean; use Laravel\Nova\Fields\Code; @@ -19,6 +20,21 @@ class GirlsInDigitalPage extends Resource public static $title = 'id'; + /** Button keys for the 8 fixed buttons (same order as blade). */ + private static function buttonKeys(): array + { + return [ + 'gcib_sprint_hero' => 'Girls Code It Better Sprint', + 'female_role_models' => 'Female Role Models Database', + 'open_call_challenges' => 'Open Call for GiD Challenges', + 'search_activity' => 'Search an activity', + 'meet_role_model' => 'Meet a Role Model', + 'organise_gcib_sprint' => 'Organise a GCIB Sprint', + 'activity_guideline' => 'Girls in Digital Activity Guideline', + 'social_media_kit' => 'Social Media Kit', + ]; + } + public static function label() { return 'Girls in Digital'; @@ -68,7 +84,7 @@ public function fields(Request $request): array Code::make('[' . $locale . ']', 'locale_override_' . $locale) ->json() ->nullable() - ->help('Optional. Override text/buttons for this locale. Keys: ' . implode(', ', \App\GirlsInDigitalPage::contentKeys()) . '. For buttons use "buttons": [{"key":"gcib_sprint_hero","label":"...","url":"...","open_new_tab":false,"enabled":true,"position":0}].') + ->help('Optional. Override text for this locale. Keys: ' . implode(', ', \App\GirlsInDigitalPage::contentKeys()) . '. faq_items: [{"question":"...","answer":"..."}].') ->resolveUsing(function () use ($locale) { $overrides = $this->resource->locale_overrides ?? []; return $overrides[$locale] ?? []; @@ -83,25 +99,48 @@ public function fields(Request $request): array ]); } + $buttonPanels = []; + foreach (self::buttonKeys() as $key => $title) { + $buttonPanels[] = new Panel('Button: ' . $title, [ + Boolean::make('Enabled', 'button_' . $key . '_enabled') + ->resolveUsing(fn () => $this->getButtonField($key, 'enabled')) + ->fillUsing(fn ($r, $m, $a, $ra) => $this->fillButtonField($m, $key, 'enabled', $r->get($ra))), + Text::make('Link (URL)', 'button_' . $key . '_url') + ->nullable() + ->resolveUsing(fn () => $this->getButtonField($key, 'url')) + ->fillUsing(fn ($r, $m, $a, $ra) => $this->fillButtonField($m, $key, 'url', $r->get($ra))), + Text::make('Text (label)', 'button_' . $key . '_label') + ->nullable() + ->resolveUsing(fn () => $this->getButtonField($key, 'label')) + ->fillUsing(fn ($r, $m, $a, $ra) => $this->fillButtonField($m, $key, 'label', $r->get($ra))), + Boolean::make('Open in new window', 'button_' . $key . '_open_new_tab') + ->resolveUsing(fn () => $this->getButtonField($key, 'open_new_tab')) + ->fillUsing(fn ($r, $m, $a, $ra) => $this->fillButtonField($m, $key, 'open_new_tab', $r->get($ra))), + ]); + } + return [ ID::make()->onlyOnForms(), - Boolean::make('Use dynamic content', 'use_dynamic_content') - ->help('When on, the Girls in Digital page uses the content below. When off, the static blade content is shown (current hardcoded text/images). Defaults to English for all languages; use locale overrides below for other languages.'), + new Panel('Section toggles (use dynamic content per section)', [ + Boolean::make('Hero dynamic', 'hero_dynamic')->help('Use DB content for hero (intro, video, image).'), + Boolean::make('About dynamic', 'about_dynamic')->help('Use DB content for about section.'), + Boolean::make('Resources dynamic', 'resources_dynamic')->help('Use DB content for resources section.'), + Boolean::make('Why matters dynamic', 'matters_dynamic')->help('Use DB content for "Why Girls in Digital Matters" section.'), + Boolean::make('FAQ dynamic', 'faq_dynamic')->help('Use DB content for FAQ (title + items).'), + ]), new Panel('Hero', [ - Textarea::make('Hero intro', 'hero_intro') - ->nullable() - ->help('Default (English) hero text. Leave empty to use static/lang.'), - Text::make('Hero video URL', 'hero_video_url') - ->nullable() - ->help('YouTube embed URL, e.g. https://www.youtube.com/embed/...'), + Textarea::make('Hero intro', 'hero_intro')->nullable(), + Text::make('Hero video URL', 'hero_video_url')->nullable()->help('YouTube embed URL.'), + Text::make('Hero image', 'hero_image')->nullable()->help('Path or URL for hero image.'), ]), new Panel('About', [ Text::make('About title', 'about_title')->nullable(), Textarea::make('About description 1', 'about_description_1')->nullable(), Textarea::make('About description 2', 'about_description_2')->nullable()->help('HTML allowed.'), + Text::make('About image', 'about_image')->nullable(), ]), new Panel('Resources', [ @@ -109,21 +148,98 @@ public function fields(Request $request): array Text::make('Young person / parent title', 'resource_person_title')->nullable(), Textarea::make('Young person / parent description 1', 'resource_person_description_1')->nullable(), Textarea::make('Young person / parent description 2', 'resource_person_description_2')->nullable(), + Text::make('Young person / parent image', 'resource_young_image')->nullable(), Text::make('Educator title', 'resource_educator_title')->nullable(), Textarea::make('Educator description', 'resource_educator_description')->nullable(), + Text::make('Educator image', 'resource_educator_image')->nullable(), + ]), + + new Panel('Why Girls in Digital Matters', [ + Text::make('Section title', 'matters_title')->nullable(), + Text::make('Graph 1 image', 'matters_graph1_image')->nullable(), + Text::make('Graph 1 link', 'matters_graph1_link')->nullable(), + Textarea::make('Graph 1 caption', 'matters_graph1_caption')->nullable(), + Text::make('Graph 2 image', 'matters_graph2_image')->nullable(), + Text::make('Graph 2 link', 'matters_graph2_link')->nullable(), + Textarea::make('Graph 2 caption', 'matters_graph2_caption')->nullable(), + Text::make('Graph 3 image', 'matters_graph3_image')->nullable(), + Text::make('Graph 3 link', 'matters_graph3_link')->nullable(), + Textarea::make('Graph 3 caption', 'matters_graph3_caption')->nullable(), + Textarea::make('Paragraph 1', 'matters_paragraph_1')->nullable(), + Textarea::make('Paragraph 2', 'matters_paragraph_2')->nullable(), ]), - new Panel('Buttons', [ - Code::make('Buttons', 'buttons') + new Panel('FAQ', [ + Text::make('FAQ section title', 'faq_title')->nullable(), + Code::make('FAQ items', 'faq_items') ->json() ->nullable() - ->help('Array of buttons. Each: {"key":"gcib_sprint_hero","label":"Girls Code It Better Sprint","url":"https://...","open_new_tab":false,"enabled":true,"position":0}. Keys: gcib_sprint_hero, female_role_models, open_call_challenges, search_activity, meet_role_model, organise_gcib_sprint, activity_guideline, social_media_kit. Disabled buttons are hidden.'), + ->help('Array of {"question":"...","answer":"..."}. HTML allowed in answer.'), ]), + ...$buttonPanels, + new Panel('Per-locale overrides (optional)', [ - \Laravel\Nova\Fields\Heading::make('Expand a locale to override text or button labels for that language. Defaults to English for all.'), + \Laravel\Nova\Fields\Heading::make('Expand a locale to override text for that language.'), ...$localePanels, ]), ]; } + + private function getButtonField(string $key, string $field) + { + $button = $this->resource->buttons()->where('key', $key)->first(); + if (! $button) { + return $field === 'enabled' ? true : ($field === 'open_new_tab' ? false : ''); + } + return $button->{$field}; + } + + private function fillButtonField(\App\GirlsInDigitalPage $model, string $key, string $field, $value): void + { + if (! isset($model->_button_updates)) { + $model->_button_updates = []; + } + if (! isset($model->_button_updates[$key])) { + $model->_button_updates[$key] = []; + } + if ($field === 'enabled' || $field === 'open_new_tab') { + $value = (bool) $value; + } + $model->_button_updates[$key][$field] = $value; + } + + public static function afterSave(NovaRequest $request, $model): void + { + $updates = $model->_button_updates ?? null; + if (! is_array($updates) || empty($updates)) { + return; + } + $positionMap = array_flip(array_keys(self::buttonKeys())); + foreach ($updates as $key => $fields) { + $existing = GirlsInDigitalButton::where('page_id', $model->id)->where('key', $key)->first(); + $payload = [ + 'label' => $fields['label'] ?? $existing?->label ?? '', + 'url' => $fields['url'] ?? $existing?->url ?? '#', + 'open_new_tab' => array_key_exists('open_new_tab', $fields) ? (bool) $fields['open_new_tab'] : ($existing?->open_new_tab ?? false), + 'enabled' => array_key_exists('enabled', $fields) ? (bool) $fields['enabled'] : ($existing?->enabled ?? true), + 'position' => $positionMap[$key] ?? $existing?->position ?? 0, + ]; + GirlsInDigitalButton::updateOrCreate( + ['page_id' => $model->id, 'key' => $key], + $payload + ); + } + unset($model->_button_updates); + } + + public static function afterCreate(NovaRequest $request, $model): void + { + self::afterSave($request, $model); + } + + public static function afterUpdate(NovaRequest $request, $model): void + { + self::afterSave($request, $model); + } } diff --git a/database/migrations/2026_02_11_100000_girls_in_digital_per_section_and_buttons_table.php b/database/migrations/2026_02_11_100000_girls_in_digital_per_section_and_buttons_table.php new file mode 100644 index 000000000..ef6699b10 --- /dev/null +++ b/database/migrations/2026_02_11_100000_girls_in_digital_per_section_and_buttons_table.php @@ -0,0 +1,190 @@ +boolean('hero_dynamic')->default(false)->after('id'); + } + if (! Schema::hasColumn($page, 'about_dynamic')) { + $table->boolean('about_dynamic')->default(false)->after('hero_dynamic'); + } + if (! Schema::hasColumn($page, 'resources_dynamic')) { + $table->boolean('resources_dynamic')->default(false)->after('about_dynamic'); + } + if (! Schema::hasColumn($page, 'matters_dynamic')) { + $table->boolean('matters_dynamic')->default(false)->after('resources_dynamic'); + } + if (! Schema::hasColumn($page, 'faq_dynamic')) { + $table->boolean('faq_dynamic')->default(false)->after('matters_dynamic'); + } + if (! Schema::hasColumn($page, 'hero_image')) { + $table->string('hero_image')->nullable()->after('hero_video_url'); + } + if (! Schema::hasColumn($page, 'about_image')) { + $table->string('about_image')->nullable()->after('about_description_2'); + } + if (! Schema::hasColumn($page, 'resource_young_image')) { + $table->string('resource_young_image')->nullable()->after('resource_educator_description'); + } + if (! Schema::hasColumn($page, 'resource_educator_image')) { + $table->string('resource_educator_image')->nullable()->after('resource_young_image'); + } + if (! Schema::hasColumn($page, 'matters_title')) { + $table->string('matters_title')->nullable()->after('resource_educator_image'); + } + if (! Schema::hasColumn($page, 'matters_graph1_image')) { + $table->string('matters_graph1_image')->nullable()->after('matters_title'); + } + if (! Schema::hasColumn($page, 'matters_graph1_link')) { + $table->string('matters_graph1_link')->nullable()->after('matters_graph1_image'); + } + if (! Schema::hasColumn($page, 'matters_graph1_caption')) { + $table->text('matters_graph1_caption')->nullable()->after('matters_graph1_link'); + } + if (! Schema::hasColumn($page, 'matters_graph2_image')) { + $table->string('matters_graph2_image')->nullable()->after('matters_graph1_caption'); + } + if (! Schema::hasColumn($page, 'matters_graph2_link')) { + $table->string('matters_graph2_link')->nullable()->after('matters_graph2_image'); + } + if (! Schema::hasColumn($page, 'matters_graph2_caption')) { + $table->text('matters_graph2_caption')->nullable()->after('matters_graph2_link'); + } + if (! Schema::hasColumn($page, 'matters_graph3_image')) { + $table->string('matters_graph3_image')->nullable()->after('matters_graph2_caption'); + } + if (! Schema::hasColumn($page, 'matters_graph3_link')) { + $table->string('matters_graph3_link')->nullable()->after('matters_graph3_image'); + } + if (! Schema::hasColumn($page, 'matters_graph3_caption')) { + $table->text('matters_graph3_caption')->nullable()->after('matters_graph3_link'); + } + if (! Schema::hasColumn($page, 'matters_paragraph_1')) { + $table->text('matters_paragraph_1')->nullable()->after('matters_graph3_caption'); + } + if (! Schema::hasColumn($page, 'matters_paragraph_2')) { + $table->text('matters_paragraph_2')->nullable()->after('matters_paragraph_1'); + } + if (! Schema::hasColumn($page, 'faq_title')) { + $table->string('faq_title')->nullable()->after('matters_paragraph_2'); + } + if (! Schema::hasColumn($page, 'faq_items')) { + $table->json('faq_items')->nullable()->after('faq_title'); + } + }); + + if (! Schema::hasTable('girls_in_digital_buttons')) { + Schema::create('girls_in_digital_buttons', function (Blueprint $table) { + $table->id(); + $table->unsignedBigInteger('page_id')->default(1); + $table->string('key'); + $table->unique(['page_id', 'key']); + $table->string('label'); + $table->string('url'); + $table->boolean('open_new_tab')->default(false); + $table->boolean('enabled')->default(true); + $table->unsignedInteger('position')->default(0); + $table->timestamps(); + }); + } + + if (Schema::hasColumn($page, 'buttons')) { + $row = DB::table($page)->where('id', 1)->first(); + if ($row && $row->buttons) { + $buttons = json_decode($row->buttons, true); + if (is_array($buttons)) { + foreach ($buttons as $i => $b) { + $key = $b['key'] ?? 'btn_' . $i; + DB::table('girls_in_digital_buttons')->updateOrInsert( + ['page_id' => 1, 'key' => $key], + [ + 'page_id' => 1, + 'label' => $b['label'] ?? '', + 'url' => $b['url'] ?? '', + 'open_new_tab' => (bool) ($b['open_new_tab'] ?? false), + 'enabled' => (bool) ($b['enabled'] ?? true), + 'position' => (int) ($b['position'] ?? $i), + 'updated_at' => now(), + 'created_at' => now(), + ] + ); + } + } + } + Schema::table($page, function (Blueprint $table) use ($page) { + $table->dropColumn('buttons'); + }); + } + + if (Schema::hasColumn($page, 'use_dynamic_content')) { + $uc = DB::table($page)->where('id', 1)->value('use_dynamic_content'); + Schema::table($page, function (Blueprint $table) use ($page) { + $table->dropColumn('use_dynamic_content'); + }); + if ($uc) { + DB::table($page)->where('id', 1)->update([ + 'hero_dynamic' => true, + 'about_dynamic' => true, + 'resources_dynamic' => true, + 'matters_dynamic' => true, + 'faq_dynamic' => true, + ]); + } + } + + $count = DB::table('girls_in_digital_buttons')->count(); + if ($count === 0) { + $defaults = [ + ['key' => 'gcib_sprint_hero', 'label' => 'Girls Code It Better Sprint', 'url' => 'https://codeweek.eu/blog/girls-in-digital-week-2026/', 'open_new_tab' => false, 'position' => 0], + ['key' => 'female_role_models', 'label' => 'Female Role Models Database', 'url' => 'https://codeweek.ecwt.eu/', 'open_new_tab' => true, 'position' => 1], + ['key' => 'open_call_challenges', 'label' => 'Open Call for GiD Challenges', 'url' => '/docs/girls-in-digital/open-call-for-new-code-week-challenges_v2.pdf', 'open_new_tab' => true, 'position' => 2], + ['key' => 'search_activity', 'label' => 'Search an activity', 'url' => '/events', 'open_new_tab' => false, 'position' => 3], + ['key' => 'meet_role_model', 'label' => 'Meet a Role Model', 'url' => 'https://codeweek.ecwt.eu/role-models/', 'open_new_tab' => true, 'position' => 4], + ['key' => 'organise_gcib_sprint', 'label' => 'Organise a GCIB Sprint', 'url' => 'https://codeweek-resources.s3.eu-west-1.amazonaws.com/GCIB-Sprint-materials.zip', 'open_new_tab' => false, 'position' => 5], + ['key' => 'activity_guideline', 'label' => 'Girls in Digital Activity Guideline', 'url' => '/docs/girls-in-digital/girls-in-digital-activity-guidelines.pdf', 'open_new_tab' => true, 'position' => 6], + ['key' => 'social_media_kit', 'label' => 'Social Media Kit', 'url' => '/docs/girls-in-digital/girls-in-digital-media-kit.pdf', 'open_new_tab' => true, 'position' => 7], + ]; + foreach ($defaults as $i => $d) { + DB::table('girls_in_digital_buttons')->insert([ + 'page_id' => 1, + 'key' => $d['key'], + 'label' => $d['label'], + 'url' => $d['url'], + 'open_new_tab' => $d['open_new_tab'], + 'enabled' => true, + 'position' => $d['position'], + 'created_at' => now(), + 'updated_at' => now(), + ]); + } + } + } + + public function down(): void + { + Schema::dropIfExists('girls_in_digital_buttons'); + $page = 'girls_in_digital_page'; + $cols = ['hero_dynamic', 'about_dynamic', 'resources_dynamic', 'matters_dynamic', 'faq_dynamic', 'hero_image', 'about_image', 'resource_young_image', 'resource_educator_image', 'matters_title', 'matters_graph1_image', 'matters_graph1_link', 'matters_graph1_caption', 'matters_graph2_image', 'matters_graph2_link', 'matters_graph2_caption', 'matters_graph3_image', 'matters_graph3_link', 'matters_graph3_caption', 'matters_paragraph_1', 'matters_paragraph_2', 'faq_title', 'faq_items']; + Schema::table($page, function (Blueprint $table) use ($page, $cols) { + foreach ($cols as $col) { + if (Schema::hasColumn($page, $col)) { + $table->dropColumn($col); + } + } + }); + } +}; diff --git a/database/seeders/GirlsInDigitalButtonSeeder.php b/database/seeders/GirlsInDigitalButtonSeeder.php index 9320c5b3c..89ee34881 100644 --- a/database/seeders/GirlsInDigitalButtonSeeder.php +++ b/database/seeders/GirlsInDigitalButtonSeeder.php @@ -2,14 +2,15 @@ namespace Database\Seeders; +use App\GirlsInDigitalButton; use App\GirlsInDigitalPage; use Illuminate\Database\Seeder; class GirlsInDigitalButtonSeeder extends Seeder { /** - * Seed the Girls in Digital page with default buttons (and optional default text). - * Run after the consolidate migration. Safe to run multiple times. + * Seed the Girls in Digital page with default buttons in the buttons table. + * Safe to run multiple times (upserts by page_id + key). */ public function run(): void { @@ -18,20 +19,30 @@ public function run(): void return; } - $defaultButtons = [ - ['key' => 'gcib_sprint_hero', 'label' => 'Girls Code It Better Sprint', 'url' => 'https://codeweek.eu/blog/girls-in-digital-week-2026/', 'open_new_tab' => false, 'enabled' => true, 'position' => 0], - ['key' => 'female_role_models', 'label' => 'Female Role Models Database', 'url' => 'https://codeweek.ecwt.eu/', 'open_new_tab' => true, 'enabled' => true, 'position' => 1], - ['key' => 'open_call_challenges', 'label' => 'Open Call for GiD Challenges', 'url' => '/docs/girls-in-digital/open-call-for-new-code-week-challenges_v2.pdf', 'open_new_tab' => true, 'enabled' => true, 'position' => 2], - ['key' => 'search_activity', 'label' => 'Search an activity', 'url' => '/events', 'open_new_tab' => false, 'enabled' => true, 'position' => 3], - ['key' => 'meet_role_model', 'label' => 'Meet a Role Model', 'url' => 'https://codeweek.ecwt.eu/role-models/', 'open_new_tab' => true, 'enabled' => true, 'position' => 4], - ['key' => 'organise_gcib_sprint', 'label' => 'Organise a GCIB Sprint', 'url' => 'https://codeweek-resources.s3.eu-west-1.amazonaws.com/GCIB-Sprint-materials.zip', 'open_new_tab' => false, 'enabled' => true, 'position' => 5], - ['key' => 'activity_guideline', 'label' => 'Girls in Digital Activity Guideline', 'url' => '/docs/girls-in-digital/girls-in-digital-activity-guidelines.pdf', 'open_new_tab' => true, 'enabled' => true, 'position' => 6], - ['key' => 'social_media_kit', 'label' => 'Social Media Kit', 'url' => '/docs/girls-in-digital/girls-in-digital-media-kit.pdf', 'open_new_tab' => true, 'enabled' => true, 'position' => 7], + $defaults = [ + ['key' => 'gcib_sprint_hero', 'label' => 'Girls Code It Better Sprint', 'url' => 'https://codeweek.eu/blog/girls-in-digital-week-2026/', 'open_new_tab' => false, 'position' => 0], + ['key' => 'female_role_models', 'label' => 'Female Role Models Database', 'url' => 'https://codeweek.ecwt.eu/', 'open_new_tab' => true, 'position' => 1], + ['key' => 'open_call_challenges', 'label' => 'Open Call for GiD Challenges', 'url' => '/docs/girls-in-digital/open-call-for-new-code-week-challenges_v2.pdf', 'open_new_tab' => true, 'position' => 2], + ['key' => 'search_activity', 'label' => 'Search an activity', 'url' => '/events', 'open_new_tab' => false, 'position' => 3], + ['key' => 'meet_role_model', 'label' => 'Meet a Role Model', 'url' => 'https://codeweek.ecwt.eu/role-models/', 'open_new_tab' => true, 'position' => 4], + ['key' => 'organise_gcib_sprint', 'label' => 'Organise a GCIB Sprint', 'url' => 'https://codeweek-resources.s3.eu-west-1.amazonaws.com/GCIB-Sprint-materials.zip', 'open_new_tab' => false, 'position' => 5], + ['key' => 'activity_guideline', 'label' => 'Girls in Digital Activity Guideline', 'url' => '/docs/girls-in-digital/girls-in-digital-activity-guidelines.pdf', 'open_new_tab' => true, 'position' => 6], + ['key' => 'social_media_kit', 'label' => 'Social Media Kit', 'url' => '/docs/girls-in-digital/girls-in-digital-media-kit.pdf', 'open_new_tab' => true, 'position' => 7], ]; - $page->buttons = $defaultButtons; - $page->save(); + foreach ($defaults as $d) { + GirlsInDigitalButton::updateOrCreate( + ['page_id' => $page->id, 'key' => $d['key']], + [ + 'label' => $d['label'], + 'url' => $d['url'], + 'open_new_tab' => $d['open_new_tab'], + 'enabled' => true, + 'position' => $d['position'], + ] + ); + } - $this->command->info('Girls in Digital page updated with default buttons. Edit in Nova under Content → Girls in Digital.'); + $this->command->info('Girls in Digital page buttons updated. Edit in Nova under Content → Girls in Digital.'); } } diff --git a/resources/views/static/girls-in-digital-week.blade.php b/resources/views/static/girls-in-digital-week.blade.php index 8dfe8ba10..5bdf2d161 100644 --- a/resources/views/static/girls-in-digital-week.blade.php +++ b/resources/views/static/girls-in-digital-week.blade.php @@ -10,18 +10,23 @@ @endsection @php - $useDynamic = $page && $page->use_dynamic_content; - $btn = function($key) use ($page, $useDynamic) { - if (!$useDynamic) { - return null; - } + $heroDynamic = $page && $page->hero_dynamic; + $aboutDynamic = $page && $page->about_dynamic; + $resourcesDynamic = $page && $page->resources_dynamic; + $mattersDynamic = $page && $page->matters_dynamic; + $faqDynamic = $page && $page->faq_dynamic; + $btn = function($key) use ($page) { return $page ? $page->getButton($key) : null; }; - $content = function($key) use ($page, $useDynamic) { - if (!$useDynamic || !$page) { - return ''; + $content = function($key) use ($page, $heroDynamic, $aboutDynamic, $resourcesDynamic, $mattersDynamic) { + if (!$page) return ''; + if (in_array($key, ['hero_intro', 'landing_header'], true) && $heroDynamic) return $page->contentForLocale($key === 'landing_header' ? 'hero_intro' : $key); + if (in_array($key, ['about_girls_title', 'about_girls_description_1', 'about_girls_description_2'], true) && $aboutDynamic) return $page->contentForLocale($key); + if (in_array($key, ['resource_title', 'resource_person_title', 'resource_person_description_1', 'resource_person_description_2', 'resource_educator_title', 'resource_educator_description'], true) && $resourcesDynamic) return $page->contentForLocale($key); + if (str_starts_with($key, 'matters_') || in_array($key, ['relevant_statistics_title', 'relevant_statistics_graph_1', 'relevant_statistics_graph_2'], true)) { + if ($mattersDynamic) return $page->contentForLocale($key); } - return $page->contentForLocale($key); + return ''; }; @endphp @section('content') @@ -36,17 +41,13 @@ class="mb-4 max-w-full" src="/images/digital-girls/digital_girls_logo.svg" />

- @if($useDynamic && $page->hero_intro) - {!! $page->hero_intro !!} - @else - {{ $content('landing_header') ?: "We're excited to announce Girls in Digital Week 2026! Empower, inspire and celebrate the next generation of girls and young Europeans!" }} - @endif + {!! $content('landing_header') ?: "We're excited to announce Girls in Digital Week 2026! Empower, inspire and celebrate the next generation of girls and young Europeans!" !!}

@include('layout.video-player', [ 'id' => 'girls-digital-hero', - 'src' => ($useDynamic && $page->hero_video_url) ? $page->hero_video_url : 'https://www.youtube.com/embed/XfYqEYLbPWY?si=7JQaVoVM6bJLuuoT', + 'src' => ($heroDynamic && $page && $page->hero_video_url) ? $page->hero_video_url : 'https://www.youtube.com/embed/XfYqEYLbPWY?si=7JQaVoVM6bJLuuoT', ])
- +

- Why Girls in Digital Matters + {{ ($mattersDynamic && $page && $page->matters_title) ? $page->matters_title : 'Why Girls in Digital Matters' }}

- - Cracking the code: Girls’ and women’s education in science, technology, engineering and mathematics (STEM). United Nations Educational, Scientific and Cultural Organization (UNESCO), 2017. + @php + $g3img = ($mattersDynamic && $page && $page->matters_graph3_image) ? $page->matters_graph3_image : '/images/digital-girls/fig-3.png'; + $g3link = ($mattersDynamic && $page && $page->matters_graph3_link) ? $page->matters_graph3_link : 'https://unesdoc.unesco.org/ark:/48223/pf0000253479'; + @endphp + + {{ ($mattersDynamic && $page) ? $page->contentForLocale('matters_graph3_caption') : 'Cracking the code: Girls and women education in STEM. UNESCO, 2017.' }}

- Multiple interconnected factors influence girls' and women's participation, achievement, and progression in STEM, with individual beliefs shaped by family, peers, education, and broader societal influences. This diagram illustrates the various factors at different levels influencing female representation in STEM. Addressing these factors holistically has been shown to positively impact confidence and motivation, encouraging more girls and women to pursue STEM education and careers. + {!! ($mattersDynamic && $page && $page->matters_paragraph_2) ? $page->matters_paragraph_2 : __('girls-in-digital.relevant_statistics_graph_2') !!}

@@ -286,10 +287,27 @@ class="block mb-12 p-6 rounded-lg border-2 border-[#A4B8D9]"

- FAQ’s + {{ ($faqDynamic && $page && $page->faq_title) ? $page->faq_title : 'FAQ\'s' }}

+ @if($faqDynamic && $page && count($page->faqItemsForLocale()) > 0) + @foreach($page->faqItemsForLocale() as $faq) +
+
+

{{ $faq['question'] ?? '' }}

+ +
+
+
+ {!! $faq['answer'] ?? '' !!} +
+
+
+ @endforeach + @else {{-- General FAQs --}}
@@ -495,6 +513,7 @@ class="block mb-12 p-6 rounded-lg border-2 border-[#A4B8D9]"
+ @endif