phpci/PHPCI/Store/Base/BuildMetaStoreBase.php

141 lines
3.7 KiB
PHP
Raw Normal View History

<?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;
/**
* BuildMeta Base Store
*/
class BuildMetaStoreBase extends Store
{
protected $tableName = 'build_meta';
protected $modelName = '\PHPCI\Model\BuildMeta';
protected $primaryKey = 'id';
2015-02-16 12:20:18 +01:00
/**
* Returns a BuildMeta model by primary key.
2015-05-31 16:01:51 +02:00
*
2015-02-16 12:20:18 +01:00
* @param mixed $value
* @param string $useConnection
2015-05-31 16:01:51 +02:00
*
2015-02-16 12:20:18 +01:00
* @return \@appNamespace\Model\BuildMeta|null
*/
public function getByPrimaryKey($value, $useConnection = 'read')
{
return $this->getById($value, $useConnection);
}
2015-02-16 12:20:18 +01:00
/**
* Returns a BuildMeta model by Id.
2015-05-31 16:01:51 +02:00
*
2015-02-16 12:20:18 +01:00
* @param mixed $value
* @param string $useConnection
2015-05-31 16:01:51 +02:00
*
2015-02-16 12:20:18 +01:00
* @return \@appNamespace\Model\BuildMeta|null
2015-05-31 16:01:51 +02:00
*
* @throws HttpException
2015-02-16 12:20:18 +01:00
*/
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.');
}
2014-02-25 17:43:06 +01:00
$query = 'SELECT * FROM `build_meta` WHERE `id` = :id LIMIT 1';
$stmt = Database::getConnection($useConnection)->prepare($query);
$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);
}
}
return null;
}
2015-02-16 12:20:18 +01:00
/**
* Returns an array of BuildMeta models by ProjectId.
2015-05-31 16:01:51 +02:00
*
2015-02-16 12:20:18 +01:00
* @param mixed $value
* @param int $limit
* @param string $useConnection
2015-05-31 16:01:51 +02:00
*
2015-02-16 12:20:18 +01:00
* @return array
2015-05-31 16:01:51 +02:00
*
* @throws HttpException
2015-02-16 12:20:18 +01:00
*/
public function getByProjectId($value, $limit = 1000, $useConnection = 'read')
{
if (is_null($value)) {
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
}
$query = 'SELECT * FROM `build_meta` WHERE `project_id` = :project_id LIMIT :limit';
$stmt = Database::getConnection($useConnection)->prepare($query);
$stmt->bindValue(':project_id', $value);
$stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT);
if ($stmt->execute()) {
$res = $stmt->fetchAll(\PDO::FETCH_ASSOC);
$map = function ($item) {
return new BuildMeta($item);
};
$rtn = array_map($map, $res);
$count = count($rtn);
return array('items' => $rtn, 'count' => $count);
} else {
return array('items' => array(), 'count' => 0);
}
}
2015-02-16 12:20:18 +01:00
/**
* Returns an array of BuildMeta models by BuildId.
2015-05-31 16:01:51 +02:00
*
2015-02-16 12:20:18 +01:00
* @param mixed $value
* @param int $limit
* @param string $useConnection
2015-05-31 16:01:51 +02:00
*
2015-02-16 12:20:18 +01:00
* @return array
2015-05-31 16:01:51 +02:00
*
* @throws HttpException
2015-02-16 12:20:18 +01:00
*/
public function getByBuildId($value, $limit = 1000, $useConnection = 'read')
{
if (is_null($value)) {
2013-10-10 02:01:06 +02:00
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
}
$query = 'SELECT * FROM `build_meta` WHERE `build_id` = :build_id LIMIT :limit';
$stmt = Database::getConnection($useConnection)->prepare($query);
$stmt->bindValue(':build_id', $value);
$stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT);
if ($stmt->execute()) {
$res = $stmt->fetchAll(\PDO::FETCH_ASSOC);
$map = function ($item) {
2013-10-10 02:01:06 +02:00
return new BuildMeta($item);
};
$rtn = array_map($map, $res);
$count = count($rtn);
return array('items' => $rtn, 'count' => $count);
} else {
return array('items' => array(), 'count' => 0);
}
}
}