Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
bastihilger committed May 20, 2021
1 parent 8929855 commit 04c13bd
Show file tree
Hide file tree
Showing 7 changed files with 214 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

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

return new class extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
$prefix = config('nova-cms-portfolio.db_prefix');

Schema::table($prefix.'slideshows', function (Blueprint $table) {
$table->unsignedBigInteger('discipline_id')->nullable();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
$prefix = config('nova-cms-portfolio.db_prefix');

Schema::table($prefix.'slideshows', function (Blueprint $table) {
$table->dropColumn('discipline_id');
});
}
};
35 changes: 35 additions & 0 deletions database/migrations/2021_05_19_000000_add_relations_to_works.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

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

return new class extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
$prefix = config('nova-cms-portfolio.db_prefix');

Schema::table($prefix.'works', function (Blueprint $table) {
$table->json('represents_artist_in_discipline')->nullable();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
$prefix = config('nova-cms-portfolio.db_prefix');

Schema::table($prefix.'works', function (Blueprint $table) {
$table->dropColumn('represents_artist_in_discipline');
});
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

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

return new class extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
$prefix = config('nova-cms-portfolio.db_prefix');

Schema::table($prefix.'works', function (Blueprint $table) {
$table->json('represents_artist_in_discipline_category')->nullable();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
$prefix = config('nova-cms-portfolio.db_prefix');

Schema::table($prefix.'works', function (Blueprint $table) {
$table->dropColumn('represents_artist_in_discipline_category');
});
}
};
2 changes: 2 additions & 0 deletions resources/lang/nova-cms-portfolio/de/works.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
return [
'caption' => 'Caption',
'is_artist_portfolio_image' => 'Ist Künstler-Portfolio-Bild',
'represents_artist_in_discipline' => 'Repräsentiert Künstler in Disziplin',
'represents_artist_in_discipline_category' => 'Repräsentiert Künstler in Kategorie',
'title' => 'Titel',
'work' => 'Werk',
'works' => 'Werke',
Expand Down
76 changes: 76 additions & 0 deletions src/Models/Artist.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,80 @@ public function categoriesForDiscipline($disciplineId)

return $categories->unique('id')->sortBy('title');
}

public function workForDiscipline($disciplineId)
{
$markedWork = $this->works()
->where('represents_artist_in_discipline->'.$disciplineId, true)
->first();

if ($markedWork) {
return $markedWork;
}

$slideshow = $this->slideshows()
->where('discipline_id', $disciplineId)
->has('works')
->first();

if (!$slideshow) {
$slideshow = $this->slideshows()
->has('works')
->first();
}

if ($slideshow) {
$markedWork = $slideshow->works()
->where('show_in_overview', true)
->first();

if (!$markedWork) {
$markedWork = $slideshow->works()->first();
}

return $markedWork;
}

return new Work();
}

public function workForDisciplineUrl($disciplineId)
{
$work = $this->workForDiscipline($disciplineId);

return $work && $work->file ? nova_cms_image($work->file) : null;
}

public function worksForCategory($categoryId, $disciplineId)
{
$works = $this->works()->whereHas('slideshow', function ($q) use ($categoryId, $disciplineId) {
$q->where(function ($q) use ($categoryId, $disciplineId) {
$q->whereNull('discipline_id')
->orWhere('discipline_id', $disciplineId);
})
->whereHas('categories', function ($q) use ($categoryId) {
$q->where('id', $categoryId);
});
})
->where('represents_artist_in_discipline_category->'.$disciplineId.'_'.$categoryId, true)
->get();

if ($works->count()) {
return $works;
}

$works = $this->works()->whereHas('slideshow', function ($q) use ($categoryId, $disciplineId) {
$q->where(function ($q) use ($disciplineId) {
$q->whereNull('discipline_id')
->orWhere('discipline_id', $disciplineId);
})
->whereHas('categories', function ($q) use ($categoryId) {
$q->where('id', $categoryId);
});
})->limit(2)->get();



return $works;
}
}
5 changes: 5 additions & 0 deletions src/Models/Work.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ class Work extends Model implements Sortable
'sort_when_creating' => true,
'sort_on_has_many' => true,
];

protected $casts = [
'represents_artist_in_discipline' => 'array',
'represents_artist_in_discipline_category' => 'array',
];

protected $guarded = [];

Expand Down
26 changes: 26 additions & 0 deletions src/Nova/Work.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Laravel\Nova\Http\Requests\NovaRequest;
use Kraenkvisuell\NovaCmsMedia\MediaLibrary;
use Laravel\Nova\Fields\Boolean;
use Laravel\Nova\Fields\BooleanGroup;
use OptimistDigital\NovaSortable\Traits\HasSortableRows;

class Work extends Resource
Expand Down Expand Up @@ -54,6 +55,31 @@ public function fields(Request $request)
Text::make(__('nova-cms::pages.title'), 'title'),

Boolean::make(__('nova-cms-portfolio::works.is_artist_portfolio_image'), 'is_artist_portfolio_image'),

BooleanGroup::make(
__('nova-cms-portfolio::works.represents_artist_in_discipline'),
'represents_artist_in_discipline'
)
->options(function () {
return optional(optional(optional($this->slideshow)->artist)->disciplines)->pluck('title', 'id');
})
->onlyOnForms(),

BooleanGroup::make(
__('nova-cms-portfolio::works.represents_artist_in_discipline_category'),
'represents_artist_in_discipline_category'
)
->options(function () {
$disciplineId = optional(optional($this->slideshow)->getDiscipline())->id;
$options = [];

foreach (optional($this->slideshow)->categories ?: [] as $category) {
$options[$disciplineId.'_'.$category->id] = $category->title;
}

return $options;
})
->onlyOnForms(),
];
}

Expand Down

0 comments on commit 04c13bd

Please sign in to comment.