-
Notifications
You must be signed in to change notification settings - Fork 145
Expand file tree
/
Copy pathWidgetAllProjectsController.php
More file actions
147 lines (119 loc) · 4.12 KB
/
Copy pathWidgetAllProjectsController.php
File metadata and controls
147 lines (119 loc) · 4.12 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
declare(strict_types=1);
namespace PHPCensor\Controller;
use Exception;
use PHPCensor\Exception\HttpException;
use Symfony\Component\HttpFoundation\Response;
use PHPCensor\Model\Build;
use PHPCensor\Model\Project;
use PHPCensor\Store\BuildStore;
use PHPCensor\Store\ProjectGroupStore;
use PHPCensor\Store\ProjectStore;
use PHPCensor\View;
use PHPCensor\WebController;
/**
* @package PHP Censor
* @subpackage Application
*
* @author Dmitry Khomutov <poisoncorpsee@gmail.com>
*/
class WidgetAllProjectsController extends WebController
{
protected BuildStore $buildStore;
protected ProjectStore $projectStore;
protected ProjectGroupStore $groupStore;
/**
* Initialise the controller, set up stores and services.
*/
public function init(): void
{
parent::init();
$this->buildStore = $this->storeRegistry->get('Build');
$this->projectStore = $this->storeRegistry->get('Project');
$this->groupStore = $this->storeRegistry->get('ProjectGroup');
}
/**
* @throws Exception
*/
public function index(): Response
{
$this->view->groups = $this->getGroupInfo();
$response = new Response();
$response->setContent($this->view->render());
return $response;
}
/**
* Generate the HTML for the project overview section of the dashboard.
*
* @param Project[] $projects
*
* @throws Exception
*/
protected function getSummaryHtml(array $projects): string
{
$summaryBuilds = [];
$successes = [];
$failures = [];
$counts = [];
foreach ($projects as $project) {
$summaryBuilds[$project->getId()] = $this->buildStore->getLatestBuilds($project->getId());
$count = $this->buildStore->getWhere(
['project_id' => $project->getId()],
1,
0,
['id' => 'DESC']
);
$counts[$project->getId()] = $count['count'];
$success = $this->buildStore->getLastBuildByStatus($project->getId(), Build::STATUS_SUCCESS);
$failure = $this->buildStore->getLastBuildByStatus($project->getId(), Build::STATUS_FAILED);
$successes[$project->getId()] = $success;
$failures[$project->getId()] = $failure;
}
$view = new View('WidgetAllProjects/index-projects');
$view->projects = $projects;
$view->builds = $summaryBuilds;
$view->successful = $successes;
$view->failed = $failures;
$view->counts = $counts;
return $view->render();
}
/**
* Get a summary of the project groups we have, and what projects they have in them.
*
* @throws Exception
*/
protected function getGroupInfo(): array
{
$rtn = [];
$groups = $this->groupStore->getWhere([], 100, 0, ['title' => 'ASC']);
foreach ($groups['items'] as $group) {
$thisGroup = ['title' => $group->getTitle()];
$projects = $this->projectStore->getByGroupId($group->getId(), false);
$thisGroup['projects'] = $projects['items'];
$thisGroup['summary'] = $this->getSummaryHtml($thisGroup['projects']);
$rtn[] = $thisGroup;
}
return $rtn;
}
/**
* @throws HttpException
*/
public function update(int $projectId): Response
{
$count = $this->buildStore->getWhere(
['project_id' => $projectId],
1,
0,
['id' => 'DESC']
);
$counts = $count['count'];
$this->view->project = $this->projectStore->getById($projectId);
$this->view->builds = $this->buildStore->getLatestBuilds($projectId);
$this->view->successful = $this->buildStore->getLastBuildByStatus($projectId, Build::STATUS_SUCCESS);
$this->view->failed = $this->buildStore->getLastBuildByStatus($projectId, Build::STATUS_FAILED);
$this->view->counts = $counts;
$response = new Response();
$response->setContent($this->view->render());
return $response;
}
}