]> git.localhorst.tv Git - alttp.git/blob - app/Http/Controllers/SitemapXmlController.php
99e909212f2bbced0371e0b9c01f9f6ea9e00684
[alttp.git] / app / Http / Controllers / SitemapXmlController.php
1 <?php
2
3 namespace App\Http\Controllers;
4
5 use App\Models\SitemapUrl;
6 use App\Models\Technique;
7 use App\Models\TechniqueMap;
8 use App\Models\Tournament;
9 use Illuminate\Http\Request;
10
11 class SitemapXmlController extends Controller
12 {
13
14         public function index() {
15                 $urls = [];
16
17                 foreach (Tournament::all() as $tournament) {
18                         $url = new SitemapUrl();
19                         $url->path = '/tournaments/'.$tournament->id;
20                         $url->lastmod = $tournament->updated_at ? $tournament->updated_at : ($tournament->created_at ? $tournament->created_at : now());
21                         $url->changefreq = $tournament->locked ? 'never' : 'daily';
22                         $url->priority = $tournament->locked ? 0.5 : 1.0;
23                         $urls[] = $url;
24                 }
25
26                 $url = new SitemapUrl();
27                 $url->path = '/map';
28                 $url->lastmod = TechniqueMap::latest()->first()->created_at;
29                 $url->changefreq = 'monthly';
30                 $url->priority = 0.9;
31                 $urls[] = $url;
32
33                 $url = new SitemapUrl();
34                 $url->path = '/tech';
35                 $url->lastmod = Technique::where('type', '=', 'tech')->where('index', true)->latest()->first()->created_at;
36                 $url->changefreq = 'monthly';
37                 $url->priority = 0.8;
38                 $urls[] = $url;
39
40                 foreach (Technique::where('type', '=', 'tech')->where('index', true)->get() as $tech) {
41                         $url = new SitemapUrl();
42                         $url->path = '/tech/'.rawurlencode($tech->name);
43                         $url->lastmod = $tech->updated_at ? $tech->updated_at : ($tech->created_at ? $tech->created_at : now());
44                         $url->changefreq = 'never';
45                         $url->priority = $tech->priority;
46                         $urls[] = $url;
47                 }
48
49                 return response()->view('sitemap', [
50                         'urls' => $urls,
51                 ])->header('Content-Type', 'text/xml');
52         }
53
54 }