-
Notifications
You must be signed in to change notification settings - Fork 145
Expand file tree
/
Copy pathWidgetBuildErrorsController.php
More file actions
89 lines (72 loc) · 2.18 KB
/
WidgetBuildErrorsController.php
File metadata and controls
89 lines (72 loc) · 2.18 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
<?php
declare(strict_types=1);
namespace PHPCensor\Controller;
use PHPCensor\Exception\HttpException;
use Symfony\Component\HttpFoundation\Response;
use PHPCensor\Store\BuildStore;
use PHPCensor\Store\ProjectStore;
use PHPCensor\View;
use PHPCensor\WebController;
/**
* @package PHP Censor
* @subpackage Application
*
* @author Dmitry Khomutov <poisoncorpsee@gmail.com>
*/
class WidgetBuildErrorsController extends WebController
{
protected BuildStore $buildStore;
protected ProjectStore $projectStore;
/**
* 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');
}
/**
* Display dashboard.
*/
public function index(): Response
{
$view = new View('WidgetBuildErrors/update');
$this->view->projects = $this->renderAllProjectsLatestBuilds($view);
$response = new Response();
$response->setContent($this->view->render());
return $response;
}
/**
* @throws HttpException
*/
public function update(): Response
{
$response = new Response();
$response->setContent($this->renderAllProjectsLatestBuilds($this->view));
return $response;
}
/**
* @throws HttpException
*/
protected function renderAllProjectsLatestBuilds(View $view): string
{
$builds = $this->buildStore->getAllProjectsLatestBuilds();
if (!empty($builds['projects'])) {
$view->builds = $builds['projects'];
$projects = $this->projectStore->getByIds(\array_keys($builds['projects']));
$viewProjects = [];
foreach ($projects as $id => $project) {
if (!$project->getArchived()) {
$viewProjects[$id] = $project;
} else {
unset($builds['projects'][$id]);
}
}
$view->projects = $viewProjects;
} else {
$view = new View('WidgetBuildErrors/empty');
}
return $view->render();
}
}