Migration complete
This commit is contained in:
@@ -4,12 +4,14 @@ namespace App\Models;
|
||||
|
||||
use App\Helpers\EntryHelpers;
|
||||
use App\Traits\HasGallery;
|
||||
use App\Traits\HasXenforoUserId;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use League\CommonMark\GithubFlavoredMarkdownConverter;
|
||||
use Monolog\Level;
|
||||
use Spatie\Activitylog\Models\Concerns\LogsActivity;
|
||||
use Spatie\Activitylog\Support\LogOptions;
|
||||
@@ -97,12 +99,17 @@ use Spatie\Activitylog\Support\LogOptions;
|
||||
* @method static Builder<static>|Entry withoutTrashed()
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \Spatie\Activitylog\Models\Activity> $activitiesAsSubject
|
||||
* @property-read int|null $activities_as_subject_count
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\EntryReview> $reviews
|
||||
* @property-read int|null $reviews_count
|
||||
* @property-read float $average_rating
|
||||
* @property-read int $reviews_count_cached
|
||||
* @property-read string $description_html
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
class Entry extends Model
|
||||
{
|
||||
|
||||
use SoftDeletes, HasGallery, LogsActivity;
|
||||
use SoftDeletes, HasGallery, LogsActivity, HasXenforoUserId;
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
@@ -143,6 +150,15 @@ class Entry extends Model
|
||||
'featured_at' => 'datetime',
|
||||
];
|
||||
|
||||
protected static function booted(): void {
|
||||
static::saving( function( $entry ) {
|
||||
if( $entry->isDirty('version') ) {
|
||||
$entry->created_at = now();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public function scopePublished( Builder $query ): Builder {
|
||||
return $query->where( 'state', 'published' );
|
||||
}
|
||||
@@ -207,6 +223,30 @@ class Entry extends Model
|
||||
return $this->hasMany(EntryHash::class);
|
||||
}
|
||||
|
||||
public function reviews(): HasMany {
|
||||
return $this->hasMany(EntryReview::class);
|
||||
}
|
||||
|
||||
public function getAverageRatingAttribute(): float
|
||||
{
|
||||
return round( $this->reviews->avg('rating') ?? 0, 1 );
|
||||
}
|
||||
|
||||
public function getReviewsCountCachedAttribute(): int
|
||||
{
|
||||
return $this->reviews->count();
|
||||
}
|
||||
|
||||
public function getDescriptionHtmlAttribute(): string
|
||||
{
|
||||
$converter = new GithubFlavoredMarkdownConverter([
|
||||
'html_input' => 'strip',
|
||||
'allow_unsafe_links' => false,
|
||||
]);
|
||||
|
||||
return $converter->convert($this->description)->getContent();
|
||||
}
|
||||
|
||||
public function parseStaffCredits(): ?array {
|
||||
return json_decode( $this->staff_credits ?? "", true );
|
||||
}
|
||||
|
||||
63
app/Models/EntryReview.php
Normal file
63
app/Models/EntryReview.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Traits\HasXenforoUserId;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Support\Str;
|
||||
use League\CommonMark\GithubFlavoredMarkdownConverter;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $entry_id
|
||||
* @property string $title
|
||||
* @property int $rating
|
||||
* @property string $description
|
||||
* @property string|null $deleted_at
|
||||
* @property \Illuminate\Support\Carbon|null $created_at
|
||||
* @property \Illuminate\Support\Carbon|null $updated_at
|
||||
* @property-read \App\Models\Entry|null $entry
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|EntryReview newModelQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|EntryReview newQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|EntryReview query()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|EntryReview whereCreatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|EntryReview whereDeletedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|EntryReview whereDescription($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|EntryReview whereEntryId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|EntryReview whereId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|EntryReview whereRating($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|EntryReview whereTitle($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|EntryReview whereUpdatedAt($value)
|
||||
* @property int $user_id
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|EntryReview whereUserId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|EntryReview onlyTrashed()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|EntryReview withTrashed(bool $withTrashed = true)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|EntryReview withoutTrashed()
|
||||
* @property-read string $description_html
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
class EntryReview extends Model
|
||||
{
|
||||
|
||||
use HasXenforoUserId, SoftDeletes;
|
||||
|
||||
protected $fillable = [ 'entry_id', 'title', 'rating', 'description', 'user_id' ];
|
||||
|
||||
public function entry(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Entry::class);
|
||||
}
|
||||
|
||||
public function getDescriptionHtmlAttribute(): string
|
||||
{
|
||||
$converter = new GithubFlavoredMarkdownConverter([
|
||||
'html_input' => 'strip',
|
||||
'allow_unsafe_links' => false,
|
||||
]);
|
||||
|
||||
return $converter->convert($this->description)->getContent();
|
||||
}
|
||||
|
||||
}
|
||||
53
app/Models/MigrationUserPlan.php
Normal file
53
app/Models/MigrationUserPlan.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|MigrationUserPlan newModelQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|MigrationUserPlan newQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|MigrationUserPlan query()
|
||||
* @property int $id
|
||||
* @property int|null $wp_user_id
|
||||
* @property int|null $xf_user_id
|
||||
* @property string $match_type
|
||||
* @property string|null $email
|
||||
* @property string|null $wp_username
|
||||
* @property string|null $xf_username
|
||||
* @property string|null $note
|
||||
* @property string $status
|
||||
* @property int|null $user_id
|
||||
* @property \Illuminate\Support\Carbon|null $created_at
|
||||
* @property \Illuminate\Support\Carbon|null $updated_at
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|MigrationUserPlan whereCreatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|MigrationUserPlan whereEmail($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|MigrationUserPlan whereId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|MigrationUserPlan whereMatchType($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|MigrationUserPlan whereNote($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|MigrationUserPlan whereStatus($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|MigrationUserPlan whereUpdatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|MigrationUserPlan whereUserId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|MigrationUserPlan whereWpUserId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|MigrationUserPlan whereWpUsername($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|MigrationUserPlan whereXfUserId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|MigrationUserPlan whereXfUsername($value)
|
||||
* @property int $wp_password_bridge
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|MigrationUserPlan whereWpPasswordBridge($value)
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
class MigrationUserPlan extends Model
|
||||
{
|
||||
protected $table = 'migration_user_plan';
|
||||
|
||||
protected $fillable = [
|
||||
'wp_user_id',
|
||||
'xf_user_id',
|
||||
'match_type',
|
||||
'email',
|
||||
'wp_username',
|
||||
'xf_username',
|
||||
'note',
|
||||
'status',
|
||||
];
|
||||
}
|
||||
@@ -4,10 +4,12 @@ namespace App\Models;
|
||||
|
||||
use App\Helpers\EntryHelpers;
|
||||
use App\Traits\HasGallery;
|
||||
use App\Traits\HasXenforoUserId;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use League\CommonMark\GithubFlavoredMarkdownConverter;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
@@ -59,7 +61,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
class News extends Model
|
||||
{
|
||||
|
||||
use SoftDeletes, HasGallery;
|
||||
use SoftDeletes, HasGallery, HasXenforoUserId;
|
||||
|
||||
protected $table = 'news';
|
||||
|
||||
@@ -108,6 +110,16 @@ class News extends Model
|
||||
return $this->belongsTo(Category::class);
|
||||
}
|
||||
|
||||
public function getDescriptionHtmlAttribute(): string
|
||||
{
|
||||
$converter = new GithubFlavoredMarkdownConverter([
|
||||
'html_input' => 'strip',
|
||||
'allow_unsafe_links' => false,
|
||||
]);
|
||||
|
||||
return $converter->convert($this->description)->getContent();
|
||||
}
|
||||
|
||||
public function getYoutubeVideoId(): ?string {
|
||||
if( !$this->youtube_link )
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user