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
35 changes: 35 additions & 0 deletions app/GirlsInDigitalButton.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class GirlsInDigitalButton extends Model
{
protected $table = 'girls_in_digital_buttons';

protected $fillable = [
'key',
'label',
'url',
'open_new_tab',
'enabled',
'position',
];

protected $casts = [
'open_new_tab' => 'boolean',
'enabled' => 'boolean',
'position' => 'integer',
];

public function scopeEnabled($query)
{
return $query->where('enabled', true);
}

public function scopeOrdered($query)
{
return $query->orderBy('position')->orderBy('id');
}
}
39 changes: 39 additions & 0 deletions app/GirlsInDigitalPage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class GirlsInDigitalPage extends Model
{
protected $table = 'girls_in_digital_page';

protected $fillable = ['locale_overrides'];

protected $casts = ['locale_overrides' => 'array'];

/**
* Get the singleton page config (id = 1). Create if missing.
*/
public static function config(): self
{
$page = self::first();
if ($page) {
return $page;
}
return self::create(['locale_overrides' => null]);
}

/**
* Get content for a key in the current locale: override or lang fallback.
*/
public function contentForLocale(string $key, ?string $locale = null): string
{
$locale = $locale ?? app()->getLocale();
$overrides = $this->locale_overrides ?? [];
if (! empty($overrides[$locale][$key])) {
return (string) $overrides[$locale][$key];
}
return (string) __('girls-in-digital.' . $key);
}
}
21 changes: 21 additions & 0 deletions app/Http/View/Composers/GirlsInDigitalComposer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace App\Http\View\Composers;

use App\GirlsInDigitalButton;
use App\GirlsInDigitalPage;
use Illuminate\Support\Facades\Schema;
use Illuminate\View\View;

class GirlsInDigitalComposer
{
public function compose(View $view): void
{
$buttons = collect();
if (Schema::hasTable('girls_in_digital_buttons')) {
$buttons = GirlsInDigitalButton::enabled()->ordered()->get();
}
$page = Schema::hasTable('girls_in_digital_page') ? GirlsInDigitalPage::config() : null;
$view->with(compact('buttons', 'page'));
}
}
57 changes: 57 additions & 0 deletions app/Nova/GirlsInDigitalButton.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace App\Nova;

use Illuminate\Http\Request;
use Laravel\Nova\Fields\Boolean;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Number;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Http\Requests\NovaRequest;

class GirlsInDigitalButton extends Resource
{
public static $group = 'Content';

public static $model = \App\GirlsInDigitalButton::class;

public static $title = 'label';

public static $search = ['key', 'label'];

public static function label()
{
return 'Girls in Digital – Buttons';
}

public static function singularLabel()
{
return 'Girls in Digital Button';
}

public static function authorizedToViewAny(Request $request): bool
{
return true;
}

public function fields(Request $request): array
{
return [
ID::make()->sortable(),
Text::make('Key', 'key')
->rules('required')
->help('Unique identifier, e.g. gcib_sprint_hero. Used in the blade to place the button.'),
Text::make('Label', 'label')->rules('required'),
Text::make('URL', 'url')->rules('required')->hideFromIndex(),
Boolean::make('Open in new tab', 'open_new_tab'),
Boolean::make('Enabled', 'enabled')
->help('When disabled, this button is hidden on the Girls in Digital page.'),
Number::make('Position', 'position')->min(0)->default(0),
];
}

public static function indexQuery(NovaRequest $request, $query)
{
return $query->orderBy('position')->orderBy('id');
}
}
109 changes: 109 additions & 0 deletions app/Nova/GirlsInDigitalPage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?php

namespace App\Nova;

use Illuminate\Http\Request;
use Laravel\Nova\Fields\Code;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Http\Requests\NovaRequest;
use Laravel\Nova\Panel;

