Commit workspace changes
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
<?php
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\ArtworkContributor;
|
||||
use App\Models\Group;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
@@ -26,6 +28,9 @@ class Artwork extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes, Searchable;
|
||||
|
||||
public const PUBLISHED_AS_USER = 'user';
|
||||
public const PUBLISHED_AS_GROUP = 'group';
|
||||
|
||||
public const VISIBILITY_PUBLIC = 'public';
|
||||
public const VISIBILITY_UNLISTED = 'unlisted';
|
||||
public const VISIBILITY_PRIVATE = 'private';
|
||||
@@ -34,6 +39,11 @@ class Artwork extends Model
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'group_id',
|
||||
'uploaded_by_user_id',
|
||||
'primary_author_user_id',
|
||||
'published_as_type',
|
||||
'published_as_id',
|
||||
'title',
|
||||
'slug',
|
||||
'description',
|
||||
@@ -81,6 +91,8 @@ class Artwork extends Model
|
||||
'is_approved' => 'boolean',
|
||||
'is_mature' => 'boolean',
|
||||
'published_at' => 'datetime',
|
||||
'published_as_type' => 'string',
|
||||
'published_as_id' => 'integer',
|
||||
'publish_at' => 'datetime',
|
||||
'clip_tags_json' => 'array',
|
||||
'yolo_objects_json' => 'array',
|
||||
@@ -167,6 +179,51 @@ class Artwork extends Model
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function group(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Group::class);
|
||||
}
|
||||
|
||||
public function uploadedBy(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'uploaded_by_user_id');
|
||||
}
|
||||
|
||||
public function primaryAuthor(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'primary_author_user_id');
|
||||
}
|
||||
|
||||
public function contributors(): HasMany
|
||||
{
|
||||
return $this->hasMany(ArtworkContributor::class)->orderBy('sort_order');
|
||||
}
|
||||
|
||||
public function isPublishedByGroup(): bool
|
||||
{
|
||||
return $this->publishedAsType() === self::PUBLISHED_AS_GROUP;
|
||||
}
|
||||
|
||||
public function publishedAsType(): string
|
||||
{
|
||||
if (in_array($this->published_as_type, [self::PUBLISHED_AS_USER, self::PUBLISHED_AS_GROUP], true)) {
|
||||
return (string) $this->published_as_type;
|
||||
}
|
||||
|
||||
return (int) ($this->group_id ?? 0) > 0 ? self::PUBLISHED_AS_GROUP : self::PUBLISHED_AS_USER;
|
||||
}
|
||||
|
||||
public function publishedAsId(): int
|
||||
{
|
||||
if ((int) ($this->published_as_id ?? 0) > 0) {
|
||||
return (int) $this->published_as_id;
|
||||
}
|
||||
|
||||
return $this->publishedAsType() === self::PUBLISHED_AS_GROUP
|
||||
? (int) ($this->group_id ?? 0)
|
||||
: (int) $this->user_id;
|
||||
}
|
||||
|
||||
public function translations(): HasMany
|
||||
{
|
||||
return $this->hasMany(ArtworkTranslation::class);
|
||||
@@ -268,7 +325,7 @@ class Artwork extends Model
|
||||
*/
|
||||
public function toSearchableArray(): array
|
||||
{
|
||||
$this->loadMissing(['user', 'tags', 'categories.contentType', 'stats', 'awardStat']);
|
||||
$this->loadMissing(['user', 'group', 'tags', 'categories.contentType', 'stats', 'awardStat']);
|
||||
|
||||
$stat = $this->stats;
|
||||
$awardStat = $this->awardStat;
|
||||
@@ -301,8 +358,9 @@ class Artwork extends Model
|
||||
'slug' => $this->slug,
|
||||
'title' => $this->title,
|
||||
'description' => (string) ($this->description ?? ''),
|
||||
'author_id' => $this->user_id,
|
||||
'author_name' => $this->user?->name ?? 'Skinbase',
|
||||
'author_id' => $this->publishedAsId(),
|
||||
'author_name' => $this->group?->name ?? $this->user?->name ?? 'Skinbase',
|
||||
'published_as_type' => $this->publishedAsType(),
|
||||
'category' => $category,
|
||||
'content_type' => $content_type,
|
||||
'tags' => $tags,
|
||||
|
||||
Reference in New Issue
Block a user