Adding project groups

This commit is contained in:
Dan Cryer 2015-10-08 16:33:01 +01:00
commit 74d313862c
18 changed files with 695 additions and 72 deletions

View file

@ -20,24 +20,11 @@ class ProjectStoreBase extends Store
protected $modelName = '\PHPCI\Model\Project';
protected $primaryKey = 'id';
/**
* Returns a Project model by primary key.
* @param mixed $value
* @param string $useConnection
* @return \@appNamespace\Model\Project|null
*/
public function getByPrimaryKey($value, $useConnection = 'read')
{
return $this->getById($value, $useConnection);
}
/**
* Returns a Project model by Id.
* @param mixed $value
* @param string $useConnection
* @throws HttpException
* @return \@appNamespace\Model\Project|null
*/
public function getById($value, $useConnection = 'read')
{
if (is_null($value)) {
@ -57,14 +44,6 @@ class ProjectStoreBase extends Store
return null;
}
/**
* Returns an array of Project models by Title.
* @param mixed $value
* @param int $limit
* @param string $useConnection
* @throws HttpException
* @return array
*/
public function getByTitle($value, $limit = 1000, $useConnection = 'read')
{
if (is_null($value)) {
@ -92,4 +71,32 @@ class ProjectStoreBase extends Store
return array('items' => array(), 'count' => 0);
}
}
public function getByGroupId($value, $limit = 1000, $useConnection = 'read')
{
if (is_null($value)) {
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
}
$query = 'SELECT * FROM `project` WHERE `group_id` = :group_id LIMIT :limit';
$stmt = Database::getConnection($useConnection)->prepare($query);
$stmt->bindValue(':group_id', $value);
$stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT);
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);
}
}
}