2013-05-03 17:02:53 +02:00
|
|
|
<?php
|
2013-05-16 03:16:56 +02:00
|
|
|
/**
|
|
|
|
* PHPCI - Continuous Integration for PHP
|
|
|
|
*
|
|
|
|
* @copyright Copyright 2013, Block 8 Limited.
|
|
|
|
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
|
|
|
* @link http://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;
|
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
|
|
|
|
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()
|
|
|
|
{
|
2013-10-08 19:24:20 +02:00
|
|
|
$projects = $this->projectStore->getWhere(array(), 50, 0, array(), array('title' => 'ASC'));
|
2013-10-08 14:52:05 +02:00
|
|
|
|
|
|
|
$summaryBuilds = array();
|
|
|
|
foreach ($projects['items'] as $project) {
|
2013-10-08 19:24:20 +02:00
|
|
|
$summaryBuilds[$project->getId()] = $this->buildStore->getLatestBuilds($project->getId());
|
2013-10-08 14:52:05 +02:00
|
|
|
}
|
2013-05-22 18:15:02 +02:00
|
|
|
|
2013-06-05 07:23:47 +02:00
|
|
|
$summaryView = new b8\View('SummaryTable');
|
2013-10-08 14:52:05 +02:00
|
|
|
$summaryView->projects = $projects['items'];
|
|
|
|
$summaryView->builds = $summaryBuilds;
|
2013-05-22 18:15:02 +02:00
|
|
|
|
2013-05-22 17:36:55 +02:00
|
|
|
$this->view->builds = $this->getLatestBuildsHtml();
|
|
|
|
$this->view->projects = $projects['items'];
|
2013-05-22 18:15:02 +02:00
|
|
|
$this->view->summary = $summaryView->render();
|
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()
|
|
|
|
{
|
|
|
|
die($this->getLatestBuildsHtml());
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|