-
Notifications
You must be signed in to change notification settings - Fork 145
Expand file tree
/
Copy pathWidgetAllProjectsController.php
More file actions
162 lines (135 loc) · 4.19 KB
/
Copy pathWidgetAllProjectsController.php
File metadata and controls
162 lines (135 loc) · 4.19 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
namespace PHPCensor\Controller;
use Exception;
use PHPCensor\Exception\HttpException;
use PHPCensor\Http\Response;
use PHPCensor\Model\Build;
use PHPCensor\Model\Project;
use PHPCensor\Store\BuildStore;
use PHPCensor\Store\Factory;
use PHPCensor\Store\ProjectGroupStore;
use PHPCensor\Store\ProjectStore;
use PHPCensor\View;
use PHPCensor\WebController;
/**
* Widget All Projects Controller
*/
class WidgetAllProjectsController extends WebController
{
/**
* @var BuildStore
*/
protected $buildStore;
/**
* @var ProjectStore
*/
protected $projectStore;
/**
* @var ProjectGroupStore
*/
protected $groupStore;
/**
* Initialise the controller, set up stores and services.
*/
public function init()
{
parent::init();
$this->buildStore = Factory::getStore('Build');
$this->projectStore = Factory::getStore('Project');
$this->groupStore = Factory::getStore('ProjectGroup');
}
/**
* @return Response
*
* @throws Exception
*/
public function index()
{
$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
*
* @return string
*
* @throws Exception
*/
protected function getSummaryHtml($projects)
{
$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.
*
* @return array
*
* @throws Exception
*/
protected function getGroupInfo()
{
$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;
}
/**
* @param int $projectId
*
* @return Response
*
* @throws HttpException
*/
public function update($projectId)
{
$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;
}
}