forked from php-censor/php-censor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectGroupStore.php
More file actions
48 lines (38 loc) · 1.18 KB
/
Copy pathProjectGroupStore.php
File metadata and controls
48 lines (38 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
declare(strict_types=1);
namespace PHPCensor\Store;
use PDO;
use PHPCensor\Exception\HttpException;
use PHPCensor\Model\ProjectGroup;
use PHPCensor\Store;
/**
* @package PHP Censor
* @subpackage Application
*
* @author Dmitry Khomutov <poisoncorpsee@gmail.com>
*/
class ProjectGroupStore extends Store
{
protected string $tableName = 'project_groups';
protected string $modelName = ProjectGroup::class;
/**
* Get a single ProjectGroup by title.
*
* @throws HttpException
*/
public function getByTitle(string $title, string $useConnection = 'read'): ?ProjectGroup
{
if (\is_null($title)) {
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
}
$query = 'SELECT * FROM {{' . $this->tableName . '}} WHERE {{title}} = :title LIMIT 1';
$stmt = $this->databaseManager->getConnection($useConnection)->prepare($query);
$stmt->bindValue(':title', $title);
if ($stmt->execute()) {
if ($data = $stmt->fetch(PDO::FETCH_ASSOC)) {
return new ProjectGroup($this->storeRegistry, $data);
}
}
return null;
}
}