phpci/PHPCI/Store/BuildStore.php

51 lines
1.4 KiB
PHP
Raw Normal View History

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\Store;
use PHPCI\Store\Base\BuildStoreBase;
/**
* Build Store
* @author Dan Cryer <dan@block8.co.uk>
* @package PHPCI
* @subpackage Core
*/
2013-05-03 17:02:53 +02:00
class BuildStore extends BuildStoreBase
{
public function getBuildSummary()
{
2013-05-22 23:11:36 +02:00
$query = 'SELECT COUNT(*) AS cnt FROM build b LEFT JOIN project p on p.id = b.project_id GROUP BY b.project_id ORDER BY p.title ASC, b.id DESC';
$stmt = \b8\Database::getConnection('read')->prepare($query);
if ($stmt->execute()) {
$res = $stmt->fetch(\PDO::FETCH_ASSOC);
$count = (int)$res['cnt'];
} else {
$count = 0;
}
2013-06-05 07:23:47 +02:00
$query = 'SELECT b.* FROM build b LEFT JOIN project p on p.id = b.project_id ORDER BY p.title ASC, b.id DESC';
$stmt = \b8\Database::getConnection('read')->prepare($query);
if ($stmt->execute()) {
$res = $stmt->fetchAll(\PDO::FETCH_ASSOC);
$map = function ($item) {
return new \PHPCI\Model\Build($item);
};
$rtn = array_map($map, $res);
return array('items' => $rtn, 'count' => $count);
} else {
return array('items' => array(), 'count' => 0);
}
}
2013-05-16 17:03:34 +02:00
}