mirror of
https://github.com/Bigherollc/wticreatorstudio.git
synced 2026-07-31 14:16:57 -04:00
53 lines
1.4 KiB
PHP
53 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Modules\Frontend\Services;
|
|
|
|
use Modules\Frontend\Entities\Creator;
|
|
use Modules\Frontend\Entities\FeaturedCreator;
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
class Creators
|
|
{
|
|
public function all()
|
|
{
|
|
$creators = Creator::with('role')->orderBy('first_name')->orderBy('last_name')->get();
|
|
|
|
return $creators;
|
|
}
|
|
|
|
public function getFeatured()
|
|
{
|
|
|
|
$featured_ids = Cache::remember('ott_featured_creator_ids', 60 * 60, function () {
|
|
return FeaturedCreator::get()->pluck('user_id');
|
|
});
|
|
$order_case = '';
|
|
|
|
foreach ($featured_ids as $index => $id) {
|
|
$order_case .= "WHEN '{$id}' THEN {$index} ";
|
|
}
|
|
|
|
if (!empty($order_case)) {
|
|
return Cache::remember('ott_featured_creators', 60 * 60, function () use($featured_ids,$order_case) {
|
|
return Creator::with('role', 'staff')->whereIn('id', $featured_ids)->orderByRaw("CASE id {$order_case} ELSE 9999 END")->get();
|
|
});
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public function updateFeatured($creators)
|
|
{
|
|
FeaturedCreator::destroy(FeaturedCreator::all()->pluck('id'));
|
|
|
|
foreach ($creators as $id) {
|
|
FeaturedCreator::create([
|
|
'user_id' => $id
|
|
]);
|
|
}
|
|
|
|
Cache::forget('ott_featured_creator_ids');
|
|
Cache::forget('ott_featured_creators');
|
|
}
|
|
}
|