]> git.localhorst.tv Git - alttp.git/blob - app/Http/Controllers/SitemapXmlController.php
4393a30c0f88cdc0ecd6ff80587cf9fb529d74dd
[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                 foreach (['lw', 'dw', 'sp', 'uw'] as $map) {
27                         $tech = TechniqueMap::where('map', '=', $map)->latest()->first();
28                         $url = new SitemapUrl();
29                         $url->path = '/map/'.$map;
30                         if ($tech) {
31                                 $url->lastmod = $tech->created_at;
32                         }
33                         $url->changefreq = 'monthly';
34                         $url->priority = 0.9;
35                         $urls[] = $url;
36                 }
37
38                 $url = new SitemapUrl();
39                 $url->path = '/tech';
40                 $url->lastmod = Technique::where('type', '=', 'tech')->where('index', true)->latest()->first()->created_at;
41                 $url->changefreq = 'monthly';
42                 $url->priority = 0.8;
43                 $urls[] = $url;
44
45                 foreach (Technique::where('type', '=', 'tech')->where('index', true)->get() as $tech) {
46                         $url = new SitemapUrl();
47                         $url->path = '/tech/'.rawurlencode($tech->name);
48                         $url->lastmod = $tech->updated_at ? $tech->updated_at : ($tech->created_at ? $tech->created_at : now());
49                         $url->changefreq = 'never';
50                         $url->priority = $tech->priority;
51                         $urls[] = $url;
52                 }
53
54                 return response()->view('sitemap', [
55                         'urls' => $urls,
56                 ])->header('Content-Type', 'text/xml');
57         }
58
59 }