Migration complete
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Entry;
|
||||
use App\Models\EntryReview;
|
||||
use App\Models\News;
|
||||
use App\View\Components\EntryCard;
|
||||
use Illuminate\Support\Carbon;
|
||||
@@ -17,9 +18,10 @@ class ActivityService
|
||||
private const CACHE_MESSAGES = 300; // seconds.
|
||||
private const CACHE_THREADS = 300; // seconds.
|
||||
private const CACHE_CLUBS = 300; // seconds.
|
||||
private const CACHE_REVIEWS = 300; // seconds.
|
||||
private const ITEMS_PER_TYPE = 15;
|
||||
|
||||
public function getActivities( array $activities = [ 'entries', 'news', 'messages', 'threads', 'clubs' ] ): Collection
|
||||
public function getActivities( array $activities = [ 'entries', 'news', 'messages', 'threads', 'clubs', 'reviews' ] ): Collection
|
||||
{
|
||||
$c = collect();
|
||||
if( in_array( 'entries', $activities ) ) {
|
||||
@@ -37,6 +39,9 @@ class ActivityService
|
||||
if( in_array( 'clubs', $activities ) ) {
|
||||
$c = $c->merge($this->getClubs());
|
||||
}
|
||||
if( in_array( 'reviews', $activities ) ) {
|
||||
$c = $c->merge($this->getReviews());
|
||||
}
|
||||
|
||||
return $c->sortByDesc('date')
|
||||
->values()
|
||||
@@ -135,6 +140,23 @@ class ActivityService
|
||||
];
|
||||
}
|
||||
|
||||
private function formatReview( EntryReview $review ): array
|
||||
{
|
||||
return [
|
||||
'type' => 'review',
|
||||
'title' => $review->title,
|
||||
'url' => $review->entry()->exists() ? route('entries.show', ['section' => $review->entry->type, 'entry' => $review->entry]) : '',
|
||||
'image' => null,
|
||||
'date' => $review->created_at->timestamp,
|
||||
'author' => null,
|
||||
'user_id' => $review->user_id,
|
||||
'badge' => 'Review',
|
||||
'badge_class' => 'review',
|
||||
'excerpt' => $review->description ? \Str::limit(strip_tags($review->description), 80) : null,
|
||||
'meta' => $review->entry()->exists() ? ( $review->entry->complete_title ?? $review->entry->title ) : null,
|
||||
];
|
||||
}
|
||||
|
||||
private function getEntries(): array
|
||||
{
|
||||
return Cache::remember('activity_entries', self::CACHE_ENTRIES, function() {
|
||||
@@ -220,4 +242,16 @@ class ActivityService
|
||||
->toArray();
|
||||
});
|
||||
}
|
||||
|
||||
private function getReviews(): array
|
||||
{
|
||||
return Cache::remember('activity_reviews', self::CACHE_REVIEWS, function() {
|
||||
return EntryReview::with(['entry'])
|
||||
->latest('created_at')
|
||||
->limit(self::ITEMS_PER_TYPE)
|
||||
->get()
|
||||
->map($this->formatReview(...))
|
||||
->toArray();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user