UpdateSiteProposals.php 3.6 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php

namespace App\Console\Commands;

use App\Project;
use Illuminate\Console\Command;
use stdClass;
use Symfony\Component\Yaml\Yaml;

class UpdateSiteProposals extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'ffs:update';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Update the files required for jeykll site';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     */
    public function handle()
    {
41
42
43
44
45
46
47
        $response = [
            $this->ideaProposals(),
            $this->fundingRequiredProposals(),
            $this->workInProgressProposals(),
        ];
        $json = json_encode($response, JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT);
        \Storage::put('new.json', $json);
48
49
    }

50
    public function ideaProposals()
51
    {
52
53
        $group = new stdClass();
        $group->stage = 'Ideas';
54
        $responseProposals = [];
55
        $proposals = Project::where('gitlab_state', 'opened')->where('state', 'IDEA')->get();
56
57
58
59
60
61
62
63
        foreach ($proposals as $proposal) {
            $prop = new stdClass();
            $prop->name = $proposal->title;
            $prop->{'gitlab-url'} = $proposal->gitlab_url;
            $prop->author = $proposal->gitlab_username;
            $prop->date = $proposal->gitlab_created_at->format('F j, Y');
            $responseProposals[] = $prop;
        }
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
        $group->proposals = $responseProposals;
        return $group;
    }

    public function fundingRequiredProposals()
    {
        $group = new stdClass();
        $group->stage = 'Funding Required';
        $responseProposals = [];
        $proposals = Project::where('gitlab_state', 'merged')->where('state', 'FUNDING-REQUIRED')->get();
        foreach ($proposals as $proposal) {
            $prop = new stdClass();
            $prop->name = $proposal->title;
            $prop->{'gitlab-url'} = $proposal->gitlab_url;
            $prop->{'local-url'} = '#';
            $prop->{'donate-url'} = '#';
            $prop->percentage = 0;
            $prop->amount = $proposal->target_amount;
            $prop->{'amount-funded'} = $proposal->target_amount;
            $prop->author = $proposal->gitlab_username;
            $prop->date = $proposal->gitlab_created_at->format('F j, Y');
            $responseProposals[] = $prop;
        }
        $group->proposals = $responseProposals;
        return $group;
    }

    public function workInProgressProposals()
    {
        $group = new stdClass();
        $group->stage = 'Work in Progress';
        $responseProposals = [];
        $proposals = Project::where('gitlab_state', 'merged')->where('state', 'WORK-IN-PROGRESS')->get();
        foreach ($proposals as $proposal) {
            $prop = new stdClass();
            $prop->name = $proposal->title;
            $prop->{'gitlab-url'} = $proposal->gitlab_url;
            $prop->{'local-url'} = '#';
            $prop->milestones = 4;
            $prop->{'milestones-completed'} = 4;
            $prop->{'milestones-percentage'} = 100;
            $prop->percentage = 0;
            $prop->amount = $proposal->target_amount;
            $prop->{'amount-funded'} = $proposal->target_amount;
            $prop->author = $proposal->gitlab_username;
            $prop->date = $proposal->gitlab_created_at->format('F j, Y');
            $responseProposals[] = $prop;
        }
        $group->proposals = $responseProposals;
        return $group;

115
116
    }
}