File: D:/HostingSpaces/stafa/stafa.nl/app/Komma/Departments/DepartmentController.php
<?php
namespace App\Komma\Departments;
use App\Komma\Base\Controller;
use App\Komma\Components\ComponentService;
use App\Komma\Departments\Models\Department;
final class DepartmentController extends Controller
{
private $departmentService;
private $departmentPaginationKey = 'departmentPagination';
public function __construct(DepartmentService $departmentService)
{
parent::__construct();
$this->departmentService = $departmentService;
}
/**
* @return \Illuminate\Contracts\View\View
*/
public function index()
{
// If you don't know the code_name get page through given page id through request
// $page = $this->pageService->getPage(request()->get('page_id'));
$page = $this->links->departments->node;
$departments = $this->departmentService->getDepartmentsPaginated();
$departments->withPath($this->links->departments->route);
// Make language menu for given page
$languageMenu = $this->pageService->makeLanguageSwitchForPage($this->links->departments, $this->links->home);
// Return view
return view('site.templates.departments_index',[
'page' => $page,
'links' => $this->links,
'languageMenu' => $languageMenu,
'departments' => $departments,
]);
}
/**
* @return \Illuminate\Contracts\View\View
*/
public function filters()
{
$filters = request('filters');
dd('customize filter function in DepartmentController');
// if (sizeof($filters) != 1) {
// throw abort(404);
// }
// $categoryName = $filters[0];
//
// // Check if category exist else trow 404
// if ( ! $category = DepartmentCategoryTranslation::where('slug', $categoryName)
// ->with('translatable')
// ->first()) {
// throw abort(404);
// }
//
// $page = $this->pageService->getPageByCodeName('blog');
// $otherLanguageRoutes = $this->languageService->getOtherLanguagesRoutes($page);
//
// //Get departments through the category
// $departments = $category->translatable->departments()->paginate(8);
// $departments->withPath('/' . $this->links->blog->route . '/' . $category->slug);
//
//
// // Return view
// return view($this->baseViewPath.$this->pagePrefix.'index',[
// 'page' => $page,
// 'links' => $this->links,
// 'otherLanguages' => $otherLanguageRoutes,
// 'departments' => $departments,
// ]);
}
/**
* @param Department $department
* @return \Illuminate\Contracts\View\View
*/
public function show(Department $department)
{
$department->load('translation','translations', 'sites');
// This checks if the department belongs to the set site
if(! $department->sites->contains($this->site)) throw abort(404);
$componentService = app(ComponentService::class);
$components = $componentService->getViewComponents($department->translation);
$departments = $this->departmentService->getDepartmentsPaginated();
$departments->withPath($this->links->departments->route);
$nextDepartments = $this->departmentService->getNextDepartments($department);
// If we don't have any next departments, we manually add the latest one
if($nextDepartments->count() == 0) {
$latestDepartment = $this->departmentService->getLastDepartment();
view()->share('latestDepartment', $latestDepartment);
}
$page = $this->links->departments->node;
// Make language menu for given page
$languageMenu = $this->pageService->makeLanguageSwitchForPage($this->links->departments, $this->links->home);
$previousRoute = $this->createPreviousRoute($this->departmentPaginationKey, $this->links->departments->route);
// Return view
return view('site.templates.departments_show',[
'components' => $components,
'page' => $page,
'department' => $department,
'departments' => $departments,
'nextDepartments' => $nextDepartments,
'links' => $this->links,
'languageMenu' => $languageMenu,
'previousRoute' => $previousRoute
]);
}
}