Completed
Push — master ( 4f00d5...2afce4 )
by John
29s queued 13s
created

SiteMap   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 23
c 1
b 0
f 0
dl 0
loc 37
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A generate() 0 35 4
1
<?php
2
3
namespace App\Models\Eloquent\Tool;
4
5
use App\Models\Eloquent\Problem;
6
use App\Models\Eloquent\Contest;
7
use App\Models\Eloquent\Group;
8
use Carbon;
9
use App;
10
11
class SiteMap
12
{
13
    public static function generate()
14
    {
15
        $sitemap=App::make("sitemap");
16
17
        $sitemap->add(route('home'), Carbon::now(), '1.0', 'daily');
18
        $sitemap->add(route('problem.index'), Carbon::now(), '1.0', 'daily');
19
        $sitemap->add(route("status.index"), Carbon::now(), '1.0', 'daily');
20
        $sitemap->add(route("contest.index"), Carbon::now(), '1.0', 'daily');
21
        $sitemap->add(route("group.index"), Carbon::now(), '1.0', 'daily');
22
23
        Problem::chunk(200, function($problems) use ($sitemap) {
24
            foreach ($problems as $problem) {
25
                $sitemap->add(route('problem.detail', [
26
                    'pcode' => $problem->pcode
27
                ]), Carbon::parse($problem->update_date), '0.8', 'monthly');
28
            }
29
        });
30
31
        Contest::where(["public" => 1, "audit_status" => 1])->chunk(200, function($contests) use ($sitemap) {
32
            foreach ($contests as $contest) {
33
                $sitemap->add(route('contest.detail', [
34
                    'cid' => $contest->cid
35
                ]), Carbon::parse($contest->created_at), '0.8', 'monthly');
36
            }
37
        });
38
39
        Group::where(["public" => 1])->chunk(200, function($groups) use ($sitemap) {
40
            foreach ($groups as $group) {
41
                $sitemap->add(route('group.detail', [
42
                    'gcode' => $group->gcode
43
                ]), Carbon::parse($group->created_at), '0.8', 'monthly');
44
            }
45
        });
46
47
        $sitemap->store('xml', 'sitemap');
48
    }
49
}
50