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;
|
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
|
|
|
|
*/
|
2013-09-20 08:33:46 +02:00
|
|
|
class HomeController extends \PHPCI\Controller
|
2013-05-03 17:02:53 +02:00
|
|
|
{
|
2013-10-08 14:52:05 +02:00
|
|
|
/**
|
|
|
|
* @var \b8\Store\BuildStore
|
|
|
|
*/
|
2013-10-08 19:24:20 +02:00
|
|
|
protected $buildStore;
|
2013-10-08 14:52:05 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \b8\Store\ProjectStore
|
|
|
|
*/
|
2013-10-08 19:24:20 +02:00
|
|
|
protected $projectStore;
|
2013-10-08 14:52:05 +02:00
|
|
|
|
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');
|
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
|
|
|
|
2015-01-31 10:50:57 +01:00
|
|
|
$projects = $this->projectStore->getWhere(
|
|
|
|
array('archived' => (int)isset($_GET['archived'])),
|
|
|
|
50,
|
|
|
|
0,
|
|
|
|
array(),
|
|
|
|
array('title' => 'ASC')
|
|
|
|
);
|
2013-05-22 18:15:02 +02:00
|
|
|
|
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;
|
2013-05-22 17:36:55 +02:00
|
|
|
$this->view->projects = $projects['items'];
|
2014-04-30 16:24:55 +02:00
|
|
|
$this->view->summary = $this->getSummaryHtml($projects);
|
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();
|
2014-04-30 16:24:55 +02:00
|
|
|
$projects = $this->projectStore->getWhere(array(), 50, 0, array(), array('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)
|
|
|
|
{
|
|
|
|
$summaryBuilds = array();
|
2015-02-28 18:13:02 +01:00
|
|
|
$successes = array();
|
|
|
|
$failures = array();
|
|
|
|
$counts = array();
|
2014-12-02 17:26:55 +01:00
|
|
|
|
2014-04-30 16:24:55 +02:00
|
|
|
foreach ($projects['items'] as $project) {
|
|
|
|
$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(
|
|
|
|
array('project_id' => $project->getId()),
|
|
|
|
1,
|
|
|
|
0,
|
|
|
|
array(),
|
|
|
|
array('id' => 'DESC')
|
|
|
|
);
|
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-02-28 18:13:02 +01:00
|
|
|
$summaryView->projects = $projects['items'];
|
|
|
|
$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()
|
|
|
|
{
|
2013-10-08 19:24:20 +02:00
|
|
|
$builds = $this->buildStore->getWhere(array(), 5, 0, array(), array('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();
|
|
|
|
}
|
|
|
|
}
|