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

namespace App;

use Illuminate\Database\Eloquent\Model;

class DreamJobRoleModel extends Model
{
protected $fillable = [
'first_name',
'last_name',
'slug',
'role',
'image',
'country',
'description1',
'description2',
'link',
'video',
'pathway_map_link',
'position',
'active',
];

protected $casts = [
'position' => 'integer',
'active' => 'boolean',
];
}
85 changes: 85 additions & 0 deletions app/DreamJobsPage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class DreamJobsPage extends Model
{
protected $table = 'dream_jobs_page';

protected $fillable = [
'hero_dynamic',
'about_dynamic',
'role_models_dynamic',
'resources_dynamic',
'hero_intro',
'hero_cta_text',
'hero_cta_link',
'about_title',
'about_description',
'about_video_url',
'role_models_title',
'resources_title',
'locale_overrides',
];

protected $casts = [
'hero_dynamic' => 'boolean',
'about_dynamic' => 'boolean',
'role_models_dynamic' => 'boolean',
'resources_dynamic' => 'boolean',
'locale_overrides' => 'array',
];

public function resources()
{
return $this->hasMany(DreamJobsResource::class, 'page_id')->orderBy('position');
}

public static function config(): self
{
$page = self::first();
if ($page) {
return $page;
}

return self::create([
'hero_dynamic' => false,
'about_dynamic' => false,
'role_models_dynamic' => false,
'resources_dynamic' => false,
'hero_cta_link' => '#dream-job-resources',
'about_video_url' => 'https://www.youtube.com/embed/pzP-kToeym4?si=FzutCQGW4rO5M_5A',
'locale_overrides' => null,
]);
}

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];
}

$value = $this->getAttribute($key);
return $value !== null ? (string) $value : '';
}

public function resourcesForLocale(?string $locale = null): array
{
return $this->resources()
->where('active', true)
->orderBy('position')
->get()
->map(fn (DreamJobsResource $item) => [
'title' => $item->titleForLocale($locale),
'description' => $item->descriptionForLocale($locale),
'button_text' => $item->buttonTextForLocale($locale),
'button_link' => $item->button_link,
'image' => $item->image,
])
->all();
}
}
66 changes: 66 additions & 0 deletions app/DreamJobsResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class DreamJobsResource extends Model
{
protected $table = 'dream_jobs_resources';

protected $fillable = [
'page_id',
'title',
'description',
'button_text',
'button_link',
'image',
'position',
'active',
'locale_overrides',
];

protected $casts = [
'position' => 'integer',
'active' => 'boolean',
'locale_overrides' => 'array',
];

public function page()
{
return $this->belongsTo(DreamJobsPage::class, 'page_id');
}

public function titleForLocale(?string $locale = null): string
{
$locale = $locale ?? app()->getLocale();
$overrides = $this->locale_overrides ?? [];
if (!empty($overrides[$locale]['title'])) {
return (string) $overrides[$locale]['title'];
}

return (string) ($this->title ?? '');
}

public function descriptionForLocale(?string $locale = null): string
{
$locale = $locale ?? app()->getLocale();
$overrides = $this->locale_overrides ?? [];
if (!empty($overrides[$locale]['description'])) {
return (string) $overrides[$locale]['description'];
}

return (string) ($this->description ?? '');
}

public function buttonTextForLocale(?string $locale = null): string
{
$locale = $locale ?? app()->getLocale();
$overrides = $this->locale_overrides ?? [];
if (!empty($overrides[$locale]['button_text'])) {
return (string) $overrides[$locale]['button_text'];
}

return (string) ($this->button_text ?? '');
}
}
60 changes: 60 additions & 0 deletions app/HackathonsPage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class HackathonsPage extends Model
{
protected $table = 'hackathons_page';

protected $fillable = [
'dynamic_content',
'hero_title',
'hero_subtitle',
'intro_title',
'intro_paragraph_1',
'intro_paragraph_2',
'details_title',
'details_paragraph_1',
'details_paragraph_2',
'details_paragraph_3',
'details_paragraph_4',
'video_url',
'recap_button_text',
'recap_button_link',
'toolkit_button_text',
'toolkit_button_link',
'locale_overrides',
];

protected $casts = [
'dynamic_content' => 'boolean',
'locale_overrides' => 'array',
];

public static function config(): self
{
$page = self::first();
if ($page) {
return $page;
}

return self::create([
'dynamic_content' => false,
'locale_overrides' => null,
]);
}

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];
}

$value = $this->getAttribute($key);
return $value !== null ? (string) $value : '';
}
}
80 changes: 80 additions & 0 deletions app/Nova/DreamJobRoleModel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?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\Fields\Textarea;
use Laravel\Nova\Http\Requests\NovaRequest;

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

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

public static $title = 'slug';

public static $search = [
'first_name',
'last_name',
'slug',
'role',
];

public static function label()
{
return 'Dream Jobs Role Models';
}

public static function singularLabel()
{
return 'Dream Jobs Role Model';
}

public function fields(Request $request): array
{
return [
ID::make()->sortable(),

Text::make('First Name', 'first_name')->rules('required', 'max:255'),
Text::make('Last Name', 'last_name')->rules('required', 'max:255'),
Text::make('Slug', 'slug')
->rules('required', 'max:255', 'unique:dream_job_role_models,slug,{{resourceId}}')
->help('Used in URL, e.g. anny-tubbs'),
Textarea::make('Role', 'role')->rules('required'),

Text::make('Image URL', 'image')
->rules('required', 'max:2048')
->help('Path from site root, e.g. /images/dream-jobs/anny-tubbs.png'),
Text::make('Country Code', 'country')
->rules('required', 'max:8')
->help('Flag code used by existing assets, e.g. be, fr, gr'),

Textarea::make('Description 1', 'description1')->nullable(),
Textarea::make('Description 2', 'description2')->nullable(),

Text::make('Profile Link', 'link')->nullable()->rules('nullable', 'max:2048'),
Text::make('Video Embed URL', 'video')->nullable()->rules('nullable', 'max:2048'),
Text::make('Pathway Map Filename', 'pathway_map_link')
->nullable()
->rules('nullable', 'max:255')
->help('Filename in /public/docs/dream-jobs/, e.g. Career Pathway Map Anny Tubbs.pdf'),

Number::make('Position', 'position')
->min(0)
->default(0)
->help('Lower numbers appear first.'),

Boolean::make('Active', 'active')->default(true),
];
}

public static function indexQuery(NovaRequest $request, $query)
{
return $query->orderBy('position')->orderBy('first_name');
}
}
Loading
Loading