File: D:/HostingSpaces/SBogers10/inzigd.komma.pro/app/Komma/Courses/CourseController.php
<?php
namespace App\Komma\Courses;
use App\Komma\Base\Controller;
use App\Komma\Components\ComponentService;
use App\Komma\Pages\Models\Page;
use App\Komma\Courses\Models\Course;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
final class CourseController extends Controller
{
private $courseService;
private $coursePaginationKey = 'coursePagination';
public function __construct(CourseService $courseService)
{
parent::__construct();
$this->courseService = $courseService;
}
/**
*
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function index()
{
$page = $this->pageService->getPage(request()->get('page_id'));
// Get the linker model
$linkerModel = $this->links->{$page->code_name};
// Get the page through the linker model
$page = $linkerModel->node;
$parent = $this->links->{$page->getParent()->code_name};
$parent->subnav = $this->pageService->getSubnav($parent->node, $this->links);
$courses = $this->courseService->getCoursesByCategoryPaginated($parent->node);
$courses->withPath($linkerModel->route);
$this->keepTrackOfPagination($this->coursePaginationKey);
$componentService = app(ComponentService::class);
$components = $componentService->getViewComponents($page->translation);
$preOverview = collect();
if ($components->count() != 0) {
$preOverview->push($components->shift());
}
// Return view
return view('site.templates.model_index', [
'indexType' => 'courses',
'page' => $page,
'parent' => $parent,
'links' => $this->links,
'models' => $courses,
'preOverview' => $preOverview,
'components' => $components,
]);
}
/**
* @param Course $course
* @return \Illuminate\Contracts\View\View
*/
public function show(Course $course)
{
// Load the needed relations
$course->load('translation', 'images');
$page = $this->pageService->getPage(request()->get('page_id'));
$parent = $this->links->{$page->getParent()->code_name};
// Get the linker model
$linkerModel = $this->links->{$page->code_name};
// Get the page through the linker model
$page = $linkerModel->node;
$componentService = app(ComponentService::class);
$components = $componentService->getViewComponents($course->translation);
// Create previous route for better navigation UX
$previousRoute = $this->createPreviousRoute($this->coursePaginationKey, $linkerModel->route);
// $otherCourses = $this->courseService->getNextCourses($course);
// Return view
return view('site.templates.model_show', [
'page' => $page,
'parent' => $parent,
'model' => $course,
'components' => $components,
'links' => $this->links,
'previousRoute' => $previousRoute,
'formRoute' => $this->links->interview->route,
'modelType' => 'courses'
]);
}
}