Skip to content

Commit

Permalink
cosmetic and migration
Browse files Browse the repository at this point in the history
  • Loading branch information
bastihilger committed Feb 11, 2022
1 parent 7cec8bd commit 4a80a46
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ public function up()
});

Schema::create($prefix.'artist_discipline', function (Blueprint $table) {
$table->id('doid');
$table->unsignedBigInteger('artist_id');
$table->unsignedBigInteger('discipline_id');
$table->unsignedBigInteger('work_id')->nullable();
$table->primary(['artist_id', 'discipline_id']);
$table->index(['artist_id', 'discipline_id']);
});

Schema::create($prefix.'categories', function (Blueprint $table) {
Expand All @@ -68,25 +69,27 @@ public function up()
$table->integer('sort_order')->nullable();
$table->json('description')->nullable();
$table->json('slides')->nullable();

$table->json('meta_description')->nullable();
$table->json('browser_title')->nullable();
$table->json('robots')->nullable();
$table->unsignedInteger('og_image')->nullable();

$table->timestamps();
});

Schema::create($prefix.'category_slideshow', function (Blueprint $table) {
$table->id('doid');
$table->unsignedBigInteger('category_id');
$table->unsignedBigInteger('slideshow_id');
$table->primary(['category_id', 'slideshow_id']);
$table->index(['category_id', 'slideshow_id']);
});

Schema::create($prefix.'category_overview_work', function (Blueprint $table) {
$table->id('doid');
$table->unsignedBigInteger('category_id');
$table->unsignedBigInteger('work_id');
$table->primary(['category_id', 'work_id']);
$table->index(['category_id', 'work_id']);
});

Schema::create($prefix.'works', function (Blueprint $table) use ($prefix) {
Expand Down
23 changes: 10 additions & 13 deletions src/Models/Artist.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Spatie\Translatable\HasTranslations;
use Kraenkvisuell\NovaCmsPortfolio\Factories\ArtistFactory;
use Spatie\Translatable\HasTranslations;

class Artist extends Model
{
use HasFactory;
use HasTranslations;

protected $guarded = [];

public function getTable()
Expand Down Expand Up @@ -71,12 +71,12 @@ public function portfolioImage()

if ($this->works->count()) {
$markedWork = $this->works->where('is_artist_portfolio_image', true)->first();
if (!$markedWork) {

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

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

Expand All @@ -85,7 +85,6 @@ public function portfolioImage()
}
}

return null;
}

public function categoriesForDiscipline($disciplineId)
Expand All @@ -94,7 +93,7 @@ public function categoriesForDiscipline($disciplineId)

if ($disciplineId) {
$slidewhows = $slidewhows->filter(function ($slideshow) use ($disciplineId) {
return !$slideshow->disciplines
return ! $slideshow->disciplines
|| $slideshow->disciplines->pluck('id')->contains($disciplineId);
});
}
Expand All @@ -106,7 +105,7 @@ public function categoriesForDiscipline($disciplineId)
$categories->push($category);
}
}

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

Expand All @@ -125,7 +124,7 @@ public function workForDiscipline($disciplineId)
->has('works')
->first();

if (!$slideshow) {
if (! $slideshow) {
$slideshow = $this->slideshows()
->has('works')
->first();
Expand All @@ -136,10 +135,10 @@ public function workForDiscipline($disciplineId)
->where('show_in_overview', true)
->first();

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

return $markedWork;
}

Expand Down Expand Up @@ -181,8 +180,6 @@ public function worksForCategory($categoryId, $disciplineId)
});
})->limit(2)->get();



return $works;
}
}
12 changes: 6 additions & 6 deletions src/Nova/Actions/ToggleRepresentsArtistInCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace Kraenkvisuell\NovaCmsPortfolio\Nova\Actions;

use Laravel\Nova\Actions\Action;
use Illuminate\Support\Collection;
use Laravel\Nova\Fields\ActionFields;
use Kraenkvisuell\NovaCmsPortfolio\Models\Category;
use Laravel\Nova\Actions\Action;
use Laravel\Nova\Fields\ActionFields;

class ToggleRepresentsArtistInCategory extends Action
{
Expand All @@ -19,23 +19,23 @@ public function __construct($categoryId)
public function name()
{
$category = Category::find($this->categoryId);

return __('nova-cms-portfolio::works.toggle_represents_artist_in_discipline_category').': '.$category->title;
}

public function handle(ActionFields $fields, Collection $models)
{
$work = $models->first();
ray($work);

$discipline = $work->slideshow->artist->disciplines->first();
$categories = $work->represents_artist_in_discipline_category;
$categoryId = $discipline->id.'_'.$this->categoryId;

if (!$categories) {
if (! $categories) {
$categories = [];
}


if (!isset($categories[$categoryId])) {
if (! isset($categories[$categoryId])) {
$categories[$categoryId] = true;
} else {
$categories[$categoryId] = ! $categories[$categoryId];
Expand Down

0 comments on commit 4a80a46

Please sign in to comment.