2013-05-03 17:02:53 +02:00
|
|
|
<?php
|
|
|
|
/**
|
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\Store;
|
|
|
|
|
2014-09-16 13:27:32 +02:00
|
|
|
use b8\Database;
|
2014-12-02 17:26:55 +01:00
|
|
|
use PHPCI\Model\Project;
|
2013-05-03 17:02:53 +02:00
|
|
|
use PHPCI\Store\Base\ProjectStoreBase;
|
|
|
|
|
|
|
|
/**
|
2013-05-16 03:30:48 +02:00
|
|
|
* Project Store
|
|
|
|
* @author Dan Cryer <dan@block8.co.uk>
|
|
|
|
* @package PHPCI
|
|
|
|
* @subpackage Core
|
|
|
|
*/
|
2013-05-03 17:02:53 +02:00
|
|
|
class ProjectStore extends ProjectStoreBase
|
|
|
|
{
|
2014-09-16 13:27:32 +02:00
|
|
|
public function getKnownBranches($projectId)
|
|
|
|
{
|
|
|
|
$query = 'SELECT DISTINCT branch from build WHERE project_id = :pid';
|
|
|
|
$stmt = Database::getConnection('read')->prepare($query);
|
|
|
|
$stmt->bindValue(':pid', $projectId);
|
|
|
|
|
|
|
|
if ($stmt->execute()) {
|
|
|
|
$res = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
|
|
|
|
|
|
|
$map = function ($item) {
|
|
|
|
return $item['branch'];
|
|
|
|
};
|
|
|
|
$rtn = array_map($map, $res);
|
|
|
|
|
|
|
|
return $rtn;
|
|
|
|
} else {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
}
|
2014-12-02 17:26:55 +01:00
|
|
|
|
|
|
|
public function getAll()
|
|
|
|
{
|
|
|
|
$query = 'SELECT * FROM `project` ORDER BY `title` ASC';
|
|
|
|
$stmt = Database::getConnection('read')->prepare($query);
|
|
|
|
|
|
|
|
if ($stmt->execute()) {
|
|
|
|
$res = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
|
|
|
|
|
|
|
$map = function ($item) {
|
|
|
|
return new Project($item);
|
|
|
|
};
|
|
|
|
$rtn = array_map($map, $res);
|
|
|
|
|
|
|
|
$count = count($rtn);
|
|
|
|
|
|
|
|
|
|
|
|
return array('items' => $rtn, 'count' => $count);
|
|
|
|
} else {
|
|
|
|
return array('items' => array(), 'count' => 0);
|
|
|
|
}
|
|
|
|
}
|
2013-05-16 17:03:34 +02:00
|
|
|
}
|