File: D:/HostingSpaces/groendesignkoencox/groendesign-koencox.be/app/Sitemap/SitemapController.php
<?php
/**
* Created by PhpStorm.
* User: mike
* Date: 03/10/17
* Time: 15:24
*/
namespace App\Sitemap;
use App\Base\Controller;
use Illuminate\Support\Facades\Response;
final class SitemapController extends Controller
{
/**
* We only need the structure of the tree to get the pages
* The content of the pages we can get through the links
*
* @param null $language
* @return \Illuminate\Contracts\View\View|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function show($language = null)
{
// If $language isset and it doesn't match with the app getLocale redefine the application language by iso of $language
// it probably means that the route is changed by manually changing the route
if(isset($language) && $language !== \App::getLocale()){
\App::changeLanguageByIso2($language);
return \App::reload(); // Because the application has many language dependencies it better reload the whole application
}
$otherLanguages = [];
foreach ($this->site->languages as $siteLanguage){
$otherLanguages[$siteLanguage->id] = (object)[
'iso' => $siteLanguage->iso_2,
'route' => $siteLanguage->iso_2.'/sitemap'
];
}
return view('site.templates.sitemap',[
'page' => $this->site->pages()->where('lft', 1)->first(),
'links' => $this->links,
'otherLanguages' => $otherLanguages
]);
}
/**
* Generate the xml sitemap
* TODO: Test this when a website is finished
*
* @return mixed
*/
public function xml()
{
$sitemapService = new SitemapService();
$sitemap = $sitemapService->makeSitemap();
$xmlSitemap = $sitemap->render();
// If just return the rendered sitemap it will crash so we need to use the getContent
return $xmlSitemap->getContent();
}
}