php-censor/src/Store/ProjectGroupStore.php

100 lines
2.3 KiB
PHP
Raw Permalink Normal View History

2015-10-08 17:33:01 +02:00
<?php
2016-07-19 20:28:11 +02:00
namespace PHPCensor\Store;
2015-10-08 17:33:01 +02:00
2018-03-04 09:34:19 +01:00
use PHPCensor\Database;
2018-03-04 11:14:09 +01:00
use PHPCensor\Exception\HttpException;
2017-02-16 13:45:50 +01:00
use PHPCensor\Store;
use PHPCensor\Model\ProjectGroup;
2015-10-08 17:33:01 +02:00
2017-02-16 13:45:50 +01:00
class ProjectGroupStore extends Store
2015-10-08 17:33:01 +02:00
{
2017-11-05 15:48:36 +01:00
/**
* @var string
*/
2017-10-14 20:29:29 +02:00
protected $tableName = 'project_group';
2017-11-05 15:48:36 +01:00
/**
* @var string
*/
2017-10-14 20:29:29 +02:00
protected $modelName = '\PHPCensor\Model\ProjectGroup';
2017-11-05 15:48:36 +01:00
/**
* @var string
*/
2017-10-14 20:29:29 +02:00
protected $primaryKey = 'id';
2017-02-16 13:45:50 +01:00
/**
* Get a ProjectGroup by primary key (Id)
2017-10-14 20:29:29 +02:00
*
* @param integer $key
* @param string $useConnection
*
* @return null|ProjectGroup
2017-02-16 13:45:50 +01:00
*/
2017-10-14 20:29:29 +02:00
public function getByPrimaryKey($key, $useConnection = 'read')
2017-02-16 13:45:50 +01:00
{
2017-10-14 20:29:29 +02:00
return $this->getById($key, $useConnection);
2017-02-16 13:45:50 +01:00
}
/**
* Get a single ProjectGroup by Id.
*
2017-10-14 20:29:29 +02:00
* @param integer $id
2017-02-16 13:45:50 +01:00
* @param string $useConnection
*
* @return ProjectGroup|null
*
* @throws HttpException
*/
2017-10-14 20:29:29 +02:00
public function getById($id, $useConnection = 'read')
2017-02-16 13:45:50 +01:00
{
2017-10-14 20:29:29 +02:00
if (is_null($id)) {
2017-02-16 13:45:50 +01:00
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
}
$query = 'SELECT * FROM {{project_group}} WHERE {{id}} = :id LIMIT 1';
$stmt = Database::getConnection($useConnection)->prepareCommon($query);
2017-10-14 20:29:29 +02:00
$stmt->bindValue(':id', $id);
2017-02-16 13:45:50 +01:00
if ($stmt->execute()) {
if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) {
return new ProjectGroup($data);
}
}
return null;
}
/**
* Get a single ProjectGroup by title.
*
2017-10-14 20:29:29 +02:00
* @param integer $title
2017-02-16 13:45:50 +01:00
* @param string $useConnection
*
* @return ProjectGroup|null
*
* @throws HttpException
*/
2017-10-14 20:29:29 +02:00
public function getByTitle($title, $useConnection = 'read')
2017-02-16 13:45:50 +01:00
{
2017-10-14 20:29:29 +02:00
if (is_null($title)) {
2017-02-16 13:45:50 +01:00
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
}
$query = 'SELECT * FROM {{project_group}} WHERE {{title}} = :title LIMIT 1';
$stmt = Database::getConnection($useConnection)->prepareCommon($query);
2017-10-14 20:29:29 +02:00
$stmt->bindValue(':title', $title);
2017-02-16 13:45:50 +01:00
if ($stmt->execute()) {
if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) {
return new ProjectGroup($data);
}
}
return null;
}
2015-10-08 17:33:01 +02:00
}