Adding project overview to dashboard, closes #55

This commit is contained in:
Dan Cryer 2013-05-22 17:15:02 +01:00
commit acb58ff5e0
4 changed files with 60 additions and 2 deletions

View file

@ -19,5 +19,32 @@ use PHPCI\Store\Base\BuildStoreBase;
*/
class BuildStore extends BuildStoreBase
{
// This class has been left blank so that you can modify it - changes in this file will not be overwritten.
public function getBuildSummary()
{
$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';
$stmt = \b8\Database::getConnection('read')->prepare($query);
if ($stmt->execute()) {
$res = $stmt->fetch(\PDO::FETCH_ASSOC);
$count = (int)$res['cnt'];
} else {
$count = 0;
}
$query = 'SELECT * FROM build b LEFT JOIN project p on p.id = b.project_id GROUP BY b.project_id ORDER BY p.title ASC';
$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);
}
}
}