1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Abstract raw repository. |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace HDNET\Focuspoint\Domain\Repository; |
8
|
|
|
|
9
|
|
|
use TYPO3\CMS\Core\Database\ConnectionPool; |
10
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Abstract raw repository. |
14
|
|
|
*/ |
15
|
|
|
abstract class AbstractRawRepository |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* Find by uid. |
19
|
|
|
* |
20
|
|
|
* @param int $uid |
21
|
|
|
* |
22
|
|
|
* @return array|null |
23
|
|
|
*/ |
24
|
|
|
public function findByUid(int $uid) |
25
|
|
|
{ |
26
|
|
|
$queryBuilder = $this->getQueryBuilder(); |
27
|
|
|
$rows = $queryBuilder->select('*') |
28
|
|
|
->from($this->getTableName()) |
29
|
|
|
->where( |
30
|
|
|
$queryBuilder->expr()->eq('uid', $uid) |
31
|
|
|
) |
32
|
|
|
->execute() |
33
|
|
|
->fetchAll(); |
34
|
|
|
|
35
|
|
|
return $rows[0] ?? null; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Find all. |
40
|
|
|
* |
41
|
|
|
* @return array |
42
|
|
|
*/ |
43
|
|
|
public function findAll(): array |
44
|
|
|
{ |
45
|
|
|
$queryBuilder = $this->getQueryBuilder(); |
46
|
|
|
|
47
|
|
|
return (array) $queryBuilder->select('*') |
48
|
|
|
->from($this->getTableName()) |
49
|
|
|
->execute() |
50
|
|
|
->fetchAll(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Update by uid. |
55
|
|
|
* |
56
|
|
|
* @param int $uid |
57
|
|
|
* @param array $values |
58
|
|
|
*/ |
59
|
|
|
public function update(int $uid, array $values) |
60
|
|
|
{ |
61
|
|
|
$this->getConnection()->update( |
62
|
|
|
$this->getTableName(), |
63
|
|
|
$values, |
64
|
|
|
['uid' => (int) $uid] |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Insert. |
70
|
|
|
* |
71
|
|
|
* @param array $values |
72
|
|
|
*/ |
73
|
|
|
public function insert(array $values) |
74
|
|
|
{ |
75
|
|
|
$this->getConnection()->insert( |
76
|
|
|
$this->getTableName(), |
77
|
|
|
$values |
78
|
|
|
); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Get connection. |
83
|
|
|
* |
84
|
|
|
* @return \TYPO3\CMS\Core\Database\Connection |
85
|
|
|
*/ |
86
|
|
|
protected function getConnection() |
87
|
|
|
{ |
88
|
|
|
return GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($this->getTableName()); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Get query builder. |
93
|
|
|
* |
94
|
|
|
* @return \TYPO3\CMS\Core\Database\Query\QueryBuilder |
95
|
|
|
*/ |
96
|
|
|
protected function getQueryBuilder() |
97
|
|
|
{ |
98
|
|
|
return GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->getTableName()); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Get the tablename. |
103
|
|
|
* |
104
|
|
|
* @return string |
105
|
|
|
*/ |
106
|
|
|
abstract protected function getTableName(): string; |
107
|
|
|
} |
108
|
|
|
|