class GirlsInDigitalPage extends Resource
{
public static $group = 'Content';

public static $model = \App\GirlsInDigitalPage::class;

public static $title = 'id';

public static function label()
{
return 'Girls in Digital – Page content';
}

public static function singularLabel()
{
return 'Girls in Digital Page';
}

public static function authorizedToViewAny(Request $request): bool
{
return true;
}

public static function uriKey(): string
{
return 'girls-in-digital-page';
}

private static function localesSorted(): array
{
$locales = config('app.locales', ['en']);
if (is_string($locales)) {
$locales = array_map('trim', explode(',', $locales));
}
$locales = array_values(array_filter($locales));
if (empty($locales)) {
$locales = ['en'];
}
sort($locales);
return $locales;
}

/** Content keys that can be overridden per locale (from resources/lang/xx/girls-in-digital.php). */
public static function contentKeys(): array
{
return [
'landing_header',
'about_girls_title',
'about_girls_description_1',
'about_girls_description_2',
'resource_title',
'resource_person_title',
'resource_person_description_1',
'resource_person_description_2',
'resource_educator_title',
'resource_educator_description',
'resource_search_activity',
'resource_organise_activity',
'resource_digital_activity',
'resource_social_media',
];
}

public function fields(Request $request): array
{
$locales = self::localesSorted();
$keysHelp = 'Optional keys: ' . implode(', ', self::contentKeys());

$localePanels = [];
foreach ($locales as $locale) {
$localePanels[] = new Panel('Override: ' . strtoupper($locale), [
Code::make('[' . $locale . ']', 'locale_override_' . $locale)
->json()
->nullable()
->help($keysHelp)
->resolveUsing(function () use ($locale) {
$overrides = $this->resource->locale_overrides ?? [];
$data = $overrides[$locale] ?? [];
return $data;
})
->fillUsing(function ($request, $model, $attribute, $requestAttribute) {
$locale = str_replace('locale_override_', '', $attribute);
$value = $request->get($requestAttribute);
$overrides = $model->locale_overrides ?? [];
$overrides[$locale] = is_string($value) ? (json_decode($value, true) ?? []) : (is_array($value) ? $value : []);
$model->locale_overrides = $overrides;
}),
]);
}

return [
ID::make()->onlyOnForms(),
new Panel('Per-locale content overrides (optional)', [
\Laravel\Nova\Fields\Heading::make('Expand a locale below to override text for that language. Defaults come from resources/lang/{locale}/girls-in-digital.php.'),
...$localePanels,
]),
];
}
}
2 changes: 2 additions & 0 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ function ($view) {
$view->with('active_countries', \App\Country::withEvents());
});

View::composer('static.girls-in-digital-week', \App\Http\View\Composers\GirlsInDigitalComposer::class);

/**
* Paginate a standard Laravel Collection.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
public function up(): void
{
Schema::create('girls_in_digital_buttons', function (Blueprint $table) {
$table->id();
$table->string('key')->unique();
$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();
});
}

public function down(): void
{
Schema::dropIfExists('girls_in_digital_buttons');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
public function up(): void
{
Schema::create('girls_in_digital_page', function (Blueprint $table) {
$table->id();
$table->json('locale_overrides')->nullable();
$table->timestamps();
});
DB::table('girls_in_digital_page')->insert(['locale_overrides' => null, 'created_at' => now(), 'updated_at' => now()]);
}

public function down(): void
{
Schema::dropIfExists('girls_in_digital_page');
}
};
36 changes: 36 additions & 0 deletions database/seeders/GirlsInDigitalButtonSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Database\Seeders;

use App\GirlsInDigitalButton;
use Illuminate\Database\Seeder;

class GirlsInDigitalButtonSeeder extends Seeder
{
public function run(): void
{
$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 => $row) {
GirlsInDigitalButton::updateOrCreate(
['key' => $row['key']],
[
'label' => $row['label'],
'url' => $row['url'],
'open_new_tab' => $row['open_new_tab'],
'enabled' => true,
'position' => $row['position'],
]
);
}
}
}
Loading
Loading