2013-10-08 08:21:46 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* BuildMeta base store for table: build_meta
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace PHPCI\Store\Base;
|
|
|
|
|
2013-10-10 02:01:06 +02:00
|
|
|
use b8\Database;
|
|
|
|
use b8\Exception\HttpException;
|
2014-02-25 17:43:06 +01:00
|
|
|
use PHPCI\Store;
|
2013-10-10 02:01:06 +02:00
|
|
|
use PHPCI\Model\BuildMeta;
|
2013-10-08 08:21:46 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* BuildMeta Base Store
|
|
|
|
*/
|
|
|
|
class BuildMetaStoreBase extends Store
|
|
|
|
{
|
2014-04-30 15:14:23 +02:00
|
|
|
protected $tableName = 'build_meta';
|
|
|
|
protected $modelName = '\PHPCI\Model\BuildMeta';
|
|
|
|
protected $primaryKey = 'id';
|
2013-10-08 08:21:46 +02:00
|
|
|
|
|
|
|
public function getByPrimaryKey($value, $useConnection = 'read')
|
|
|
|
{
|
|
|
|
return $this->getById($value, $useConnection);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getById($value, $useConnection = 'read')
|
|
|
|
{
|
|
|
|
if (is_null($value)) {
|
2013-10-10 02:01:06 +02:00
|
|
|
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
|
2013-10-08 08:21:46 +02:00
|
|
|
}
|
|
|
|
|
2014-02-25 17:43:06 +01:00
|
|
|
$query = 'SELECT * FROM `build_meta` WHERE `id` = :id LIMIT 1';
|
2014-04-30 15:14:23 +02:00
|
|
|
$stmt = Database::getConnection($useConnection)->prepare($query);
|
2013-10-08 08:21:46 +02:00
|
|
|
$stmt->bindValue(':id', $value);
|
|
|
|
|
|
|
|
if ($stmt->execute()) {
|
|
|
|
if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
2013-10-10 02:01:06 +02:00
|
|
|
return new BuildMeta($data);
|
2013-10-08 08:21:46 +02:00
|
|
|
}
|
|
|
|
}
|
2014-04-30 15:14:23 +02:00
|
|
|
|
2013-10-08 08:21:46 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2014-05-13 17:15:06 +02:00
|
|
|
public function getByProjectId($value, $limit = null, $useConnection = 'read')
|
|
|
|
{
|
|
|
|
if (is_null($value)) {
|
|
|
|
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
|
|
|
|
}
|
|
|
|
|
|
|
|
$add = '';
|
|
|
|
|
|
|
|
if ($limit) {
|
|
|
|
$add .= ' LIMIT ' . $limit;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$query = 'SELECT * FROM `build_meta` WHERE `project_id` = :project_id' . $add;
|
|
|
|
$stmt = Database::getConnection($useConnection)->prepare($query);
|
|
|
|
$stmt->bindValue(':project_id', $value);
|
|
|
|
|
|
|
|
if ($stmt->execute()) {
|
|
|
|
$res = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
|
|
|
|
|
|
|
$map = function ($item) {
|
|
|
|
return new BuildMeta($item);
|
|
|
|
};
|
|
|
|
$rtn = array_map($map, $res);
|
|
|
|
|
2014-12-02 17:26:55 +01:00
|
|
|
$count = count($rtn);
|
|
|
|
|
|
|
|
|
2014-05-13 17:15:06 +02:00
|
|
|
return array('items' => $rtn, 'count' => $count);
|
|
|
|
} else {
|
|
|
|
return array('items' => array(), 'count' => 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-08 08:21:46 +02:00
|
|
|
public function getByBuildId($value, $limit = null, $useConnection = 'read')
|
|
|
|
{
|
|
|
|
if (is_null($value)) {
|
2013-10-10 02:01:06 +02:00
|
|
|
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
|
2013-10-08 08:21:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$add = '';
|
2014-04-30 15:14:23 +02:00
|
|
|
|
2013-10-08 08:21:46 +02:00
|
|
|
if ($limit) {
|
|
|
|
$add .= ' LIMIT ' . $limit;
|
|
|
|
}
|
2014-04-30 15:14:23 +02:00
|
|
|
|
2013-10-08 08:21:46 +02:00
|
|
|
|
2014-02-25 17:43:06 +01:00
|
|
|
$query = 'SELECT * FROM `build_meta` WHERE `build_id` = :build_id' . $add;
|
2014-04-30 15:14:23 +02:00
|
|
|
$stmt = Database::getConnection($useConnection)->prepare($query);
|
2013-10-08 08:21:46 +02:00
|
|
|
$stmt->bindValue(':build_id', $value);
|
|
|
|
|
|
|
|
if ($stmt->execute()) {
|
|
|
|
$res = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
|
|
|
|
|
|
|
$map = function ($item) {
|
2013-10-10 02:01:06 +02:00
|
|
|
return new BuildMeta($item);
|
2013-10-08 08:21:46 +02:00
|
|
|
};
|
|
|
|
$rtn = array_map($map, $res);
|
|
|
|
|
2014-12-02 17:26:55 +01:00
|
|
|
$count = count($rtn);
|
|
|
|
|
|
|
|
|
2013-10-08 08:21:46 +02:00
|
|
|
return array('items' => $rtn, 'count' => $count);
|
|
|
|
} else {
|
|
|
|
return array('items' => array(), 'count' => 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|