2013-05-03 17:02:53 +02:00
|
|
|
<?php
|
2013-05-16 03:16:56 +02:00
|
|
|
/**
|
2014-05-12 18:26:17 +02:00
|
|
|
* PHPCI - Continuous Integration for PHP
|
|
|
|
*
|
|
|
|
* @copyright Copyright 2014, Block 8 Limited.
|
|
|
|
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
|
|
|
* @link https://www.phptesting.org/
|
|
|
|
*/
|
2013-05-03 17:02:53 +02:00
|
|
|
|
|
|
|
namespace PHPCI\Controller;
|
2013-05-16 16:25:39 +02:00
|
|
|
|
2013-05-03 17:02:53 +02:00
|
|
|
use b8;
|
2014-02-25 18:00:05 +01:00
|
|
|
use PHPCI\BuildFactory;
|
2014-12-04 12:14:04 +01:00
|
|
|
use PHPCI\Helper\Lang;
|
2014-12-02 17:26:55 +01:00
|
|
|
use PHPCI\Model\Build;
|
2016-05-09 08:20:26 +02:00
|
|
|
use PHPCI\Controller;
|
2013-05-03 17:02:53 +02:00
|
|
|
|
2013-05-16 03:30:48 +02:00
|
|
|
/**
|
2013-09-20 08:33:46 +02:00
|
|
|
* Home Controller - Displays the PHPCI Dashboard.
|
2013-05-16 03:30:48 +02:00
|
|
|
* @author Dan Cryer <dan@block8.co.uk>
|
|
|
|
* @package PHPCI
|
|
|
|
* @subpackage Web
|
|
|
|
*/
|
2016-05-09 08:20:26 +02:00
|
|
|
class HomeController extends Controller
|
2013-05-03 17:02:53 +02:00
|
|
|
{
|
2013-10-08 14:52:05 +02:00
|
|
|
/**
|
2015-10-08 17:33:01 +02:00
|
|
|
* @var \PHPCI\Store\BuildStore
|
2013-10-08 14:52:05 +02:00
|
|
|
*/
|
2013-10-08 19:24:20 +02:00
|
|
|
protected $buildStore;
|
2013-10-08 14:52:05 +02:00
|
|
|
|
|
|
|
/**
|
2015-10-08 17:33:01 +02:00
|
|
|
* @var \PHPCI\Store\ProjectStore
|
2013-10-08 14:52:05 +02:00
|
|
|
*/
|
2013-10-08 19:24:20 +02:00
|
|
|
protected $projectStore;
|
2013-10-08 14:52:05 +02:00
|
|
|
|
2015-10-08 17:33:01 +02:00
|
|
|
/**
|
|
|
|
* @var \PHPCI\Store\ProjectGroupStore
|
|
|
|
*/
|
|
|
|
protected $groupStore;
|
|
|
|
|
2014-12-08 12:25:33 +01:00
|
|
|
/**
|
|
|
|
* Initialise the controller, set up stores and services.
|
|
|
|
*/
|
2013-05-16 16:25:39 +02:00
|
|
|
public function init()
|
|
|
|
{
|
2013-10-08 19:24:20 +02:00
|
|
|
$this->buildStore = b8\Store\Factory::getStore('Build');
|
|
|
|
$this->projectStore = b8\Store\Factory::getStore('Project');
|
2015-10-08 17:33:01 +02:00
|
|
|
$this->groupStore = b8\Store\Factory::getStore('ProjectGroup');
|
2013-05-16 16:25:39 +02:00
|
|
|
}
|
|
|
|
|
2013-05-16 18:17:29 +02:00
|
|
|
/**
|
|
|
|
* Display PHPCI dashboard:
|
|
|
|
*/
|
2013-05-16 16:25:39 +02:00
|
|
|
public function index()
|
|
|
|
{
|
2014-12-04 12:14:04 +01:00
|
|
|
$this->layout->title = Lang::get('dashboard');
|
2014-12-02 17:26:55 +01:00
|
|
|
$builds = $this->buildStore->getLatestBuilds(null, 10);
|
|
|
|
|
|
|
|
foreach ($builds as &$build) {
|
|
|
|
$build = BuildFactory::getBuild($build);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->view->builds = $builds;
|
2015-10-08 17:33:01 +02:00
|
|
|
$this->view->groups = $this->getGroupInfo();
|
2013-05-16 16:25:39 +02:00
|
|
|
|
2013-05-22 17:36:55 +02:00
|
|
|
return $this->view->render();
|
2013-05-16 16:25:39 +02:00
|
|
|
}
|
|
|
|
|
2013-05-16 18:17:29 +02:00
|
|
|
/**
|
|
|
|
* AJAX get latest builds table (HTML)
|
|
|
|
*/
|
2013-05-16 16:25:39 +02:00
|
|
|
public function latest()
|
|
|
|
{
|
2015-02-12 14:20:08 +01:00
|
|
|
$this->response->disableLayout();
|
2015-02-12 13:37:56 +01:00
|
|
|
$this->response->setContent($this->getLatestBuildsHtml());
|
|
|
|
return $this->response;
|
2013-05-16 16:25:39 +02:00
|
|
|
}
|
|
|
|
|
2014-12-08 12:25:33 +01:00
|
|
|
/**
|
|
|
|
* Ajax request for the project overview section of the dashboard.
|
|
|
|
*/
|
2014-04-30 16:24:55 +02:00
|
|
|
public function summary()
|
|
|
|
{
|
2015-02-12 14:20:08 +01:00
|
|
|
$this->response->disableLayout();
|
2016-04-20 17:39:48 +02:00
|
|
|
$projects = $this->projectStore->getWhere([], 50, 0, [], ['title' => 'ASC']);
|
2015-02-12 13:37:56 +01:00
|
|
|
$this->response->setContent($this->getSummaryHtml($projects));
|
|
|
|
return $this->response;
|
2014-04-30 16:24:55 +02:00
|
|
|
}
|
|
|
|
|
2014-12-08 12:25:33 +01:00
|
|
|
/**
|
|
|
|
* Generate the HTML for the project overview section of the dashboard.
|
|
|
|
* @param $projects
|
|
|
|
* @return string
|
|
|
|
*/
|
2014-04-30 16:24:55 +02:00
|
|
|
protected function getSummaryHtml($projects)
|
|
|
|
{
|
2016-04-20 17:39:48 +02:00
|
|
|
$summaryBuilds = [];
|
|
|
|
$successes = [];
|
|
|
|
$failures = [];
|
|
|
|
$counts = [];
|
2014-12-02 17:26:55 +01:00
|
|
|
|
2015-10-08 17:33:01 +02:00
|
|
|
foreach ($projects as $project) {
|
2014-04-30 16:24:55 +02:00
|
|
|
$summaryBuilds[$project->getId()] = $this->buildStore->getLatestBuilds($project->getId());
|
2014-12-02 17:26:55 +01:00
|
|
|
|
2015-02-28 18:51:04 +01:00
|
|
|
$count = $this->buildStore->getWhere(
|
2016-04-20 17:39:48 +02:00
|
|
|
['project_id' => $project->getId()],
|
2015-02-28 18:51:04 +01:00
|
|
|
1,
|
|
|
|
0,
|
2016-04-20 17:39:48 +02:00
|
|
|
[],
|
|
|
|
['id' => 'DESC']
|
2015-02-28 18:51:04 +01:00
|
|
|
);
|
2015-02-28 18:13:02 +01:00
|
|
|
$counts[$project->getId()] = $count['count'];
|
|
|
|
|
2014-12-02 17:26:55 +01:00
|
|
|
$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;
|
2014-04-30 16:24:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$summaryView = new b8\View('SummaryTable');
|
2015-10-08 17:33:01 +02:00
|
|
|
$summaryView->projects = $projects;
|
2015-02-28 18:13:02 +01:00
|
|
|
$summaryView->builds = $summaryBuilds;
|
2014-12-02 17:26:55 +01:00
|
|
|
$summaryView->successful = $successes;
|
2015-02-28 18:13:02 +01:00
|
|
|
$summaryView->failed = $failures;
|
|
|
|
$summaryView->counts = $counts;
|
2014-04-30 16:24:55 +02:00
|
|
|
|
|
|
|
return $summaryView->render();
|
|
|
|
}
|
|
|
|
|
2013-05-16 18:17:29 +02:00
|
|
|
/**
|
|
|
|
* Get latest builds and render as a table.
|
|
|
|
*/
|
2013-05-16 16:25:39 +02:00
|
|
|
protected function getLatestBuildsHtml()
|
|
|
|
{
|
2016-04-20 17:39:48 +02:00
|
|
|
$builds = $this->buildStore->getWhere([], 5, 0, [], ['id' => 'DESC']);
|
2013-05-16 16:25:39 +02:00
|
|
|
$view = new b8\View('BuildsTable');
|
2014-02-25 18:00:05 +01:00
|
|
|
|
|
|
|
foreach ($builds['items'] as &$build) {
|
|
|
|
$build = BuildFactory::getBuild($build);
|
|
|
|
}
|
|
|
|
|
2013-05-16 16:25:39 +02:00
|
|
|
$view->builds = $builds['items'];
|
|
|
|
|
|
|
|
return $view->render();
|
|
|
|
}
|
2015-10-08 17:33:01 +02:00
|
|
|
|
2015-10-09 10:38:55 +02:00
|
|
|
/**
|
|
|
|
* Get a summary of the project groups we have, and what projects they have in them.
|
|
|
|
* @return array
|
|
|
|
*/
|
2015-10-08 17:33:01 +02:00
|
|
|
protected function getGroupInfo()
|
|
|
|
{
|
2016-04-20 17:39:48 +02:00
|
|
|
$rtn = [];
|
|
|
|
$groups = $this->groupStore->getWhere([], 100, 0, [], ['title' => 'ASC']);
|
2015-10-08 17:33:01 +02:00
|
|
|
|
|
|
|
foreach ($groups['items'] as $group) {
|
2016-04-20 17:39:48 +02:00
|
|
|
$thisGroup = ['title' => $group->getTitle()];
|
2015-10-08 17:33:01 +02:00
|
|
|
$projects = $this->projectStore->getByGroupId($group->getId());
|
|
|
|
$thisGroup['projects'] = $projects['items'];
|
|
|
|
$thisGroup['summary'] = $this->getSummaryHtml($thisGroup['projects']);
|
|
|
|
$rtn[] = $thisGroup;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $rtn;
|
|
|
|
}
|
2013-05-16 16:25:39 +02:00
|
|
|
}
|