forked from fabarea/messenger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPageRepository.php
More file actions
105 lines (87 loc) · 3.17 KB
/
Copy pathPageRepository.php
File metadata and controls
105 lines (87 loc) · 3.17 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
namespace Fab\Messenger\Domain\Repository;
/*
* This file is part of the Fab/Messenger project under GPLv2 or later.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Utility\GeneralUtility;
class PageRepository extends AbstractContentRepository
{
protected string $tableName = 'pages';
protected ConnectionPool $connectionPool;
public function __construct(ConnectionPool $connectionPool)
{
$this->connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
}
public function findByUids(array $uids): array
{
$query = $this->getQueryBuilder();
$query
->select('*')
->from($this->tableName)
->where($this->getQueryBuilder()->expr()->in('uid', $uids));
return $query->executeQuery()->fetchAllAssociative();
}
protected function getQueryBuilder(): QueryBuilder
{
/** @var ConnectionPool $connectionPool */
$connectionPool = $this->connectionPool;
return $connectionPool->getQueryBuilderForTable($this->tableName);
}
public function findByUid(int $uid): array
{
$query = $this->getQueryBuilder();
$query
->select('*')
->from($this->tableName)
->where(
$this->getQueryBuilder()
->expr()
->eq('uid', $this->getQueryBuilder()->expr()->literal($uid)),
);
$messages = $query->executeQuery()->fetchAssociative();
return is_array($messages) ? $messages : [];
}
public function findAll(): array
{
$query = $this->getQueryBuilder();
$query->select('*')->from($this->tableName);
return $query->executeQuery()->fetchAllAssociative();
}
public function findByDemand(array $demand = [], array $orderings = [], int $offset = 0, int $limit = 0): array
{
$queryBuilder = $this->getQueryBuilder();
$queryBuilder->select('*')->from($this->tableName);
$constraints = [];
foreach ($demand as $field => $value) {
$constraints[] = $queryBuilder
->expr()
->like(
$field,
$queryBuilder->createNamedParameter('%' . $queryBuilder->escapeLikeWildcards($value) . '%'),
);
}
if ($constraints) {
$queryBuilder->where($queryBuilder->expr()->or(...$constraints));
}
if ($orderings === []) {
$orderings = ['uid' => 'ASC'];
}
// We handle the sorting
$queryBuilder->addOrderBy(key($orderings), current($orderings));
if ($limit > 0) {
$queryBuilder->setMaxResults($limit);
}
return $queryBuilder->executeQuery()->fetchAllAssociative();
}
public function deleteByUids(array $uids): int
{
$query = $this->getQueryBuilder();
$query->delete($this->tableName)->where($query->expr()->in('uid', $uids));
return $query->executeQuery();
}
}