mirror of
https://github.com/Bigherollc/wticreatorstudio.git
synced 2026-07-31 14:16:57 -04:00
127 lines
3.3 KiB
PHP
127 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace Modules\Frontend\Services;
|
|
|
|
use Modules\Frontend\Entities\Section;
|
|
use Modules\Frontend\Entities\SectionCategory;
|
|
use Modules\Frontend\Entities\SectionItem;
|
|
use Modules\Frontend\Entities\SectionTranslation;
|
|
use Modules\Frontend\Facades\Videos;
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
class Sections
|
|
{
|
|
public function all()
|
|
{
|
|
$sections = Section::with('items.thumbnail', 'categories')->orderBy('order')->get();
|
|
|
|
return $sections;
|
|
}
|
|
|
|
public function getLead()
|
|
{
|
|
return Cache::remember('ott_section_leads', 60 * 60, function () {
|
|
return Section::active()->orderBy('order')->get();
|
|
});
|
|
}
|
|
|
|
public function getSectionItems($section)
|
|
{
|
|
$items = $section->items;
|
|
$items->load('thumbnail');
|
|
$categories = $section->categories;
|
|
|
|
if ($categories->count() > 0) {
|
|
$categoryItems = collect([]);
|
|
|
|
foreach ($categories as $category) {
|
|
$videos = Videos::getByCategory($category);
|
|
$categoryItems = $categoryItems->merge($videos);
|
|
}
|
|
|
|
$items = $items->merge($categoryItems);
|
|
}
|
|
|
|
return $items->toArray();
|
|
}
|
|
|
|
public function getSectionLeadItems($section)
|
|
{
|
|
$items = $section->items()->where('is_short', false)->get();
|
|
$items->load('thumbnail');
|
|
$categories = $section->categories->pluck('id');
|
|
|
|
$videos = Videos::getByCategories($categories, 8);
|
|
$items = $items->merge($videos);
|
|
|
|
return $items->toArray();
|
|
}
|
|
|
|
public function lazyLoadSectionItems($section, $skipped)
|
|
{
|
|
$items = $section->items()->where('is_short', false)->get();
|
|
$items = collect([]);
|
|
$categories = $section->categories->pluck('id');
|
|
|
|
$videos = Videos::getByCategories($categories, 8, $skipped - $items->count());
|
|
$items = $items->merge($videos);
|
|
|
|
return $items->toArray();
|
|
}
|
|
|
|
public function updateSectionItems($section, $items)
|
|
{
|
|
SectionItem::where('section_id', $section->id)->delete();
|
|
|
|
foreach ($items as $item) {
|
|
SectionItem::create([
|
|
'section_id' => $section->id,
|
|
'video_id' => $item,
|
|
]);
|
|
}
|
|
|
|
Cache::forget('ott_section_leads');
|
|
}
|
|
|
|
public function updateSectionCategories($section, $items)
|
|
{
|
|
SectionCategory::where('section_id', $section->id)->delete();
|
|
|
|
foreach ($items as $item) {
|
|
SectionCategory::create([
|
|
'section_id' => $section->id,
|
|
'category_id' => $item,
|
|
]);
|
|
}
|
|
|
|
Cache::forget('ott_section_leads');
|
|
}
|
|
|
|
public function updateSectionTranslations($section, $items)
|
|
{
|
|
SectionTranslation::where('section_id', $section->id)->delete();
|
|
|
|
foreach ($items as $item) {
|
|
$item = (object) $item;
|
|
|
|
SectionTranslation::create([
|
|
'section_id' => $section->id,
|
|
'title' => $item->title,
|
|
'code' => $item->code,
|
|
]);
|
|
}
|
|
|
|
Cache::forget('ott_section_leads');
|
|
}
|
|
|
|
public function updateSectionStatus($section, $state)
|
|
{
|
|
$section->active = $state;
|
|
$section->update();
|
|
|
|
Cache::forget('ott_section_leads');
|
|
|
|
return $section;
|
|
}
|
|
}
|