2017-11-05 22:34:11 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace PHPCensor\Controller;
|
|
|
|
|
2018-03-04 08:30:34 +01:00
|
|
|
use PHPCensor\Store\Factory;
|
2018-02-16 14:18:04 +01:00
|
|
|
use PHPCensor\View;
|
2018-03-04 11:22:14 +01:00
|
|
|
use PHPCensor\Http\Response;
|
2017-11-05 22:34:11 +01:00
|
|
|
use PHPCensor\Controller;
|
2017-11-09 14:51:07 +01:00
|
|
|
use PHPCensor\Store\BuildStore;
|
|
|
|
use PHPCensor\Store\ProjectStore;
|
2017-11-05 22:34:11 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Widget Build Errors Controller
|
|
|
|
*/
|
|
|
|
class WidgetBuildErrorsController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
2017-11-09 14:51:07 +01:00
|
|
|
* @var BuildStore
|
2017-11-05 22:34:11 +01:00
|
|
|
*/
|
|
|
|
protected $buildStore;
|
|
|
|
|
|
|
|
/**
|
2017-11-09 14:51:07 +01:00
|
|
|
* @var ProjectStore
|
2017-11-05 22:34:11 +01:00
|
|
|
*/
|
|
|
|
protected $projectStore;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialise the controller, set up stores and services.
|
|
|
|
*/
|
|
|
|
public function init()
|
|
|
|
{
|
2017-11-09 14:51:07 +01:00
|
|
|
$this->buildStore = Factory::getStore('Build');
|
|
|
|
$this->projectStore = Factory::getStore('Project');
|
2017-11-05 22:34:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-11-09 14:51:07 +01:00
|
|
|
* Display dashboard.
|
2017-11-05 22:34:11 +01:00
|
|
|
*/
|
|
|
|
public function index()
|
|
|
|
{
|
2017-11-09 14:51:07 +01:00
|
|
|
$view = new View('WidgetBuildErrors/update');
|
|
|
|
|
2017-11-05 22:34:11 +01:00
|
|
|
$this->view->projects = $this->renderAllProjectsLatestBuilds($view);
|
|
|
|
|
|
|
|
$this->response->disableLayout();
|
|
|
|
$this->response->setContent($this->view->render());
|
|
|
|
|
|
|
|
return $this->response;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-11-09 14:51:07 +01:00
|
|
|
* @return Response
|
2017-11-05 22:34:11 +01:00
|
|
|
*/
|
|
|
|
public function update()
|
|
|
|
{
|
|
|
|
$this->response->disableLayout();
|
|
|
|
$this->response->setContent($this->renderAllProjectsLatestBuilds($this->view));
|
|
|
|
|
|
|
|
return $this->response;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-11-09 14:51:07 +01:00
|
|
|
* @param View $view
|
|
|
|
*
|
2017-11-05 22:34:11 +01:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
protected function renderAllProjectsLatestBuilds($view)
|
|
|
|
{
|
|
|
|
$builds = $this->buildStore->getAllProjectsLatestBuilds();
|
|
|
|
|
2017-11-17 08:35:25 +01:00
|
|
|
if (!empty($builds['projects'])) {
|
|
|
|
$view->builds = $builds['projects'];
|
|
|
|
$projects = $this->projectStore->getByIds(array_keys($builds['projects']));
|
2017-11-05 22:34:11 +01:00
|
|
|
|
2017-11-17 08:35:25 +01:00
|
|
|
$view_projects = [];
|
|
|
|
foreach($projects as $id => $project) {
|
|
|
|
if (!$project->getArchived()) {
|
|
|
|
$view_projects[$id] = $project;
|
|
|
|
} else {
|
|
|
|
unset($builds['projects'][$id]);
|
|
|
|
}
|
2017-11-05 22:34:11 +01:00
|
|
|
}
|
2017-11-17 08:35:25 +01:00
|
|
|
$view->projects = $view_projects;
|
|
|
|
} else {
|
|
|
|
$view = new View('WidgetBuildErrors/empty');
|
2017-11-05 22:34:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $view->render();
|
|
|
|
}
|
|
|
|
}
|